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

Added new constructors for SyncParameterClient #612

Merged
merged 4 commits into from
Dec 20, 2018
Merged

Added new constructors for SyncParameterClient #612

merged 4 commits into from
Dec 20, 2018

Conversation

alsora
Copy link
Collaborator

@alsora alsora commented Dec 12, 2018

Following issue #599

Allows to create SyncParameterClient in a class which inherits from rclcpp::Node

@tfoote tfoote added the in review Waiting for review (Kanban column) label Dec 12, 2018
Copy link
Member

@wjwwood wjwwood left a comment

Choose a reason for hiding this comment

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

Thanks for starting this pr, I have some requested changes and unfortunately we're past the point in the Crystal release where this could be included, instead it will go into post Crystal (for the D-turtle release) and therefore this pr might have to wait for a few days/weeks while we finish the release.

rclcpp::Node * node,
const std::string & remote_node_name,
const rmw_qos_profile_t & qos_profile)
: executor_(executor), node_(node)
Copy link
Member

Choose a reason for hiding this comment

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

This is dangerous, because you're creating a shared pointer to Node (in node_) from a pointer that is already owned by another shared pointer (node is the pointer and all nodes are created as shared pointers to support std::enable_shared_from_this).

The SyncParametersClient needs to be changed to hold a raw pointer (optionally or always) rather than always having a shared pointer to node which cannot be safely fulfilled with a raw pointer as input.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed the SyncParametersClient member node_ to a raw pointer.
SyncParametersClient has still constructors which accept a raw or shared pointer to a node.

@@ -185,6 +185,19 @@ class SyncParametersClient
const std::string & remote_node_name = "",
const rmw_qos_profile_t & qos_profile = rmw_qos_profile_parameters);

RCLCPP_PUBLIC
explicit SyncParametersClient(
rclcpp::Node * node,
Copy link
Member

Choose a reason for hiding this comment

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

Instead a signature which took the component parts of the node that this client needs would be better, e.g. maybe the NodeParameterInterface and the NodeBaseInterface (and perhaps others?).

Copy link
Member

Choose a reason for hiding this comment

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

You could keep a signature like this one which simply extracted those components from a rclcpp::Node and delegated them to another constructor. That way this could be more easily used with other forms of Node's like rclcpp_lifecycle::LifecycleNode.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

From what I have understood, SyncParameterClient only uses NodeBaseInterface for calling spin_until_future_complete.
All the other interfaces are used by AsyncParameterClient and are "extracted" from the node pointer in the AsyncParameterClient constructor.
I do not get what's the advantage of having a SyncParameterClient constructor signature which takes interfaces, since all the logic using them is contained in the AsyncParameterClient

Copy link
Member

Choose a reason for hiding this comment

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

I do not get what's the advantage of having a SyncParameterClient constructor signature which takes interfaces, since all the logic using them is contained in the AsyncParameterClient.

Doesn't the SyncParameterClient create an AsyncParameterClient internally? Therefore it needs those parts to pass to the constructor of the AsyncParameterClient (specifically this one:

RCLCPP_PUBLIC
AsyncParametersClient(
const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_interface,
const rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics_interface,
const rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph_interface,
const rclcpp::node_interfaces::NodeServicesInterface::SharedPtr node_services_interface,
const std::string & remote_node_name = "",
const rmw_qos_profile_t & qos_profile = rmw_qos_profile_parameters);
).

As to why the parts rather than an rclcpp::Node pointer only, the reason is that this won't be only used with rclcpp::Node, for instance if you wanted to use it with rclcpp_lifecycle::LifecycleNode (which does not inherit from rclcpp::Node), or some user defined node that doesn't inherit from rclcpp::Node, then you'd want the constructor that takes the interfaces.

If you want to be resilient to changes in the AsyncParameterClient's constructor, you could try to use perfect forwarding to forward the arguments that are only used by the AsyncParameterClient, but that makes it harder to document imo.

You can still have convenience constructors that take common node base types like rclcpp::Node and just extract the interfaces needed and then delegates to the other constructor.

@alsora
Copy link
Collaborator Author

alsora commented Dec 18, 2018

In the last commit I took into account the possibility for objects which does not inherit from rclcpp::Node to create a SyncParametersClient.

I had to change again the node_ member.
I substituted it with const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_interface_ .

Now there are 5 constructors for SyncParameterClient and 3 constructors for AsyncParameterClient.

These are examples of flow for the SyncParameterClient:

  • shared_ptr constructor -> executor + shared_ptr constructor -> executor + interfaces constructor
  • raw ptr constructor -> executor + raw ptr constructor -> executor + interfaces constructor

The just added "executor + interfaces constructor" instantiates the AsyncParameterClient using the provided interfaces.

I just noticed that there is a failed test (it was present also with the last commit, but I did not saw it since I only tested rclcpp package).
Do you have any idea why changing the ParameterClient can affect the rclcpp_action client ?
The test error is a timeout during async_cancel_some_goals

@wjwwood
Copy link
Member

wjwwood commented Dec 18, 2018

In the last commit I took into account the possibility for objects which does not inherit from rclcpp::Node to create a SyncParametersClient.

Thanks! I'll give it a look.

Do you have any idea why changing the ParameterClient can affect the rclcpp_action client ?
The test error is a timeout during async_cancel_some_goals

It may or may not be related, we do occasionally have flaky tests, @jacobperron and @sloretz do either of you know if that is a known flaky test?

@jacobperron
Copy link
Member

It may or may not be related, we do occasionally have flaky tests, @jacobperron and @sloretz do either of you know if that is a known flaky test?

I'm not aware of any flaky tests in rclcpp_action.
With either master branch or this PR, the following command passes for me locally:

colcon test --executor sequential --retest-until-fail 10 --packages-select rclcpp_action

@alsora
Copy link
Collaborator Author

alsora commented Dec 19, 2018

@jacobperron yes, you are right, now the checks are marked as passed.

I repeated all the rclcpp tests more than one time and apparently sometimes errors in the rclcpp_action package arise.

@wjwwood
Copy link
Member

wjwwood commented Dec 20, 2018

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@wjwwood
Copy link
Member

wjwwood commented Dec 20, 2018

Restarted Windows CI due to failure: Build Status

@wjwwood
Copy link
Member

wjwwood commented Dec 20, 2018

The failing tests are due to another unrelated issue, so I'll merge this. Thanks @alsora!

@wjwwood wjwwood merged commit eb2081b into ros2:master Dec 20, 2018
@wjwwood wjwwood removed the in review Waiting for review (Kanban column) label Dec 20, 2018
cho3 pushed a commit to cho3/rclcpp that referenced this pull request Jun 3, 2019
* added new constructors for sync parameter client

* sync param client now has raw ptr member instead of shared ptr

* fixed pointer style

* allow objects which do not inherit from node to create a sync parameters client
nnmm pushed a commit to ApexAI/rclcpp that referenced this pull request Jul 9, 2022
Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>
DensoADAS pushed a commit to DensoADAS/rclcpp that referenced this pull request Aug 5, 2022
…to find bagfiles in incorrectly-written metadata (ros2#612)

* Deduplicate sequentialcompressionreader business logic, add fallback to find bagfiles in incorrectly-written metadata

Signed-off-by: Emerson Knapp <eknapp@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants