ROS CLI cheatsheet

2 minute read

Environment Setup

I add the following aliases to my .bashrc (in Linux):

export ROS_CATKIN_PATH=~/catkin_ws
export ROS_NOETIC_SETUP=/opt/ros/noetic/setup.bash

alias rosnoetic='source $ROS_NOETIC_SETUP; source $ROS_CATKIN_PATH/devel/setup.bash'
alias rosbuild='cd $ROS_CATKIN_PATH; catkin_make; cd -'

When I need ros noetic avaliable from the command line, I run rosnoetic.

When I want to rebuild my entire catkin workspace, I run rosbuild.

roscd # Go to distro root
roscd <package> # Go to <package> folder
rosls <package> # List files in <package>

Making Packages with Catkin

See Creating a workspace for catkin

General structure:

catkin_ws/
  src/
    CMakeLists.txt 
    package_1/
      CMakeLists.txt
      package.xml
      src/
      scripts/
      msg/
      srv/
      ...
    package_2/
      ...
  devel/
    setup.bash
    ...
  build/
    ...
  .catkin_workspace

Catkin can be used to build and install python and cpp packages. See the creating a package tutorial.

ROS Master

roscore

Nodes

Run a <pkg>::<node>:

rosrun <pkg> <node>
rosrun turtlesim turtlesim_node # Run turtlebot simulator.

Analyze running nodes:

rosnode list        # Show running nodes
rosnode info <node> # Show info on particular node
rosnode ping <node> # Ping your node

Topics

Analyzing topics:

rostopic list         # Show active topics
rostopic list -v      # Show active topics with types/stats
rostopic bw <topic>   # Show bandwidth of <topic>
rostopic type <topic> # Show the type name of <topic>

Subscribing to a topic from the command line:

rostopic echo <topic> # Subscribe to and echo <topic>

Publishing a topic:

rostopic pub <topic> <type> -- <data>
rostopic pub <topic> <type> -r <Hz> -- <data>

rostopic pub /hello /std_msgs/String -- "hello"
rostopic pub /hello /std_msgs/String -r 2 -- "hello @ 2Hz"

Publishing more complex structures uses YAML:

rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- \
  '{linear: {x: 2.0, y: 0.0, z: 0.0},
  angular: {x: 0.0,y: 0.0,z: 0.0}}'

Topic types can be analyzed using rosmsg:

> rosmsg show geometery_msgs/Twist
geometry_msgs/Vector3 linear
  float64 x
  float64 y
  float64 z
geometry_msgs/Vector3 angular
  float64 x
  float64 y
  float64 z

Services

Analyzing services:

rosservice list # Show all active services
rosservice info <service> # Get URI, type and args for <service>
rosservice uri <service> # Get <service> uri
rosservice type <service> # Get <service> type
rosservice args <service> # Get <service> args

Calling a service from CLI:

rosservice call <service> <args>

rosservice call /rosout/set_logger_level ros debug

Ros Service types are analyzed using rossrv:

> rossrv show turtlesim/Spawn
float32 x
float32 y
float32 theta
string name
---
string name

Params

Get/set the value of a <param>

rosparam get <param>
rosparam set <param> <value>

Launch files

Launch files allow us to create a consistent launch setup for nodes.

See the launch file tutorial for details on writing a launch file.

To run a launch file from a ROS package:

roslaunch <package> <file.launch>

Bag - data recording

Recording:

rosbag record -a                # Everything
rosbag record <topic1> <topic2> # Only topics 1 and 2
rosbag record -e <regex>        # Topics matching regex
rosbag record -a -O <name>      # Name the bag
rosbag record -h                # Show record help

Get information about bag <name>:

rosbag info <name>

Play the information in bag <name>:

rosbag play <name>
rosbag play <name> -l # Loop forever.