Skip to content

Latest commit

 

History

History
59 lines (34 loc) · 1.98 KB

File metadata and controls

59 lines (34 loc) · 1.98 KB

Simple ROS 2 Subscriber in C++

A simple ROS 2 node which subscribes to messages of the topic ros2_simple_cpp.

Prerequisites

  • ros-base snap. The base snap which provides the ROS 2 runtime binaries. Has to be installed on ctrlX OS. See ROS 2 Humble Base Snap.
  • An Ubuntu based build environment to build an app. See ctrlX Automation SDK.

Basis for this Project

This project is based on the official ROS 2 Tutorial: Writing a simple publisher and subscriber (C++).

Building a Snap

Building a snap has two steps:

  1. Colcon build: CMakeLists.txt defines how compile and link the C++ sources.
  2. snap build: snap/snapcraft.yaml defines how the compiled binaries are packed into the snap and how they are called on ctrlX OS.

Colcon Configuration

The colcon build tool is configured by CMakeLists.txt.

This section defines the ROS 2 packages needed:

find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)

And here the executables and their dependencies are defined:

add_executable(listener src/subscriber_member_function.cpp)
ament_target_dependencies(listener rclcpp std_msgs)

Snapcraft Configuration

snap/snapcraft.yaml defines how the snap will be build:

  • install/ is dumped into the snap
  • also wrapper/
  • Two apps (talker and listener) are copied into the snap and started as services
  • The snap - respectively the executables - uses the content interface of the ros-base snap (here the ROS 2 runtime is provided).

Build the Snap

Start this script:

./build-snap-amd64.sh

About

SPDX-FileCopyrightText: Copyright (c) 2023 Bosch Rexroth AG

https://www.boschrexroth.com/en/dc/imprint/

Licenses

SPDX-License-Identifier: Apache-2.0