Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View awesomebytes's full-sized avatar

Sam Pfeiffer awesomebytes

View GitHub Profile

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
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
#!/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
#!/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
#!/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

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:

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
#!/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)

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"