Skip to content

Instantly share code, notes, and snippets.

Avatar

Sam Pfeiffer awesomebytes

View GitHub Profile
@awesomebytes
awesomebytes / project_points_on_image.py
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
View project_points_on_image.py
#!/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
awesomebytes / serialized_subscriber.py
Last active March 15, 2023 07:50
Python ROS 1 Subscriber that provides serialized messages and allows to deserialize at a later point
View serialized_subscriber.py
#!/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 gmail.com>
# License: BSD-3
View control_power_distribution.py
#!/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
awesomebytes / ipv6_discovery.md
Created November 10, 2022 03:18
Connect to an unconfigured board via ethernet without DHCP or link local using ipv6
View ipv6_discovery.md

SSH into directly connected ethernet board

From: https://unix.stackexchange.com/a/624347

# 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:
View building_live_ubuntu_cd_with_rt.md
View building_rt_preempt.md

Compile Kernel with PREEMPT_RT

When following https://docs.ros.org/en/foxy/Tutorials/Miscellaneous/Building-Realtime-rt_preempt-kernel-for-ROS-2.html

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
awesomebytes / image_flip.py
Created October 17, 2022 00:55
ROS Image stream camera flip either horizontally, vertically or both via OpenCV
View image_flip.py
#!/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
"""
@awesomebytes
awesomebytes / how_to_publish_rostopic_pub_launchfile.md
Last active July 20, 2022 02:25
rostopic pub in a launchfile with a complex message (PointCloud2)
View how_to_publish_rostopic_pub_launchfile.md

How to publish with rostopic pub in a launchfile with a complex message

Using the dictionary syntax: http://wiki.ros.org/ROS/YAMLCommandLine#Command-line_and_messages_.28dictionaries.29 We avoid the problem of requiring double quotes inside of the args field. (I found no way to realiably escape the quotes, for double quote I used &quot; and for single quote I used &apos; but I still was getting errors).

<launch>
    <!-- Publishing a dummy empty pointcloud (but with x y z fields described to avoid
    errors like: Failed to find match for field 'x'. ) -->
    <node name="dummy_pointcloud_pub" pkg="rostopic" type="rostopic"
@awesomebytes
awesomebytes / message_filter_over_rosbag.py
Last active December 29, 2022 16:20
message_filters ApproximateTimeSynchronizer over a rosbag (without roscore or /use_sim_time)
View message_filter_over_rosbag.py
#!/usr/bin/env python
import itertools
import sys
import time
import rospy
import rosbag
import message_filters
"""
Example using a message_filters filter (ApproximateTimeSynchronizer) iterating
@awesomebytes
awesomebytes / nvidia_cuda_fail_workaround.md
Last active January 16, 2023 07:02
Nvidia CUDA driver not working after suspend or hibernation workaround
View nvidia_cuda_fail_workaround.md

How to reset the GPU to use CUDA after suspend or hibernation

I needed to do:

sudo rmmod nvidia_uvm
sudo modprobe nvidia_uvm

From the nvidia forums.

I also got the following error fixed (docker-nvidia related) with these commands: