Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rclrs/minimal_pub_sub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ anyhow = {version = "1", features = ["backtrace"]}
rclrs = "0.6"
rosidl_runtime_rs = "0.5"
example_interfaces = "*"
clap = { version = "4.5.51", features = ["derive"] }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually dependencies are only so specific if they need a fix that is present in the requested minor / patch version. Does your example need anything specific from 4.5.51 or is 4.5, or even 4 good enough? If so can you just change it to the less strict requirement?


# This specific version is compatible with Rust 1.75
backtrace = "=0.3.74"
Expand Down
15 changes: 14 additions & 1 deletion rclrs/minimal_pub_sub/src/minimal_publisher.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
use anyhow::{Error, Result};
use rclrs::*;

use clap::Parser;

/// Simple program to publish ROS 2 messages using clap
#[derive(Parser, Debug)]
#[command(long_about = None)]
struct Args {
/// Number of messages to publish
#[arg(short, long, default_value_t = u32::MAX)]
count: u32,
Comment on lines +11 to +12

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to make this an Option<u32> and, if None, we don't limit the number of messages instead of publishing u32::MAX messages?

}

fn main() -> Result<(), Error> {
let args = Args::parse_from(extract_non_ros_args(std::env::args())?);

let context = Context::default_from_env()?;
let executor = context.create_basic_executor();

Expand All @@ -13,7 +26,7 @@ fn main() -> Result<(), Error> {

let mut publish_count: u32 = 1;

while context.ok() {
while context.ok() && publish_count <= args.count {
message.data = format!("Hello, world! {}", publish_count);
println!("Publishing: [{}]", message.data);
publisher.publish(&message)?;
Expand Down