Skip to content

Instantly share code, notes, and snippets.

View PeterMitrano's full-sized avatar
🔬

Peter Mitrano PeterMitrano

🔬
View GitHub Profile
@PeterMitrano
PeterMitrano / multiple_services_and_actions.py
Created November 11, 2025 07:24
Simple example of using service callbacks
import threading
from time import sleep
import rclpy
from rclpy.node import Node
from example_interfaces.srv import AddTwoInts
class MinimalClientAsync(Node):
@PeterMitrano
PeterMitrano / debug_node_exit.launch.py
Created August 4, 2025 10:45
How to cause the entire ros2 launch process to die when a specific node exits with an error code.
# This is useful for testing buggy ros launch setups,
# because you can run it like `while ros2 launch pkg debug.launch.py; do sleep 0.5; done;`
# and it will keep restarting util the test node returns an error.
# this was really difficult to figure out how to do.... :(
import os
import sys
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, RegisterEventHandler, EmitEvent
from launch.event_handlers import OnProcessExit
from launch.events import Shutdown
@PeterMitrano
PeterMitrano / humble_debug_ros2_launch.py
Created August 4, 2025 10:43
How to run the equivalent of `ros2 launch` in python, so it can be debugged
import launch
import launch_ros
from launch import LaunchService
from launch.frontend import Parser
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.utilities import normalize_to_list_of_substitutions
import os
# Absolute path to your launch file
launch_file_path = (
@PeterMitrano
PeterMitrano / serialize_deserialize_rospy_python3
Created March 4, 2021 15:58
Quick example of how to serialize then deserialize a ROS msg in python 3
from io import BytesIO
from geometry_msgs.msg import Point
p = Point(x=2, y=4)
print(p)
buff = BytesIO()
p.serialize(buff)
serialized_bytes = buff.getvalue()
@PeterMitrano
PeterMitrano / read_bagfile_ros2_python.py
Created February 16, 2023 18:31
One way to read a bagfile from python in ros2
def open_bagfile(bagfile: Path):
reader = rosbag2_py.SequentialReader()
storage_options = rosbag2_py.StorageOptions(bagfile.as_posix())
converter_options = rosbag2_py.ConverterOptions("cdr", "cdr")
reader.open(storage_options, converter_options)
topic_types = reader.get_all_topics_and_types()
# Create a map for quicker lookup
type_map = {
@PeterMitrano
PeterMitrano / setup.py
Created January 17, 2023 05:25
Yolov7 setup.py
#!/usr/bin/env python
from distutils.core import setup
setup(name='yolo',
version='1.0',
description='yolo v7',
author='',
author_email='',
url='',
@PeterMitrano
PeterMitrano / aws_setup.sh
Last active October 20, 2021 19:03
AWS setup
# NOTE: if using this outside ec2, you will need to copy your ~/.aws/credentials into the computer first
sudo apt update
sudo apt install -y g++ build-essential cmake git htop tree tmux curl openssh-server imagemagick maim vim-gtk3 i3 python3-pip python3-virtualenv libappindicator3-dev castxml qt5-style-plugins trash-cli checkinstall gparted net-tools rename libreadline-dev imagemagick policykit-1-gnome
sudo apt upgrade
git config --global user.email "peter@`echo $HOSTNAME`"
git config --global user.name "peter"
sudo apt-get install ubuntu-drivers-common
@PeterMitrano
PeterMitrano / motion_planning_tutorial.cpp
Created September 17, 2021 18:51
y-shaped robot pose goal(s)?
#include <ros/ros.h>
#include <moveit/kinematic_constraints/utils.h>
#include <moveit/planning_interface/planning_interface.h>
#include <moveit/planning_pipeline/planning_pipeline.h>
#include <moveit/planning_scene_monitor/planning_scene_monitor.h>
#include <moveit/robot_model_loader/robot_model_loader.h>
#include <moveit/robot_state/conversions.h>
#include <moveit_msgs/DisplayTrajectory.h>
#include <moveit_visual_tools/moveit_visual_tools.h>

Install

sudo snap install chromium
sudo apt install -y g++ build-essential cmake git htop tree tmux curl openssh-server imagemagick maim vim-gtk3 i3 python3-pip python3-virtualenv libappindicator3-dev castxml qt5-style-plugins trash-cli checkinstall gparted net-tools rename  libreadline-dev imagemagick policykit-1-gnome
sudo snap install pycharm-professional --classic
sudo snap install clion --classic
# https://linuxconfig.org/how-to-install-the-nvidia-drivers-on-ubuntu-20-04-focal-fossa-linux
sudo ubuntu-drivers autoinstall
# https://linuxconfig.org/how-to-install-cuda-on-ubuntu-20-04-focal-fossa-linux
sudo apt install -y nvidia-cuda-toolkit
#!/bin/bash
PS3='Choose a workspace type: '
options=("default" "debug")
select opt in "${options[@]}"
do
case $opt in
"default")
source /home/peter/catkin_ws/devel/setup.bash
cd /home/peter/catkin_ws/
catkin profile set default