Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add demo of how to use qos overrides #474

Merged
merged 8 commits into from
Dec 11, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update after last API changes
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
  • Loading branch information
ivanpauno authored and clalancette committed Dec 9, 2020

Verified

This commit was signed with the committer’s verified signature.
jar-b Jared Baker
commit 525eef8be63f907a256fa4022d28b0bcd060a307
63 changes: 33 additions & 30 deletions quality_of_service_demo/rclcpp/src/qos_overrides_listener.cpp
Original file line number Diff line number Diff line change
@@ -42,39 +42,42 @@ class QosOverridesListener : public rclcpp::Node
};
rclcpp::SubscriptionOptions sub_opts;
// Update the subscription options to allow reconfigurable qos settings.
sub_opts.qos_overriding_options.policy_kinds = {
// Here all policies that are desired to be reconfigurable are listed.
rclcpp::QosPolicyKind::Depth,
rclcpp::QosPolicyKind::Durability,
rclcpp::QosPolicyKind::History,
rclcpp::QosPolicyKind::Reliability,
};
sub_opts.qos_overriding_options.validation_callback = [](const rclcpp::QoS & qos) {
/** This is a qos validation callback, that can optionally be provided.
* Here, arbitrary constraints in the final qos profile can be checked.
* The function will return true if the user provided qos profile is accepted.
* If the profile is not accepted, the user will get an InvalidQosOverridesException.
*/
// TODO(ivanpauno): Add getters to `rclcpp::QoS` to make this easier.
rclcpp::QosCallbackResult result;
result.successful = false;
if (qos.get_rmw_qos_profile().depth > 10u) {
result.reason = "expected history depth less or equal than 10";
sub_opts.qos_overriding_options = rclcpp::QosOverridingOptions {
{
// Here all policies that are desired to be reconfigurable are listed.
rclcpp::QosPolicyKind::Depth,
rclcpp::QosPolicyKind::Durability,
rclcpp::QosPolicyKind::History,
rclcpp::QosPolicyKind::Reliability,
},
[](const rclcpp::QoS & qos) {
/** This is a qos validation callback, that can optionally be provided.
* Here, arbitrary constraints in the final qos profile can be checked.
* The function will return true if the user provided qos profile is accepted.
* If the profile is not accepted, the user will get an InvalidQosOverridesException.
*/
// TODO(ivanpauno): Add getters to `rclcpp::QoS` to make this easier.
ivanpauno marked this conversation as resolved.
Show resolved Hide resolved
rclcpp::QosCallbackResult result;
result.successful = false;
if (qos.get_rmw_qos_profile().depth > 10u) {
result.reason = "expected history depth less or equal than 10";
return result;
}
result.successful = true;
return result;
}
result.successful = true;
return result;
/**
* The "id" option is useful when you want to have subscriptions
* listening to the same topic with different QoS profiles within a node.
* You can try uncommenting and modifying
* `qos_overrides./qos_overrides_topic.subscription`
* to
* `qos_overrides./qos_overrides_topic.subscription_custom_identifier`
*
* Uncomment the next line to try it.
*/
// , "custom_identifier"
};
/**
* The "id" option is useful when you want to have subscriptions
* listening to the same topic with different QoS profiles within a node.
* You can try uncommenting and modifying
* `qos_overrides./qos_overrides_topic.subscription`
* to
* `qos_overrides./qos_overrides_topic.subscription_custom_identifier`
*/
// sub_opts.qos_overriding_options.id = "custom_identifier";

// create the subscription
sub_ = create_subscription<sensor_msgs::msg::Image>(
"qos_overrides_chatter", 1, callback, sub_opts);
56 changes: 34 additions & 22 deletions quality_of_service_demo/rclcpp/src/qos_overrides_talker.cpp
Original file line number Diff line number Diff line change
@@ -55,34 +55,46 @@ class QosOverridesTalker : public rclcpp::Node

pub_->publish(msg_);
};

rclcpp::PublisherOptions pub_opts;
// Update the subscription options to allow reconfigurable qos settings.
pub_opts.qos_overriding_options.policy_kinds = {
// Here all policies that are desired to be reconfigurable are listed.
rclcpp::QosPolicyKind::Depth,
rclcpp::QosPolicyKind::Durability,
rclcpp::QosPolicyKind::History,
rclcpp::QosPolicyKind::Reliability,
};
pub_opts.qos_overriding_options.validation_callback = [](const rclcpp::QoS & qos) {
/** This is a qos validation callback, that can optionally be provided.
* Here, arbitrary constraints in the final qos profile can be checked.
* The function will return true if the user provided qos profile is accepted.
* If the profile is not accepted, the user will get an InvalidQosOverridesException.
*/
// TODO(ivanpauno): Add getters to `rclcpp::QoS` to make this easier.
rclcpp::QosCallbackResult result;
result.successful = false;
if (qos.get_rmw_qos_profile().depth > 10u) {
result.reason = "expected history depth less or equal than 10";
pub_opts.qos_overriding_options = rclcpp::QosOverridingOptions {
{
// Here all policies that are desired to be reconfigurable are listed.
rclcpp::QosPolicyKind::Depth,
rclcpp::QosPolicyKind::Durability,
rclcpp::QosPolicyKind::History,
rclcpp::QosPolicyKind::Reliability
},
[](const rclcpp::QoS & qos) {
/** This is a qos validation callback, that can optionally be provided.
* Here, arbitrary constraints in the final qos profile can be checked.
* The function will return true if the user provided qos profile is accepted.
* If the profile is not accepted, the user will get an InvalidQosOverridesException.
*/
// TODO(ivanpauno): Add getters to `rclcpp::QoS` to make this easier.
rclcpp::QosCallbackResult result;
result.successful = false;
if (qos.get_rmw_qos_profile().depth > 10u) {
result.reason = "expected history depth less or equal than 10";
return result;
}
result.successful = true;
return result;
}
result.successful = true;
return result;
/**
* The "id" option is useful when you want to have subscriptions
* listening to the same topic with different QoS profiles within a node.
* You can try uncommenting and modifying
* `qos_overrides./qos_overrides_topic.subscription`
* to
* `qos_overrides./qos_overrides_topic.subscription_custom_identifier`
*
* Uncomment the next line to try it.
*/
// , "custom_identifier"
};


// Create a publisher
pub_ = this->create_publisher<sensor_msgs::msg::Image>("qos_overrides_chatter", 1, pub_opts);