The intention of this collection is to give you a very quick overview of ROS and act a 'cheatsheet'. For a more through analysis of ROS and its packages, refer to the ROS wiki.
Note:
Commands followed by a ✶ will take over an instance of your terminal. As a result, to run each instance of these commands, you will need a new terminal (having a terminal emulator that can be tabbed will go a long way in preventing clutter). Don't forget to pay attention to the output of these programs as they are used for warnings and errors. To end a program while keeping the terminal window open, press Ctrl-C
. Additionally, be careful to not accidentally close these terminals as they will end the program they are running.
$ roscore
✶ Does not take any additional arguments and needs to be running the entire time you are working with ROS (in other words, run this first always). Keep in mind that stopping roscore will prevent all running nodes from establishing new connections, even if you start a new instance of roscore.
$ rosrun package-name executable-name arg-name:=arg-value
✶ Starts a running instance of a program (i.e. a node). The first parameter is a package name and the second one is an executable in said package.
After that, you can name and specify command-line arguments (as many as you like) using the :=
assignment.
Keep in mind that rosrun starts only one node. For more nodes, you need more terminals and other instances of rosrun.
$ roslaunch package-name launch-file-name
✶ Launches a number of nodes. The first parameter is a package name and the second one is a launch file that details a group of nodes that should be started at the same time.
$ rosnode list
Lists currently running nodes. You should always see the /rosout
node which is started by roscore at all times.
$ rosnode info node-name
Outputs information about a node. It includes a list of topics for which the node is a publisher or subscriber and a summary of the connections it has made to other nodes.
$ rostopic list
Provides a list of active topics.
$ rostopic echo topic-name
✶ Shows the actual messages getting published on a single topic. Only outputs messages that are published while the program is running. Can be performed on topics and sub-parts of topics.
$ rostopic info topic-name
Shows details about the message types of selected topic and publishers and subscribers to the the topic.
$ rosmsg show message-type-name
Shows details about a message type, including the fields and their names.
$ rostopic pub --rate=x topic-name message-type msg
Repeatedly publishes the given message on the given topic at the given rate in HZ. Once you get to typing msg, double tap tab and the terminal should fill out a stub message for you (based on message-type).
$ rosbag record -O filename.bag topic-names
✶ Records the messages published to topics specified by topic-names in a file specified by filename.bag. It is important to note that rosbag will only record messages while it's running. So, start a recording before your desired messages are sent to the desired topics and end the recording once they are done.
-a
records on every topic. -j
compresses the recording. -x "regex"
excludes a topic that matches the regex from the recording. Some topics (e.g. /camera/rgb/image_raw
) will take a lot of space in a bag file. In such scenarios, this flag is handy. $ rosbag info filename.bag
Inspects a bag file. In particular, it lists out message count, duration, and topic lists. Use this command to ensure your bag files meet submission requirements.
$ rosbag play filename.bag
Replays recorded messages in the same manner they were recorded. While replaying, make sure no other node's publishing is interfering with the recordings. Additionally, keep in mind that while a recording contains every message published, it has no information about initial conditions. Hence, replays might lead to different outcomes depending on your setup. Be sure to specify initial conditions if necessary somewhere else.
$ rosrun rviz rviz
✶ or simply run:
$ rviz
✶ Starts a GUI that allows you to observe what your robot sees (there will be a dark panel in the middle if you have yet to connect a robot to it). Keep in mind that RViz is just an observation tool. It is unable to actually control your robot.
$ roslaunch turtlebot3_gazebo turtlebot3_gazebo_rviz.launch
✶ Launches an RViz instance that automatically connects to the gazebo simulator and sets up the RViz based on the waffle_pi robots.
The ROS software is provided in packages. These packages include nodes, libraries, datasets, or anything that constitutes something useful. A package is usually maintained in a folder with the same name and has a number of files and folders. The relevant files and folders for this course are,
msg/
: Folder containing Message (msg) types.scripts/
: Executable scripts.launch/
: Package launch files.worlds/
: Folder containing the world files.CMakeLists.txt
: CMake build file.package.xml
: An XML file that holds information about the package (packages name, authors, dependencies, etc.) and is required to have the package be compliant with the ROS ecosystem.To create a ROS package, you need to first navigate to the source directory in your catkin workspace,
$ cd ~/catkin_ws/src/
Then we can use catkin_create_pkg
to create a package,
$ catkin_create_pkg package_name [dependency1] [dependency2] [dependency3] ...
Here is an example package with some basic dependencies,
$ catkin_create_pkg intro_robo_sample_pkg std_msgs rospy roscpp
Running the above command will create a folder with the name intro_robo_sample_pkg
, which includes some basic files and folders. For further information on creating ROS packages, refer to this tutorial.
Run the following command to build your new package,
$ cd ~/catkin_ws && catkin_make
$ source devel/setup.bash
msg files are simple text files that describe the fields of a ROS message. msgs are simply text files with with a field type and a field name per line. Here is the Vector3
msg as an example,
float64 x
float64 y
float64 z
In the above example, we can see that the Vector3
msg has three 64bit float fields named x,y, and z. In a ROS msg file, the field types always come on the left are immediately followed by a name that will refer to that name. The following filed types are allowed,
Attention: Although we will be using Python (which is dynamically typed), you should pay close attention to the filed types of the msg you are using. If you assign an inappropriate value to a filed, python will not complain, but ROS will refuse to publish your msg.
If you have included a msg file in your package, you should be able to easily reference it in your scripts. For more information, refer to this tutorial
source your-neotic-directory/devel/setup.bash
. chmod u+x script_name
.