robotics,

Robot Operating System - Command Line Tools

Jan 23, 2019 · 12 mins read
Robot Operating System - Command Line Tools
Share this

ROS is an opensource middleware framework providing seamless interaction between software-software and hardware-software components of robots. With features like package management, hardware-level abstraction and support for almost all kinds of software tools and packages needed for robotics; ROS creates a language agnostic environment that allows development under the same umbrella.

The most important features of ROS include software packages for perception, control, data-manipulation and data logging among others and the ability to sustain a system running across multiple machines asynchronously. It also supports 3D visualization and simulation platforms like RViz and Gazebo.

This article explains the important aspects of ROS, common tools and their usage.

NOTE: This article may be best suited for readers with some previous exposure and awareness about ROS as most of content is a concise summary and aimed at covering the breadth of the concepts rather than being thorough.

Introduction

The communication architecture is the backbone of the ROS ecosystem. It supports mainly two paradigms - one, the synchronous RPC-style communication through services and two, the asynchronous publisher-subscriber based communication. Most of the concepts in ROS revolve around deploying multiple software packages for different tasks and use either of the two communication techniques as per requirements to make the distributed robotic system interact and work together.

It is important to understand the ROS filesystem where packages are the easiest to build, release and create code compatible with ROS. Packages have the algorithmic implementations of the concept and all ROS infrastructure along to possibly run nodes(ROS runtime processes) and use other ROS-dependent libraries, datasets, config files.

Also, there are few important concepts about the rules during interactions, limitations of ROS and best practices.

ROS Workspace

ROS uses the concept of a catkin_workspace which basically supports multiple independent ROS packages while handling all the linking with the ROS ecosystem and sharing common resources for the multiple packages within the workspace.

The workspace is essentially a folder where multiple catkin ROS packages can be installed, built and modified. Catkin operates with the meta-build system and uses CMakeLists.txt to build the packages with defined targets, dependencies and integration with the ROS ecosystem.

  • Create a ROS catkin_workspace
    ~$ mkdir -p catkin_workspace && cd catkin_workspace && mkdir -p src && catkin_make

Now the ROS workspace is created and the directory structure looks like

ROS Catkin Workspace Directory Structure ROS Catkin Workspace Directory Structure

The workspace has 3 main folders:

  • src - The folder containing the source code for all the packages in the workspace. It is the directory to be used for modifications
  • build - This folder is where the CMake system runs to generate the build and cache files that are needed during compilation
  • devel - It is the folder where the built files reside before installation of the packages

  • Source the ROS workspace to make the ROS ecosystem recognize and search the packages define within the package
    ~$ source catkin_workspace/devel/setup.bash

  • Create a ROS package
    ~$ cd catkin_workspace && src && catkin_create_pkg <package_name>     std_msgs roscpp rospy <ros_dependency>

Remember to source the workspace after building the package to register the new developments with the ROS ecosystem.

ROS Computation Graph-Level

 ROS Computation Graph
ROS Computation Graph

ROS operates on some fundamental principles involving nodes, messages, topics, parameter server, master, launch files, services and bags.

These components are the essential building blocks of any robotic system working with ROS.

NOTE: On a ROS installed machine, you could try all the terminal commands mentioned below. Package specific commands use the turtlebot package that can be installed with instructions from here.

ROS Master-Node Integration
ROS Master-Node Integration

Master

ROS master provides registration to the main ROS framework and ability to look up for other nodes/services or other sections of the Computation Graph in general. Without master, message exchange or service requests are not possible.

  • Run the ROS master and the ecosystem to support topics, messages, nodes and all other ROS infrastructure
    ~$ roscore

  • Launch multiple ROS nodes with certain properties, setting features on the parameter server locally or remotely via SSH.
    ~$ roslaunch <package_name> <launch_file.launch>

Example - To run ROS node that navigates the Turtlebot robot manually using inputs from the keyboard and also runs the roscore from within the launch file (basically multiple nodes run from the same launch file).
~$ roslaunch turtlebot_teleop keyboard_teleop.launch

  • Run a particular node in the package directly without launch file
    ~$ rosrun <package_name> <executable_binary>

Example: To run the keyboard_teleop
~$ rosrun &turtlebot_teleop> <turtlebot_joy>

Packages

A ROS package is collection of source code with ROS nodes, launch files, definitions for custom messages, datasets and any additional libraries. ROS packages are generally collections of softwares for defined for particular robotic task or domain.

Example Nodes - gmapping (Laser-based SLAM package), rtab_map (Real Time Appearance-based Mapping using in SLAM)

rospack crawls the ROS_PACKAGE_PATH and ROS_ROOT to extract information from the multiple directories and sub-directories.

  • Display the list of packages currently installed
    ~$ rospack list

  • Find a particular package from the list of packages currently installed
    ~$ rospack find <package_name>

  • Displays the list of packages that take maximum time to crawl and displays the time taken as well. It helps optimize the usage understanding if the location of the package is too deep sub-directory.
    ~$ rospack profile --length=<number_of_packages>

Filesystem Handling

ROS provides some terminal commands that allow crawling through the directories to provide filesystem handling terminal commands for ROS specific packages, workspace and libaries. rosbash is a package with bash/terminal commands and allows for tab-completion and these commands are largely a part of this suite.

*Enter a ROS package
~$ roscd <package_name>

*View the contents of a ROS package
~$ rosls <package_name>

*ROS equivalent of pushd to access multiple directories and switch between them seamlessly while also keeping them in the stack
~$ rospd <package_name>

*List the ROS package directories in the directory stack
~$ rosd

*Edit any file of a ROS package in the terminal with default vim or other user specified editor
~$ rosed <package_name> <filename>

Nodes

Nodes run independently doing a modular task and might share(receive or accept) information from some other concurrent node. They are organized in packages are generally run via launch files. Example Nodes - Motion Planning node, laser scanner node, localization node Data Exchange Structure - Laser Scanner Node -> Localization Node -> Motion Planning Node rosnode is the package that provides command-line interface to investigate and debug the ROS nodes currently running.

*List the current ROS nodes
~$ rosnode list

*Obtain information about a ROS node’s publications, subscriptions, services and process ID
~$ rosnode info <ros_node_name>

*Obtain information about a ROS node’s publications, subscriptions, services and process ID
~$ rosnode info <ros_node_name>

*Kill a ROS node or all nodes
~$ rosnode kill <ros_node_name>
~$ rosnode kill -a

*Check the connectivity of a ROS node - Returns the time taken to get a reply with the XML RPC(remote procedure call)
~$ rosnode ping <ros_node_name>

*Obtain the list of nodes on the particular machine
~$ rosnode machine <machine_address>

Parameter Server

Parameter server is a dictionary that allows data storage in a central memory location for ROS accessible via network APIs. It is generally suitable for static data that is not modified frequently but only accessed at runtime by ROS nodes for values like configuration parameters. It supports all basic data types like integers, boolean, string and doubles among several others.

rosparam is another ROS package for command-line interface for interaction with the ROS parameters.

  • Get the list of ROS parameters on the server by name
    ~$ rosparam list

  • Get the value of a ROS parameter
    ~$ rosparam get <parameter_name>

  • Set the value of a ROS parameter on the server
    ~$ rosparam set <parameter_name> <parameter_value>

  • Delete a ROS parameter from the server
    ~$ rosparam delete <parameter_name>

  • Dump or download the parameters from the server to a file in the YAML format
    ~$ rosparam dump <file_name.yaml>

  • Upload the parameters from a YAML file on to server
    ~$ rosparam load <file_name.yaml>

Messages

Fundamental component of the communication setup between nodes is the data. ROS messages are essentially data structures formed out standard primitive data types. For example, pose message has the data structure (float x, float y, float z) and orientation (float rw, float rx, float ry, float rz). ROS allows defining messages composed of a collection of different data types.

A detailed list of data types for the messages is found on the ROS Wiki here. rosmsg is the ROS package that provides support for messages types and service types.

  • Obtain the details of a ROS message type
    ~$ rosmsg show <message_type>

  • Obtain the list of messages from the current packages and libraries
    ~$ rosmsg list

  • Obtain the details of all ROS messages in a package
    ~$ rosmsg package <package_name>

ROS messages & Topics ROS messages & Topics

Topics

Topic is the channel to which messages are published to or subscribed from. A ROS node sends out data by publishing to a topic while another node might subscribe to it to fetch the data It is a standard message bus - topic is a name to identify the content of the message and publishers and subscribers don’t know each other; so, essentially decoupled. One publisher/subsriber can publish and subscribe to many topics.

rostopic is a command-line tool for investigating into currently operational ROS topics.

  • List of ROS topics being published/subscribed to currently.
    ~$ rostopic list

  • Display the data content of the ROS topic on the terminal
    ~$ rostopic echo <topic_name>

  • Find all topics with a particular message type
    ~$ rostopic find <message_type>

  • Display the publishing rate of the topic
    ~$ rostopic hz <topic_name>

  • Display the bandwidth of the topic
    ~$ rostopic bw <topic_name>

  • Obtain information about the topic - publishers, subsribers
    ~$ rostopic info <topic_name>

  • Display the contents of the ROS topic on the terminal
    ~$ rostopic pub <topic_name> <msg_type> <msg_data>

  • Obtain the message type for the topic
    ~$ rostopic type <topic_name>

Services

Services are the peer-to-peer RPC style synchronous communication paradigm in ROS. They are defined by a request-reply pair of data structure with one carrying the request variable and other storing the received result.

rosservice is a package to provide command-line interface for investigating details about the service. It includes obtaining information about message type, URI or the argument. It eventually also allows to call the service from the terminal.

ROS Services ROS Services

  • Call a ROS service from the command line with arguments to be passed
    ~$ rosservice call <service_name> <arguments>

  • Display the services of a particular type
    ~$ rosservice find <service_type>

  • Obtain the list of services
    ~$ rosservice list

  • Obtain details on a ROS service
    ~$ rosservice info <service_name>

  • Obtain the arguments of a ROS service
    ~$ rosservice args <service_name>

  • Obtain the URI of a ROS service
    ~$ rosservice uri <service_name>

Bags

Format for saving and replaying the ROS messages. Can be used to store data from sensors/other factors that need post-processing or to reuse. ROS bags can virtually simulate sensor data or basically a robot behavior by publishing to the topic.

rosbag is command-line tool providing inteface with the bags with options to view, modify and observer stored information.

  • Record information from a topic to a ROS bag
    ~$ rostopic record <topic_name>

  • Compress the information in a ROS bag to save space
    ~$ rostopic compress <rosbag_filename.bag>

  • Publish the contents of a ROS bag onto the topic as per the timestamps from the initial recording
    ~$ rostopic play <rosbag_filename.bag>

  • Check if a ROS bag file shall work on playback
    ~$ rostopic check <rosbag_filename.bag>