ROS2

This is a general overview, and for the most part aims be version independent. However, this documentation was made with reference to Humble Hawksbill's wiki.

Terminology

Node

A node can be thought of a fundamental unit that is built for one specific task. Nodes communicate through a variety of methods, but they all involve something called an interface.

Parameters

A node can be configured using parameters. We can dump and load parameters. Parameter files are to be stored in YAML format.

Discovery

Nodes on a network with the same domain ID are able to discover other nodes. Domain IDs can range from 0 to 101 both inclusive, and are used to calculate ports for communication.

Topic

A topic can be thought of as a hub for transferring data. A node can publish data to a topic, and subscribe to a topic to receive data. This data is often called a message.

The format for a message is

<variable_type1> <variable_name1>
<variable_type2> <variable_name2>

Service

Services are like topics but they use a request-response paradigm. There can only be one service server, which can respond to multiple service clients. Each service has types that describe the structure of a request message and a response message. Suitable for short running procedures, you call a service, and an action is performed, nothing else.

The interface format for a service is

<request_message_format>
---
<response_message_format>

Action

Actions are like services, but they provide realtime feedback and can be cancelled midway. They are suitable as long running "services".

The interface format is

<goal>
---
<request>
---
<feedback>

Build system

Workspace

A ROS2 workspace contains packages, build files, logs and more, all in one folder. The src folder in a workspace contains packages.

rosdep

rosdep is a python package that uses package.xml to identify dependencies and install them. It doesn't install them itself (like apt would) but uses the system package manager. The xml tags it looks for are -

  • <depend> for deps that are required at both build and run times
  • <build_depend> for deps that are required at build time
  • <build_export_depend> for deps that will be required by an exported header file. (If we export a header that imports some other header, we list the other header here)
  • <exec_depend> for deps that are required at run time
  • <test_depend> for deps that are required only during testing

Packages

A package is a unit of self contained code, which can be released for others to use if wanted. A barebones Python package looks like this -

workspace/src/
	package_name/
		package.xml
	    resource/package_name
	    setup.cfg
	    setup.py
	    my_package/

Creating a package involved the following steps

  1. Create a package with ros2 pkg create
  2. Update dependencies in package.xml. This is done automatically if the --dependencies flag is used during the previous command
  3. Write the package code in ws/src/pkg_name/pkg_name. There should be a __init__.py file in that directory
  4. Add the main function from this newly written file as an entry point in setup.py like so script_name = pkg_name.filename_without_ext:main