-
Notifications
You must be signed in to change notification settings - Fork 772
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 gazebo_ros::QoS class #1091
Merged
+964
−3
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
307db94
Add QoS class
jacobperron 060c50f
Store QoS profiles for each ROS node
jacobperron f143af4
Fix typo
jacobperron 4e0ed2f
Return const reference
jacobperron 6d60d68
Indent test XML
jacobperron 7d5bcde
Explicitly set default QoS in tests
jacobperron 7e5ee40
Remove extra QoS parameter from CreateWithArgs
jacobperron 578d238
Map strings to QoS policies
jacobperron f86fa38
map -> unordered_map
jacobperron 15192ff
Use std::ostringstream
jacobperron 9ae6524
Remove manual_by_node option
jacobperron ce4df06
Add support for topic remapping
jacobperron 3443cf0
Use explicit types instead of auto
jacobperron 29b3305
Add TODO about using rclcpp API
jacobperron 365db64
Validate remapped topic name before returning
jacobperron b98866d
Add test involving a node namespace
jacobperron bec2ecb
Fix typo in comment
jacobperron 5bcfe93
Make return value const reference
jacobperron 1eb881a
Use PIMPL
ivanpauno 3b8d0f5
Impreve get_qos signatures
ivanpauno a9921eb
Please linters
ivanpauno 7a5188a
Use <qos> tag nested in <ros> tag in some of the tests
ivanpauno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
// Copyright 2020 Open Source Robotics Foundation, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef GAZEBO_ROS__QOS_HPP_ | ||
#define GAZEBO_ROS__QOS_HPP_ | ||
|
||
#include <sdf/sdf.hh> | ||
|
||
#include <rclcpp/node_options.hpp> | ||
#include <rclcpp/qos.hpp> | ||
|
||
#include <map> | ||
#include <memory> | ||
#include <stdexcept> | ||
#include <string> | ||
|
||
namespace gazebo_ros | ||
{ | ||
|
||
/// Exception thrown when there is an invalid QoS configuration. | ||
class InvalidQoSException : public std::runtime_error | ||
{ | ||
public: | ||
explicit InvalidQoSException(const std::string & msg) | ||
: std::runtime_error(msg) | ||
{} | ||
}; | ||
|
||
// Forward declare private implementation | ||
struct QoSPrivate; | ||
|
||
/// Quality of service profile for ROS node entities | ||
/** | ||
* \class QoS qos.hpp <gazebo_ros/qos.hpp> | ||
* Encapsulates QoS profiles for a group of ROS publishers and subscriptions. | ||
* Supports parsing SDF <qos> tags. | ||
* | ||
* Note, this implementation groups QoS profiles by entity type (publisher or subscription) and | ||
* topic name. | ||
* For example, two publishers using the same topic will have the same QoS returned by this class. | ||
* \include gazebo_ros/qos.hpp | ||
*/ | ||
class QoS | ||
{ | ||
public: | ||
QoS(); | ||
|
||
/// Constructor with SDF | ||
/** | ||
* \details Create a new QoS profile for a collection of node entities from SDF. | ||
* SDF should have the form: | ||
* \code{.xml} | ||
* <qos> | ||
* <!-- Zero or more topic tags with topic names to configure --> | ||
* <topic name="my/topic/name"> | ||
* <!-- Optional tag for setting the QoS profile for subscriptions --> | ||
* <subscription> | ||
* <!-- Optional tags for overriding default settings (see below)--> | ||
* </subscription> | ||
* <!-- Optional tag for setting the QoS profile for publishers --> | ||
* <publisher> | ||
* <!-- Optionally tags for overriding default settings (see below) --> | ||
* </publisher> | ||
* </topic> | ||
* </qos> | ||
* \endcode | ||
* | ||
* The available QoS settings that can be overridden are outlined below. | ||
* For more information on each option and their possible values, see | ||
* http://design.ros2.org/articles/qos.html and | ||
* http://design.ros2.org/articles/qos_deadline_liveliness_lifespan.html. | ||
* | ||
* The <reliability> element must contain one of the following: "reliable", "best_effort", | ||
* or "system". | ||
* | ||
* The <durability> element must contain one of the following: "volatile", "transient_local", | ||
* or "system". | ||
* | ||
* The <history> element must contain one of the following: "keep_last", "keep_all", or "system". | ||
* If "keep_last" is used, a "depth" attribute must be present and set to a positive integer. | ||
* | ||
* The <deadline> element must contain a positive integer representing a duration in | ||
* milliseconds. | ||
* | ||
* The <lifespan> element must contain a positive integer representing a duration in | ||
* milliseconds. | ||
* | ||
* The <liveliness> element must contain one of the following: "automatic", "manual_by_topic", | ||
* or "system". | ||
* | ||
* The <liveliness_lease_duration> element must contain a positive integer representing a | ||
* duration in milliseconds. | ||
* | ||
* For any QoS setting that is not specified in the SDF, the default QoS object passed | ||
* to the getter methods is used. | ||
* | ||
* The topic name should be the name expected after any remapping occurs. | ||
* For example, if a <remapping> tag remaps a topic 'foo' to the name 'bar', then the <topic> | ||
* tag's name attribute should have the value 'bar' to override any QoS settings: | ||
* | ||
* \code{.xml} | ||
* <remapping>foo:=bar</remapping> | ||
* <qos> | ||
* <topic name='bar'> | ||
* </topic> | ||
* </qos> | ||
* \endcode | ||
* | ||
* \param[in] _sdf An SDF element in the style documented above | ||
* \param[in] node_name The name of the node associated with these QoS settings. | ||
* \param[in] node_namespace The namespace of the node associated with these QoS settings. | ||
* \param[in] options Node options that were also passed to the node associated with these QoS | ||
* settings. | ||
* This contains the necessary information extracting the remappings. | ||
* \throws gazebo_ros::InvalidQoSException if there is an invalid QoS value or a topic element | ||
* is missing a "name" attribute. | ||
*/ | ||
QoS( | ||
sdf::ElementPtr _sdf, | ||
const std::string node_name, | ||
const std::string node_namespace, | ||
const rclcpp::NodeOptions & options); | ||
|
||
/// Get the QoS for a publisher | ||
/* | ||
* \param[in] topic: Get QoS for publishers on this topic name. | ||
* \param[in] default_qos: The default quality of service used for settings that have not been | ||
* overridden. | ||
*/ | ||
rclcpp::QoS get_publisher_qos( | ||
const std::string topic, rclcpp::QoS default_qos = rclcpp::QoS(10)) const; | ||
|
||
/// Get the QoS for a subscription | ||
/* | ||
* \param[in] topic: Get QoS for subscriptions on this topic name. | ||
* \param[in] default_qos: The default quality of service used for settings that have not been | ||
* overridden. | ||
*/ | ||
rclcpp::QoS get_subscription_qos( | ||
const std::string topic, rclcpp::QoS default_qos = rclcpp::QoS(10)) const; | ||
|
||
/// QoS is copyable | ||
// need explicit copy constructor due to `std::unique_ptr` `impl_` | ||
QoS(const QoS & other); | ||
|
||
/// QoS is movable | ||
// this is needed due to rule of five | ||
QoS(QoS && other); | ||
|
||
/// QoS is copy assignable | ||
// need explicit copy assignment due to `std::unique_ptr` `impl_` | ||
QoS & operator=(const QoS & other); | ||
|
||
/// QoS is move assignable | ||
// this is needed due to rule of five | ||
QoS & operator=(QoS && other); | ||
|
||
// this is needed due to rule of five | ||
~QoS(); | ||
|
||
private: | ||
std::unique_ptr<QoSPrivate> impl_; | ||
}; | ||
|
||
} // namespace gazebo_ros | ||
#endif // GAZEBO_ROS__QOS_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid namespaces should be always absolute (contrary to names, which can be relative/private/absolute).
I guess @jacobperron did that change because the namespace is being passed to the new QoS class, and some of the API it uses may be doing namespace validation.
@jacobperron can you confirm if that was the case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Since we started going down this road on this PR, do you think we should also do some checking on line 58 in case the user passes an invalid namespace? Or maybe we prepend the
/
for them in case it's missing?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ivanpauno is exactly right. Without this change, I was seeing runtime errors from some
rcl
/rclcpp
API calls (though I can't recall exactly which ones).I guess if a user passes an invalid namespace, they will see similar runtime errors. I think the validation and error message from the underlying layers is enough (it also is nice to keep it encapsulated there in case the naming requirement changes for some reason).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, makes sense. I'm just wondering why we haven't seen problems so far with this default value, and whether this change is backwards compatible. But you peeps know best about these details 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this may have messed something up 🤔 #1116
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't seem related to me.
That default value is being immediately overridden by the value in the SDF if it exists
gazebo_ros_pkgs/gazebo_ros/src/node.cpp
Lines 57 to 59 in 57732fe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, it's related to this
gazebo_ros_pkgs/gazebo_ros/src/gazebo_ros_factory.cpp
Lines 231 to 235 in 57732fe
gazebo_ros_pkgs/gazebo_ros/src/gazebo_ros_factory.cpp
Lines 354 to 355 in 57732fe
?
According to grep that's the only place where we set the
namespace
SDF tag.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! @ahcorde , are you spawning your robot through the factory? In my case I was.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1117