Skip to content

Instantly share code, notes, and snippets.

@gabrieleara
Last active June 24, 2018 07:57
Show Gist options
  • Select an option

  • Save gabrieleara/e431a4c2668ddeb2d5fb01ce4cd63102 to your computer and use it in GitHub Desktop.

Select an option

Save gabrieleara/e431a4c2668ddeb2d5fb01ce4cd63102 to your computer and use it in GitHub Desktop.

ROS Commands Cheatsheet

Initializing system

To start master node:

roscore

Node commands

  • To run a node:
rosrun <package> <nodetype>
  • To run a node with a custom name
rosrun <package> <node> __name:=<nodename>
  • To list registered nodes:
rosnode list
  • To check whether a registered node is available:
rosnode ping <nodename>
  • To check a node info:
rosnode info /<nodename>
  • To check nodes/topics graph:
rosrun rqt_graph rqt_graph

Interaction with nodes and topics

  • To interact with topics via command line:
rostopic <cmd>
  • To list possible rostopic commands:
rostopic -h
  • Listing available topics (optional argument shows more data)
rostopic list [-v]
  • Printing messages published on a topic
rostopic echo <topic>
  • Printing message types in a topic
rostopic type <topic>
  • Check the structure of a message type
rosmsg show <type>
  • Show directly topic message structure
rosmsg show $(rostopic type <topic>)
  • Alternative
rostopic type <type> | rosmsg show
  • Publish manually content
rostopic pub -1 <topic> <msg_type> -- <args>

In previous command

  • The -1 option indicates that only one message should be sent on the topic.
  • The -- option tells rostopic pub that the following arg is not an option for itself, but it's some argument of the msg_type.
  • Slightly more complex syntax that is less error-prone (you avoid typing message type by hand)
rostopic pub -1 <topic> $(rostopic type <topic>) -- <args>
  • Quick example:
rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]'
  • Publish content over and over at a fixed rate
rostopic pub -r <rate> <topic> <msg_type> -- <args>

In previous command, rate argument is a number expressed in Hz that shall be greater than zero. Quick example (with rate 1 Hz)

rostopic pub -r 1 /turtle1/cmd_vel $(rostopic type /turtle1/cmd_vel) -- '[2.0, 0, 0]' '[0, 0, -1.8]'
  • Estimate publication rate on a given topic
rostopic hz <topic>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment