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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Cargo
# will have compiled files and executables
/target/
target

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Expand Down
37 changes: 34 additions & 3 deletions rclrs/parameter_demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,41 @@ fn main() -> Result<(), RclrsError> {
.default("Hello".into())
.mandatory()?;

let _subscription =
node.create_subscription("greet", move |msg: example_interfaces::msg::String| {
let reliability_override = node
.declare_parameter::<Arc<str>>("qos_override/reliability")
.optional()?
.get();

// Use PrimitiveOptions and override the reliability if needed.
// PrimitiveOptions ensures that the subscription will use the default
// QoS of a subscription for any setting that is not overridden.
let mut subscription_options = PrimitiveOptions::new("greet");
if let Some(reliability_override_str) = reliability_override {
match &*reliability_override_str {
"reliable" => {
subscription_options.reliability = Some(QoSReliabilityPolicy::Reliable);
}
"best_effort" => {
subscription_options.reliability = Some(QoSReliabilityPolicy::BestEffort);
}
"best_available" => {
subscription_options.reliability = Some(QoSReliabilityPolicy::BestAvailable);
}
"system_default" => {
subscription_options.reliability = Some(QoSReliabilityPolicy::SystemDefault);
}
x => {
panic!("Unknown reliability override string: {x}");
}
}
}

let _subscription = node.create_subscription(
subscription_options,
move |msg: example_interfaces::msg::String| {
println!("{}, {}", greeting.get(), msg.data);
})?;
},
)?;

println!(
"Ready to provide a greeting. \
Expand Down