ROS2 Guidelines

Packages

Structure

my_package
β”œβ”€β”€ config
β”‚   └── params.yml
β”œβ”€β”€ include
β”‚   β”œβ”€β”€ lib
β”‚   β”‚   └── my_library.h
β”‚   └── my_node.h
β”œβ”€β”€ launch
β”‚   └── my_launch_file.py
β”œβ”€β”€ lib
β”‚   └── my_library.cpp
β”œβ”€β”€ src
β”‚   β”œβ”€β”€ my_node.cpp
β”‚   └── node_composition.cpp
β”œβ”€β”€ CMakeLists.txt
└── package.xml

config and lib directories are only needed if you use parameters, or make a custom library.

Composition

Write your nodes as components! This means in your my_node.cpp file, you will just have your node class, and no main function. See thisarrow-up-right tutorial for more information.

You will have a node composition file (or multiple?), that should use executors to instantiate each node. See thisarrow-up-right page on executors.

circle-exclamation

Example node_composition.cpp

Custom Interfaces

If you create custom interfaces (messages, services, actions), you should create a separate package for them. This is due to CMake dependency issues with building messages in the same packages that uses them. There are suggested work arounds online, I havenn't been able to get any to work.

For example, if your package is called my_package, you will create another package called my_package_interfaces and use msg, srv, and action directories for your interfaces.

Parameter Files

Example

Launch Files

Rules

  • You must set a log level launch argument - see example. This allows us to control the log level from the launch file, and the terminal.

  • If using parameters, you must pass them to your node from your launch file.

Basic Example

Nodes

  • Each node is a class. Use header files.

  • Setup subscribers and publishers in class constructor

  • Write nodes as components

  • If you have a lot of complex functions - move them to a library

  • Throttlearrow-up-right log messages that are very frequent, or set to DEBUG.

How to get parameters to your node

See lidar_prop_detector_component.cpp for an example. //TODO ADD LINK TO FILE

We need to inherit from rclcpp and make our own node class and add these functions in, but for now you can do the following.

  1. Add to your node's header file:

  1. Create member variables for each parameter starting with p_.

  2. Inside your node's constructor:

Call getParam() for each param you have:

Set up your parameter callback:

  1. Write your parameter callback

Example:

Last updated