GitHub - Zard-C/rclc_example: Example codes for ros2/rclc

Example codes as a complement to rclc/examples

ROS2 Distro: Humble

docker image: tonghezhang/ros2_x86:humble_lint_0.1

Examples

  1. timer with context
  2. publish with loaned_msg
  3. subscription with loaned msg
  4. subscription with context

prerequisites

To use subscription_with_loaned_msg, we need to add msg_loan in rclc/executor.c

rcl_take_loaned_message

take loaned message

rcl_return_loaned_message_from_subscription

return loaned message

This change is already on branch humble_add_msg_loan_in_sub_callback of my fork of ros2/rclc,

currently, you can use my repo rclc to test this feature

build rclc from source

git clone https://github.com/Zard-C/rclc.git
git checkout humble
colcon build --packages-select rclc

build rclc_example from source

colcon build --packages-select rclc_example

use ros2's default middleware (fastrtps) zero copy feature

export FASTRTPS_DEFAULT_PROFILES_FILE=${PATH_TO_CONFIG}/fast_dds_profiles.xml
export RMW_FASTRTPS_USE_QOS_FROM_XML=1

replace ${PATH_TO_CONFIG} with your own path (we have a demo in demo_config_file)

Build

colcon build --packages-select rclc_example

dependencies and version

Zard-C/rclc

environment

source /opt/ros2/humble/setup.bash
source ${rclc}/install/setup.bash
source ${rclc_example}/install/setup.bash

# for using fastrtps's zero copy, in your rclc_example workspace
export FASTRTPS_DEFAULT_PROFILES_FILE=${PATH_TO_CONFIG}/fast_dds_profiles.xml
export RMW_FASTRTPS_USE_QOS_FROM_XML=1

# run in one terminal
./build/rclc_example/pub_loaned_msg

# run in another terminal
./build/rclc_example/sub_loaned_msg

features

  • timer_with_context
  • publish_with_loaned_msg
  • subscription_with_loaned_msg
  • subscription_with_context