A scratchpad for common pitfalls, commands, and shortcuts when using ROS1.

Questions/Answers

Set an argument based on the exclusive OR of two other arguments

This is a really ugly hack, but it gets the job done. Since we don’t care much about the name, we set it so that if the user provides both of them at the same time, they get a descriptive message back.

<!-- arg1 XOR arg2 -->
<arg if="$(eval (arg1 != '') == (arg2 != ''))" name="Please_Set_Exclusively_Either_Arg1_Or_Arg2"/>
<arg if="$(eval (arg1 != '') == (arg2 != ''))" name="dummy" value="$(arg Please_Set_Exclusively_Either_Arg1_Or_Arg2)"/>

Set a parameter based on an environment variable, fallback to a default

<launch>
<arg name="mydefault" value="kalimera"/>
<arg if="$(eval optenv('KALIMERA') != '')" name="kalimera" value="$(env KALIMERA)"/>
<arg unless="$(eval optenv('KALIMERA') != '')" name="kalimera" value="$(arg mydefault)"/>

<param name="kalimera" value="$(arg kalimera)"/>
</launch>

How to debug launchfile execution

See the following CLI arguments

--wait
Delay the launch until a roscore is detected.

--local
Launch of the local nodes only. Nodes on remote machines will not be run.

--screen
Force all node output to screen. Useful for node debugging.

--log
Force all node output to log file. Also useful for node debugging.

-v
Enable verbose printing. Useful for tracing roslaunch file parsing.

--dump-params
Print parameters in launch file in YAML format.

Roslaunch conditional

<include file="..." >
<arg if="$(arg var1)" name="var" value="value" />
<arg unless="$(arg var1)" name="var" value="value2" />
</include>

Visualise topics/services/images etc from the command line (without X/OpenGL):

Use rosshow

ps -ef | grep -E ros\|melodic | awk '{print 2}' | xargs kill -9

How do I debug a URDF file and its transforms?

Use the urdfdom tools (independent package)

apt-get install liburdfdom-tools graphviz
urdf_to_graphiz <path-to-your-urdf

You can also use the xacro package and the check_urdf tool:

rosrun xacro xacro.py `rospack find pr2_description`/robots/pr2.urdf.xacro -o /tmp/pr2.urdf
check_urdf pr2.urdf

[ERROR]: Creation of publisher failed: unknown error handler name ‘rosmsg’

There is a bug in genpy for version <= 0.6.13, try apt-get upgrade-ing it

Source

Error: RQT doesn't list plugins on startup:

Remove its cache, then it works: rm ~/.config/ros.org/rqt_gui.ini

Source

I’m getting the following error: multiple files named ... in package

Disable install space.

catkin clean
catkin build <package-name> --no-install

Run catkin for the package in the current directory:

catkin build --this -DCMAKE...

Publish to /move_base_simple/goal:

rostpic pub /move_base_simple/goal geometry_msgs/PoseStamped '{header: {stamp: now, frame_id: "map"}, pose: {position: {x: 1.0, y: 0.0, z: 0.0}, orientation: {w: 1.0}}}'

Source

image_transport plugins - how to setup:

sudo apt-get install ros-melodic-\*-image-transport
rosrun image_transport republish compressed /in/compressed:=/<path-to-topic>/compressed_image0 "raw" out:=/<path-to-topic>/image0

Source

Use ninja when building with catkin_make

catkin_make --use-ninja --cmake-args -DCMAKE_BUILD_TYPE=Release

Adjust logger verbosity - inspect “debug” messages:

Run the rqt_logger_level GUI:

rosrun rqt_logger_level rqt_logger_level

Alternatively adjust it using the service call:

rosservice list
rosservice call /rviz_123/get_loggers <tab><tab>
rosservice call /rviz_123/set_logger_level <tab><tab>

Adjust the logger verbosity from the start of the run

Define your own ROSCONSOLE_CONFIG_FILE variable + config file.

rosconsole will load a config file from $ROS_ROOT/config/rosconsole.config when it initializes.

rosconsole also lets you define your own configuration file that will be used by log4cxx, defined by the ROSCONSOLE_CONFIG_FILE environment variable. Anything defined in this config file will override the default config file.

A simple example:

# Set the default ros output to warning and higher

log4j.logger.ros=WARN

# Override my package to output everything

log4j.logger.ros.my_package_name=DEBUG

List all available plugins of a particular package

rospack plugins --attrib=plugin nav_core

See also: http://wiki.ros.org/pluginlib

Have detailed output for debugging

# Try one of the following

export ROSCONSOLE_FORMAT='[${severity}] [${time}]: ${message}' # default
export ROSCONSOLE_FORMAT='${severity} | ${time} | ${message}'
export ROSCONSOLE_FORMAT='${severity} | ${node} | ${time} | ${message} | ${file}:${line}'
export ROSCONSOLE_FORMAT='${severity} | ${node} - ${thread} | ${time} | ${message} | +${line} ${file}'

ROS Unittesting

If you use only gtest then you have to add your target like this:

catkin*add_gtest(UT*${PROJECT_NAME} test/test_file.cpp
...)

However, if you also use gmock then you should use catkin_add_gmock instead!

catkin*add_gmock(UT*{PROJECT_NAME} test/test_file.cpp
...)

To run all the tests:

catkin_make run_tests

Notice that the previous call will return a 0 (success) error code in any case even if the tests fail.

To get a summary and get the appropriate error code you can either run catkin_test_results or the CTest target test:

catkin_make test

Source: https://github.com/ros/catkin/issues/576

Get all ROS topics programmatically

Query the master; from C++ use something like this:

#include <ros/master.h>
// see /opt/ros/<ros-version>/include/ros/master.h for more details on this
// struct
ros::master::V_TopicInfo allTopics;
ros::master::getTopics(allTopics);

Source

Remap a topic in the same TF Tree

<node name="remapper" pkg="tf_remapper_cpp" type="tf_remap">
<rosparam param="mappings">[{old: /slamcore/map, new: /kalimera}]</rosparam>

  <param name="old_tf_topic_name" value="/tf" />
  <param name="new_tf_topic_name" value="/tf" />
</node>

REPs of interest

REP stands for ROS Enhancement Proposal. A REP is a design document providing information to the ROS community, or describing a new feature for ROS or its processes or environment.

ROS Ecosystem - Miscellaneous Tools

  • champ: ROS packages for Quadruped Robot based on MIT Cheetah I
  • colcon: CLI Tool to improve the workflow of building, testing, and using multiple packages - Default build orchestrator for ROS2
  • vcstool: VCS Designed to facilitate working with multiple repositories
  • publish-python: Python script to publish your python code to Github Release / PyPI, etc. or generate a debian package

A Mental Model of the ROS1 Navigation Stack