Skip to content

Instantly share code, notes, and snippets.

@sytrus-in-github
Last active August 26, 2022 11:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sytrus-in-github/5fae81ead75ad27c1220bd4ec499e36b to your computer and use it in GitHub Desktop.
Save sytrus-in-github/5fae81ead75ad27c1220bd4ec499e36b to your computer and use it in GitHub Desktop.
A cheat-sheet-like summary of the ROS tutorial

ROS tutorial summary

1 ROS environment management

1.1 check ROS environment

printenv | grep ROS

1.2 setup ROS environment (can be added to ~/.bash_profile for autosetup on each login)

source /opt/ros/<distro>/setup.bash (for Bash, don't use sth else like setup.sh!)

2 ROS (catkin) workspace management

2.1 create ROS (catkin) workspace

mkdir <path_to>/<workspace_name>/src

cd <path_to>/<workspace_name>/src

catkin_init_workspace

2.2 build workspace

cd <path_to>/<workspace_name>

catkin_make [--source <src_dir>] (this will create build and devel folders)

catkin_make install [--source <src_dir>] (optional, like make install)

!!! --source should be used to specify the source directory if it is not named ./src.

[i] further reading on CMake&Make and ./configure && make && make install.

2.3 overlay workspace on top of the environment

source <path_to>/<workspace_name>/devel/setup.bash (for Bash, don't use sth else like setup.sh!)

2.4 check workspace overlay

echo $ROS_PACKAGE_PATH (should include /opt/ros/<distro>/share and the src folder of the workspace)

3. ROS Filesystem Tools

!!! Tab completion works for its commands.

3.1 rospack

- get ROS package path

rospack find <pkg_name>

- check package dependencies

!!! if fails with [rospack] Error: the rosdep view is empty: call 'sudo rosdep init' and 'rosdep update', run rosdep update

-- check 1st-order package dependencies

rospack depends1 <pkg_name>

-- check all package dependencies

rospack depends <pkg_name>

3.2 rosbash

- change directory (cd) to a (subdirectory of) ROS package or stack

roscd <pkg_name>[/<sub_dir>]

!!! Will only find ROS packages in ROS_PACKAGE_PATH, check with echo $ROS_PACKAGE_PATH.

- switch to ROS log directory

roscd log

- list information (ls) of a (subdirectory of) ROS package or stack

rosls <pkg_name>[/<sub_dir>]

- edit file inside a package

[EDITOR='nano -w'] rosed <pkgname> <filename> (change environment variable $EDITOR to specify editor)

- run a ROS executable (node)

rosrun <pkgname> <nodename> [ARGS]

-- remapping arguments

rosrun can remap names in a node to run it in different ways.

  • to change a (topic) name within a node: rosrun <pkgname> <nodename> <old_name>:=<new_name>
  • to change the name of a node: rosrun <pkgname> <nodename> __name:=<new_nodename>
  • to assign value val to private parameter param of a node: rosrun <pkgname> <nodename> _param:=val
  • to change the namespace (from the package name) of a node: ROS_NAMESPACE=<new_namespace> rosrun <pkgname> <nodename>

4 ROS package management

4.1 ROS (Catkin) package creation

cd <path_to>/<workspace_name>/src

catkin_create_pkg <pkg_name> [<depend_pkg_1> <depend_pkg_2> ...]

4.2 ROS package customization (package.xml)

- package description

<description>The xxx package</description>

- maintainer tag

<maintainer email="user@todo.todo">user</maintainer>

- license tag

<license>BSD</license>

- dependencies tags

build tool packages: <buildtool_depend>catkin</buildtool_depend>

packages needed at compile time: <build_depend>std_msgs</build_depend>

packages needed at runtime: <run_depend>python-yaml</run_depend>

packages needed for test: <test_depend>gtest</test_depend>

4.3 ROS (Catkin) package build

Build its workspace. See 2.2

5 ROS commands

5.0 concept overview

See appendix A.

5.1 initialization of the ROS environment

roscore (blocking initialize Master + rosout + parameter server)

5.2 ROS nodes

- rosnode command

rosnode offers information and operations on currently running nodes.

  • rosnode ping [-a / -c count] <nodename> check if a node is (easily) reachable
  • rosnode list list active nodes
  • rosnode info <nodename> print information about node
  • rosnode machine [<machinename>] list nodes running on a particular machine or list machines
  • rosnode kill [-a] <nodename> kill a running node
  • rosnode cleanup purge registration information of unreachable nodes

- rosrun command

rosrun <pkgname> <nodename> [ARGS] see rosbash commands

it runs a node within a package by name.

- roslaunch command

roslaunch <pkg_name> <file.launch> starts nodes as defined in a launch file: wrapped in <launch></launch> tag; nodes to be launched are specified by <node pkg="pkg_name" name="given_name" type="real_node_name"></node>;remapping arguments are specified by <remap from="orignial_arg" to="new_arg" /> within <node> tag; nodes can be grouped and given a namespace by wrapping <node> tags within <group ns="namespace"> </group>.

5.3 ROS topics/messages

- rostopic command

rostopic offers information and operations on ROS topics.

  • rostopic bw display bandwidth used by topic
  • rostopic delay display delay of topic from timestamp in header
  • rostopic echo print messages to screen
  • rostopic find find topics by type
  • rostopic hz display publishing rate of topic
  • rostopic info print information about active topic
  • rostopic list list active topics
  • rostopic pub publish data to topic
  • rostopic type print topic or field type

- rosmsg command

rosmsg shows information about ROS Message types.

  • rosmsg show Show message description
  • rosmsg info Alias for rosmsg show
  • rosmsg list List all messages
  • rosmsg md5 Display message md5sum
  • rosmsg package List messages in a package
  • rosmsg packages List packages that contain messages

5.4 ROS services

- rosservice command

rosservice offers information and operations on ROS services.

  • rosservice args <servicename> print service arguments
  • rosservice call <servicename> [<args>] call the service with the provided args
  • rosservice find <srv_type> find services by service type
  • rosservice info <servicename> print information about service
  • rosservice list [-n] [<namespace>] list active services (with provider nodes / in namespace)
  • rosservice type <servicename> print service type
  • rosservice uri <servicename> print service ROSRPC uri

- rossrv command

rossrv shows information about ROS service types.

  • rossrv show <srv_type> Show service description
  • rossrv info <srv_type> Alias for rossrv show
  • rossrv list List all services
  • rossrv md5 <srv_type> Display service md5sum
  • rossrv package [-s] <pkg_name> List services in a package
  • rossrv packages [-s] List packages that contain services

5.5 ROS parameter server

rosparam shows and manipulates data on the ROS Parameter Server.

  • rosparam set [opt] <param> <val> set parameter
  • rosparam get [opt] <param> get parameter
  • rosparam load [-v] <filename.yaml> [<namespace>] load parameters from file
  • rosparam dump [-v] <filename.yaml> [<namespace>] dump parameters to file
  • rosparam delete [-v] <param> delete parameter
  • rosparam list [<namespace>] list parameter names

6. ROS GUI utilities: rqt

6.1 rqt_graph

It visualizes the ROS node graph with topic connections. rosrun rqt_graph rqt_graph

6.2 rqt_plot

It plots the evolution of data published to a topic in time.

6.3 rqt_topic

It displays information about ROS topics.

6.4 rqt_console

It displays and filters ROS messages.

6.5 rqt_logger_level

It adjusts the logger level of ros nodes. Only superior levels are displayed. (Fatal > Error > Warn > Info > Debug)

7. ROS coding

7.1 msg file and srv file creation

msg(srv) file has extension ".msg"(".srv"), are stored in /msg/(/srv/) sub-folder of the package and contains 1 list (2 lists seperated by a line of "---") of variables of build-in message types: bool, [u]int[8/16/32/64], float[32/64], string, time, duration, fixed-length array (type[size]) / variable-length array (type[]), Header and other msg files with respective variable names (plus a value for a constant), each taking 1 line: type var_name [= val].

- package configuration
  • In package.xml, add/uncomment <build_depend>message_generation</build_depend> and <run_depend>message_runtime</run_depend>.
  • In CMakeLists.txt
    • add message_generation in find_package list
    • uncomment/add the generate_messages list with lines DEPENDENCIES, std_msgs and all other packages dependencies containing .msg files in use.
    • add message_runtime in catkin_package list line CATKIN_DEPENDS
    • (for srv) uncomment/add the add_service_files list with FILES in the 1st line and continue with all srv files of the package.
    • (for msg) uncomment/add the add_message_files list with FILES in the 1st line and continue with all msg files of the package.

!!! (re)make the package after this using catkin_make install

ROS diagnosis: roswtf

roswtf is a tool for diagnosing issues with a running ROS system. Just run it when in trouble.

A. ROS concept overview

http://wiki.ros.org/ROS/Concepts

  • node: a process (executable) that performs computation and uses decoupled undirectional streaming topics, client-active blocking remote procedure call services, and the Parameter Server etc. to communicate with other nodes. It is uniquely identified by its name.
  • Client Libraries: libraries that let you write ROS nodes, publish and subscribe to topics, write and call services, and use the Parameter Server. Support C++ by roscpp, Python by rospy, Lisp by roslisp, etc.
  • topic: named buses over which nodes exchange messages which decouples the production of information from its consumption. It is intended for unidirectional, streaming communication. Strongly typed by the ROS message type msg file.
  • service: request / reply interaction between nodes by a pair of messages: one for the request and one for the reply. A providing ROS node offers a service under a string name, and a client calls the service by sending the request message and awaiting the reply. Defined using srv files.
  • names:
    • Graph Resource Name: ROS-Computation-Graph-level concept provide a hierarchical naming structure (linux-filesystem-like) for all resources in a ROS Computation Graph, such as Nodes, Parameters, Topics, and Services. There are four types of Graph Resource Names in ROS:
      • base: direct relative names node1 -> /pkg/node1
      • relative: relative to current package foo/bar -> /pkg/foo/bar
      • global: considered fully resovled /foo/bar -> /foo/bar
      • private: relative to current node ~foo/bar -> /pkg/node/foo/bar
    • Package Resource Name: Filesystem-Level concept simplify the process of referring to files and data types on disk. It is name of the Package that the resource is in plus the name of the resource (Package Resource Name = package name + Graph Resource Name).
  • message: C-struct-like data structure containing fields and constants specifying the content for communication between nodes.
  • bag: a format for saving and playing back ROS message data from ROS topics.
  • msg: messages description language for describing the messages that goes by the topics formatted as a list of data field (type name) descriptions and constant(type name = val) definitions on separate lines. Has commonly a header.
  • svc: service description language for describing ROS service types as 2 msg lists seperated by a line of "---"
  • master: provides naming and registration services to the rest of the nodes in the ROS system, pointing nodes to desired destinations so that they could then communicate P2P.
  • rosout: ROS equivalent of stdout/stderr. Package for system-wide logging mechanism for messages sent to the /rosout topic.
  • parameter: global variable with hierachical names and access (dictionary-based).
  • parameter server: a global, multi-variate dictionary intended for configuration parameters (not efficient for large data block).

!!! difference between ROS topic/service/actionlib

B. YAML syntax

http://wiki.ros.org/ROS/YAMLCommandLine

1 is an integer, 1.0 is a float, one is a string, true is a boolean, [1, 2, 3] is a list of integers, and {a: b, c: d} is a dictionary

TODO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment