CodeRef
CodeRef
  • Software
    • VSCode
  • Midjourney_AI
    • Midjourney Cheat Sheet
  • aws
    • S3 Reference
    • Services
  • bash
    • .bashrc File Contents
    • CAN
    • _System Config File Locations
    • argument-length-limits
    • Conditionals
    • Data Structures
    • File Permissions
    • File Syncing
    • File System
    • Functions
    • General
    • Loops
    • My Functions
    • Networking
    • Number Operations
    • OpenVPN
    • Operators
    • Resource Management
    • Serial RS232
    • Spinning Wheel Animation
    • SSH
    • Text Operations
    • Environment Variables
  • cpp
    • ChatGPT | Pointers vs. References
    • arrays
    • Classes
    • Data Types / Structures
    • Enumerated Classes
    • Exception Handling
    • Function Objects
    • Functions
    • I/O
    • Loops
    • Macros
    • Namespaces
    • New Features
    • Pointers
    • Scope
    • Smart Pointers
    • Raw String Literals
    • Style Guide
    • Switch Case
    • Templating
    • How to Use tinyxml2
    • Useful Libraries
    • google-test
    • Conditionals
    • Rule of Three/Five
    • Optional Parameters
    • Keywords
    • Filesystem
    • Random
    • Casting
    • tools
  • git
    • Code Review Dependency Strategy
    • Git Bisect Guide
    • Git Reference
    • removing-cherry-picks
    • Useful Tools
    • Graphite Reference
  • js
    • functions
    • Javascript Reference
  • linux
    • Display
    • Dual Boot with Windows
    • File System
    • NVIDIA
    • Sending/Receiving TCP/UDP Messages in Ubuntu
    • dynamically_linked_binaries
  • markdown
    • Images
    • obsidian-reference
  • python
    • Classes
    • Exceptions
    • Functions
    • Operations
    • Python Reference
    • unittest_command-line-args
    • unittest_magicmock_GPT
    • unittest_mock
    • unittest_printing
    • unittest_subtest
    • useful-stuff
    • jupyter
    • poetry
  • ros
    • _ROS Cheat Sheet
    • Create New Workspace
    • Install ROS
    • Node Sample - Listener
    • Node Sample - Talker
    • Node Template
    • Setup
    • urdf
  • excel
    • excel-reference
  • windows
    • File System
    • WSL - Windows Subsystem for Linux
    • WSL
  • software_engineering
    • uncle_bob_lectures
      • Overview
      • Lesson 01 - Notes
  • web
    • Front End
    • Hugo
    • new_frontend_tools
  • sql
    • cheatsheet
Powered by GitBook
On this page
  1. ros

_ROS Cheat Sheet

Setup

source [setup file]  # Sets up environment variables for ROS.
source /opt/ros/noetic/setup.bash

Autocomplete

# Autocomplete - How to find commands/tools:
# (might have to hit tab twice)
ros [tab]  # Lists all ROS commands
rosrun [tab]  # Lists available packages to run
rosrun pkg [tab]  # Lists available nodes to run within package "pkg"
catkin [tab]  # Lists all catkin commands
rostopic [tab]  # Tools related to ROS topics

ROS Master

roscore
roscore &  # Start ROS Master in background

Packages

rospack [tab]  # List all rospack options
rospack list  # List all ROS packages installed
rospack find  # Search for specific package installed
catkin_create_pkg  # Create new package folder
roscd [pkg name]  # Jump to folder of a package by name

Nodes

rosrun [package name] [node executable]  # Start ROS node
rosrun turtlesim turtlesim_node
rosnode list  # list all nodes currently running
rosnode info /turtlesim

Topics

rostopic list
rostopic info [topic]
rostopic echo [topic]  # Prints stream of messages on this topic.
rostopic hz [topic]  # Shows how frequently topic messages are publishing.
rostopic pub /topic_name message_type "data"  # Publish message on a topic once.
	# Since each topic has a specific message type, just [tab] after
	# the topic name and it will fill in the message type.
rostopic pub /topic_name [tab] [tab]  # Publish message on a topic once.
	# First tab fills in message type.
	# Second tab provides blank message for you to fill in.
rostopic pub /topic_name [tab] [tab] -r 1  # Rate (-r) flag, publish 1/sec.
rostopic pub /topic_name [tab] [tab] --once  # Sends 1 message then kills it.

Graphical Tools

rqt  # All graphical tools
	rqt [tab]  # See all rqt plugins and launch them directly
rviz

ROS Bags

rosbag record -a  # Record all messages to a bag file.
rosbag info [your_bag_file.bag]  # Inspect a bag file.
rosbag play [your_bag_file.bag]  # Play back a bag file.
rosbag filter [your_bag_file.bag] [filtered_bag_file.bag] "topic == '/camera/image' or topic == '/imu/data'"
	# Copy specific messages from one bag file to a new bag file.
rosbag info [your_bag_file.bag]  # See list of topics and types within bag file.

ROS Messages

rosmsg show [message_type]  # Show format of a message type.

Catkin Tools (Optional Package)

sudo sh \
    -c 'echo "deb http://packages.ros.org/ros/ubuntu `lsb_release -sc` main" \
        > /etc/apt/sources.list.d/ros-latest.list'
wget http://packages.ros.org/ros.key -O - | sudo apt-key add -
sudo apt-get update
sudo apt-get install python3-catkin-tools
sudo pip3 install -U catkin_tools
catkin init  # from workspace root folder
catkin build  # from workspace root folder
sudo apt-get install python-wstool
sudo pip install -U wstool
wstool init src PATH_TO_ROSINSTALL_FILE.rosinstall  # from workspace root folder
wstool update -t src
# ROS Noetic
sudo apt-get install python3-rosdep
# ROS Melodic and earlier
sudo apt-get install python-rosdep
# All versions
sudo pip install -U rosdep

sudo rosdep init
rosdep update
rosdep install AMAZING_PACKAGE
rosdep install --from-paths src --ignore-src -r -y
ros::init(argc, argv, "rosbot_node")  // create ros node
RosbotClass::get_position()  // get published message "position"
ROS_INFO_STREAM("hello")  // print to the console - automatically timestamped
ROS_INFO_STREAM(x_2 << " and " << y_2);
ROS_INFO();

Compiling and Running

# Compile Using ROS - catkin_make
cd ~/catkin_ws
catkin_make
source devel/setup.bash

# Compile Using ROS - catkin build
# Catkin Tools must be installed.
cd ~/catkin_ws
catkin build
source devel/setup.bash

# Run
rosrun c_scripts unit1_exercise  # pass package and program

# Compile using g++
g++ -std=c++11 name.cpp -o name_compiled
# Run
./name_compiled

Other

~  # Private namespace prefix

Unused

catkin_init_workspace  # Initialize new workspace (run in xxxxx_ws folder)

Last updated 1 year ago

wstool

rosdep

wstool ROS Docs
rosdep ROS Docs