🚀 This repository is a ROS 2 workspace (ros2_ws
) that contains a set of ROS 2 nodes written in Rust that demonstrate publisher/subscriber communication using the ros2_rust client library.
- ROS 2 (ex Humble Hawksbill): Follow the ROS 2 Installation guide for Ubuntu.
- Rust Toolchain: Install Rust.
- colcon (for building the workspace)
Follow the instructions in ros2-rust/ros2_rust to install Rust bindings for ROS 2. Once cloned and set up, build it inside your workspace (e.g., ~/workspace):
cd ~/workspace
colcon build
source install/setup.bash
This repository is already structured as a ROS 2 workspace. After cloning it, ensure it sources the ros2_rust
build:
cd ~/ros2_ws
source /opt/ros/humble/setup.bash # Source the previously installed ros2 humble setup files
source ~/workspace/install/setup.bash # Source ros2_rust
colcon build
source install/local_setup.bash
Note: The source install/local_setup.bash ensures both ros2_rust and this package are properly linked.
The nodes now use ROS 2 parameters instead of command-line arguments. Parameters can be set using --ros-args --param when running the nodes.
topic: <string> # Name of the ROS2 topic to publish to
publish_rate_ms: <integer> # Publication rate in milliseconds
prefix: <string> # Text appearing before the counter
suffix: <string> # Text appearing after the counter
count_start: <integer> # Initial counter value
topic: <string> # Name of the ROS2 topic to subscribe to
output_file: <string> # Path to the file where received messages will be logged
You can run the nodes manually using the ros2 run
command. For example:
Publisher:
ros2 run rust_nodes simple_publisher --ros-args \
--param topic:=my_topic \
--param publish_rate_ms:=1000 \
--param prefix:="Hello" \
--param suffix:="World" \
--param count_start:=0
# Publishes: "Hello 0 World", "Hello 1 World", etc. every 1 second
Subscriber:
ros2 run rust_nodes simple_subscriber --ros-args \
--param topic:=my_topic \
--param output_file:=subscriber_output.txt
For convenience, multi-level Python launch files are provided in rust_nodes_bringup
:
ros2 launch rust_nodes_bringup main_launch.py publish_rate_ms:=5000 prefix:=Hi suffix:=There count_start:=10
⚠ Configuring .cargo/config.toml
This repository includes a .cargo/config.toml
file, which must be modified for different environments:
-
It contains local file paths that reference built dependencies in
ros2_rust
. -
Update the paths in .cargo/config.toml to match your setup after building ros2_rust.
-
If the paths are incorrect, the build may fail due to missing dependencies.
Example:
If ros2_rust
was built in /home/user/my_ros2_rust_workspace
, update:
[patch.crates-io.rclrs]
path = "/home/user/my_ros2_rust_workspace/install/rclrs/share/rclrs/rust"