ROS

This post is some ROS command from ROS tutorial.

Tutorial commands

Create a ROS workspace

1
2
3
4
5
6
mkdir -p <path>/src
cd <path>
catkin_make

# can also add this to the .bashrc
source <path>/devel/setup.bash

Create ROS Packages

Packages are the software organization unit of ROS code. Each package can contain libraries, executables, scripts, or other artifacts.

A manifest (package.xml) is a description of a package. It serves to define dependencies between packages and to capture meta information about the package like version, maintainer, license, etc…

One workspace could have several packages. Each package folder has the package.xml file and the CMakeList.txt file. There is also a top level CMakeList.txt file in the <path>/src provided by catkin.

To make and build a package inside a workspace

1
2
3
4
5
6
7
8
9
10
11
cd <path>/src
catkin_create_pkg <package_name> [depend1] [depend2] ....

cd <path>
catkin_make

# don't require if previously addd this to the .bashrc
source <path>/devel/setup.bash

# Check the depends of packages
rospack depends1 <package_name>

Create a executable (node)

In <path>/src, create a cpp file with main function. Then add dependencies in CMakeList.txt. Use catkin_make to build the package.

The executable files are located in catkin_ws/devel/lib/<package_name>.

ROS Graph - Nodes, Topics and Messages

Nodes: an executable that uses ROS to communicate with other nodes
Topics: Nodes can publish messages to a topic as well as subscribe to a topic to receive messages
Messages: data type used when subscribing or publishing to a topic
Master: Name service for ROS (i.e. helps nodes find each other)
rosout: ROS equivalent of stdout/stderr
roscore: Master + rosout + parameter server

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Run the server
roscore

# Run a new node
rosrun [package_name] [node_name]
...

# Run a package with launch file
roslaunch [package_name] [filename.launch]

# Show the running nodes
rosnode list

# Show the graph containing nodes and topics communicated among nodes
rosrun rqt_graph rqt_graph
# Show the realtime data in plotted figure
rosrun rqt_plot rqt_plot
# Show the log info and set the logging verbosity level
rosrun rqt_console rqt_console
rosrun rqt_logger_level rqt_logger_level

# Show all topics info [topic message number_of_publisher/subscriber]
rostopic list -v
# Show the data logging under a topic
rostopic echo <topic_name>

# Show message (data type) in a topic
rostopic type <topic_name>
# Show details about a message
rosmsg show <message_name>

# Publish data to a topic
rostopic pub <topic_name> <message_name> [-1] [-r 1] -- <data>

Below is a rqt_graph figure showing the communications among nodes.

ROS Services

Services are another way that nodes can communicate with each other. Services allow nodes to send a request and receive a response.

1
2
3
4
5
6
7
8
9
10
11
12
13
# Show all running services
rosservice list

# Show service type
rosservice type [service_name]
# Show service required arguments
rosservice type [service_name] | rossrv show
# which equals to
rossrv show [service_type_name]

# call service
rosservice call [service_name] [argument1] [argument2] ...

ROS msg and srv file

msg: msg files are simple text files that describe the fields of a ROS message. They are used to generate source code for messages in different languages
srv: an srv file describes a service. It is composed of two parts: a request and a response

msg files and srv files are located in the src/msg and src/srv folders in a package folder. msg files contain the data type and data name; srv files contain the request and response data type and data name which are split by ---.

Once added new msg files and srv files. The package.xml and CMakeLists.txt files are required to be edited to include the new added files. Then the package needs to be make again. The generated codes files for msg and srv are located in devel/include/<package_name> (C++) and devel/lib/python3/dist-package/<package_name> (Python).

ROS Parameter Server

The Parameter Server can store integers, floats, boolean, dictionaries, and lists. rosparam uses the YAML markup language for syntax.

1
2
3
4
5
6
7
8
9
10
# Show parameter names in parameter server
rosparam list

# Set / get value of parameters
rosparam set [param_name] <value>
rosparam get [param_name]

# Save / load parameters
rosparam dumpy [file_name] [namespace]
rosparam load [file_name] [namespace]

ROS Debug

Record topic data to ROS bag

1
2
3
4
5
6
7
8
9
10
# in a folder to place the .bag file
rosbag record -a # to record all topic data

rosbag record -O <bag_file_name> [topic1] [topic2]

# play back bag file
rosbag play <bag_file_name>

# read data from bag file
ros_readbagfile <bag_file_name>

Check nodes status

1
2
roscd [package_name]
roswtf