Skip to content

Instantly share code, notes, and snippets.

View awesomebytes's full-sized avatar

Sam Pfeiffer awesomebytes

View GitHub Profile
awesomebytes /
Created April 30, 2024 09:39
Interactive debugging tips in Python with ipdb, hickle and ipython
#!/usr/bin/env python
"""Example of usage of ipython debugger (ipdb)
to interactively debug something in the code with autocomplete and color support.
You may need to install:
sudo pip install ipdb

How to keep color of a 3D model for gazebo and Rviz

Get model from SolidWorks in .ply and in .obj (All in a single file) (so, you need a model that has color information somehow, in my case, opening it with meshlab always showed the color)

Use the .obj to open in Blender, make sure to adjust the import size (probably is in mm, so 0.001)

Now export to collada (.dae) and the model will keep color

#!/usr/bin/env python
import rospy
import tf2_ros
from geometry_msgs.msg import PoseStamped
# You want to use "simulated time" so it uses the time from the rosbag
# rosparan set /use_sim_time true
# Play your rosbag with something like:
awesomebytes /
Created March 17, 2023 11:39
The output of experimenting with ChatGPT writing and helping to fix a node to project pointcloud points on an image
#!/usr/bin/env python
import rospy
import sensor_msgs.point_cloud2 as pc2
from sensor_msgs.msg import PointCloud2, CameraInfo, CompressedImage
from cv_bridge import CvBridge
import tf2_ros
import tf2_py as tf2
import tf2_sensor_msgs
import cv2
awesomebytes /
Last active March 15, 2023 07:50
Python ROS 1 Subscriber that provides serialized messages and allows to deserialize at a later point
#!/usr/bin/env python3
from typing import Any
import rospy
import types
# Possible future idea: this could allow to also drop messages on purpose on the Python side
# deserializing is the second most expensive thing to do anyways (the first being just receiving the message)
# Author: Sam Pfeiffer <sammypfeiffer at>
# License: BSD-3
#!/usr/bin/env python
import rospy
from can_msgs.msg import Frame
from std_msgs.msg import UInt8MultiArray
def create_request(channel, off_on_toggle):
"""Create a CAN Frame to request CHANNEL to OFF_ON_TOGGLE
0 - 48 0 1 2
bits 0-7 bits 8-15"""
awesomebytes /
Created November 10, 2022 03:18
Connect to an unconfigured board via ethernet without DHCP or link local using ipv6

SSH into directly connected ethernet board


# Find the ipv6 address connected to the interface (-I YOUR_INTERFACE)
ping6 -L -I enx8cae4cdd3a4d ff02::1
# PING ff02::1(ff02::1) from fe80::15c5:f43f:2c00:fefd%enx8cae4cdd3a4d enx8cae4cdd3a4d: 56 data bytes
# 64 bytes from fe80::f00b:9167:92a:a182%enx8cae4cdd3a4d: icmp_seq=44 ttl=64 time=3.78 ms
# Now ssh into the discovered address+interface:

Compile Kernel with PREEMPT_RT

When following

I built this in a VM using the Ubuntu ubuntu-20.04.5-desktop-amd64.iso. I needed to provide the VM with 7GB of RAM to avoid OOM (out of memory) errors. I needed to provide it with 60GB of storage space (Ubuntu installation needs short of 7GB and the kernel compilation seems to need over 40GB, plus testing the .deb installation it fills the disk).

39G	linux-5.15.73
8.2M	linux-headers-5.15.73-rt52_5.15.73-rt52-8_amd64.deb
84M	linux-image-5.15.73-rt52_5.15.73-rt52-8_amd64.deb
1.2G	linux-image-5.15.73-rt52-dbg_5.15.73-rt52-8_amd64.deb
1.2M	linux-libc-dev_5.15.73-rt52-8_amd64.deb
awesomebytes /
Created October 17, 2022 00:55
ROS Image stream camera flip either horizontally, vertically or both via OpenCV
#!/usr/bin/env python
import sys
import rospy
from sensor_msgs.msg import Image, CompressedImage
import numpy as np
import cv2
from cv_bridge import CvBridge, CvBridgeError