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

demo for rclpy parameter_client #566

Merged
merged 11 commits into from
Aug 29, 2022
Merged

Conversation

ihasdapie
Copy link
Member

Adds demos for parameter_client functionality introduced in ros2/rclpy#959

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Copy link
Member

@jacobperron jacobperron left a comment

Choose a reason for hiding this comment

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

Technically, the demo looks okay to me. However, there's a lot going on this demo and I want to make sure we present the content clearly (both in code and output). Running it produces a wall of text that is a bit overwhelming.

I think it would be nicer to clean up the output so it looks something like:

Listing parameters:
  zero
  one
  etc...

Getting parameters:
  zero: 0
  one: 1

etc...

Note, this also makes it easier to automate testing the expected output if we end up doing that for the Python demos in the future. We do this for the C++ demos.

@audrow audrow changed the base branch from master to rolling June 28, 2022 14:18
@ihasdapie ihasdapie self-assigned this Jul 14, 2022
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
@ihasdapie
Copy link
Member Author

Example output:

[INFO] [1658275274.649338142] [async_param_client]: Listing Parameters:
[INFO] [1658275274.652336413] [async_param_client]:     - int_parameter
[INFO] [1658275274.653305327] [async_param_client]:     - bool_parameter
[INFO] [1658275274.654270555] [async_param_client]:     - string_parameter
[INFO] [1658275274.655189378] [async_param_client]: Getting parameters:
[INFO] [1658275274.658082906] [async_param_client]:     - int_parameter: 1
[INFO] [1658275274.659183929] [async_param_client]:     - bool_parameter: False
[INFO] [1658275274.660092542] [async_param_client]:     - string_parameter: Hello World
[INFO] [1658275274.661109533] [async_param_client]: Setting parameters:
[INFO] [1658275274.664789004] [async_param_client]:     int_parameter:
[INFO] [1658275274.665872191] [async_param_client]:         successful: True
[INFO] [1658275274.666908393] [async_param_client]:     bool_parameter:
[INFO] [1658275274.668202344] [async_param_client]:         successful: True
[INFO] [1658275274.669686203] [async_param_client]:     string_parameter:
[INFO] [1658275274.671188020] [async_param_client]:         successful: True
[INFO] [1658275274.672594992] [async_param_client]: Getting parameters:
[INFO] [1658275274.676670296] [async_param_client]:     int_parameter: 10
[INFO] [1658275274.677923705] [async_param_client]:     bool_parameter: True
[INFO] [1658275274.679453591] [async_param_client]:     string_parameter: Fee Fi Fo Fum
[INFO] [1658275274.680601828] [async_param_client]: Describing parameters:
[INFO] [1658275274.683611963] [async_param_client]:     int_parameter:
[INFO] [1658275274.684388868] [async_param_client]:         _name: int_parameter
[INFO] [1658275274.685428469] [async_param_client]:         _type: 2
[INFO] [1658275274.686444349] [async_param_client]:         _description:
[INFO] [1658275274.687288811] [async_param_client]:         _additional_constraints:
[INFO] [1658275274.688324485] [async_param_client]:         _read_only: False
[INFO] [1658275274.689269545] [async_param_client]:         _dynamic_typing: False
[INFO] [1658275274.690464325] [async_param_client]:         _floating_point_range: []
[INFO] [1658275274.692117490] [async_param_client]:         _integer_range: []
[INFO] [1658275274.693731677] [async_param_client]:     bool_parameter:
[INFO] [1658275274.695472536] [async_param_client]:         _name: bool_parameter
[INFO] [1658275274.697122332] [async_param_client]:         _type: 1
[INFO] [1658275274.698527533] [async_param_client]:         _description:
[INFO] [1658275274.700029622] [async_param_client]:         _additional_constraints:
[INFO] [1658275274.701329337] [async_param_client]:         _read_only: False
[INFO] [1658275274.702998828] [async_param_client]:         _dynamic_typing: False
[INFO] [1658275274.704470816] [async_param_client]:         _floating_point_range: []
[INFO] [1658275274.705855489] [async_param_client]:         _integer_range: []
[INFO] [1658275274.707255351] [async_param_client]:     string_parameter:
[INFO] [1658275274.708630585] [async_param_client]:         _name: string_parameter
[INFO] [1658275274.709944576] [async_param_client]:         _type: 4
[INFO] [1658275274.711334061] [async_param_client]:         _description:
[INFO] [1658275274.712558386] [async_param_client]:         _additional_constraints:
[INFO] [1658275274.713721877] [async_param_client]:         _read_only: False
[INFO] [1658275274.714733624] [async_param_client]:         _dynamic_typing: False
[INFO] [1658275274.715899981] [async_param_client]:         _floating_point_range: []
[INFO] [1658275274.716969787] [async_param_client]:         _integer_range: []
[INFO] [1658275274.718051580] [async_param_client]: Getting parameter types:
[INFO] [1658275274.721188226] [async_param_client]:     int_parameter: 2
[INFO] [1658275274.721982724] [async_param_client]:     bool_parameter: 1
[INFO] [1658275274.722940016] [async_param_client]:     string_parameter: 4
[INFO] [1658275274.724470042] [async_param_client]: Setting parameters atomically:
[INFO] [1658275274.729675244] [async_param_client]:     Set parameters atomically:
[INFO] [1658275274.730952995] [async_param_client]:         True
[INFO] [1658275274.731986115] [async_param_client]: Loading parameters:
[INFO] [1658275274.746458694] [async_param_client]:     other_int_parameter:
[INFO] [1658275274.747668982] [async_param_client]:         successful: True
[INFO] [1658275274.749209929] [async_param_client]:         value: 0
[INFO] [1658275274.750360991] [async_param_client]:     int_parameter:
[INFO] [1658275274.751581455] [async_param_client]:         successful: True
[INFO] [1658275274.752936772] [async_param_client]:         value: 12
[INFO] [1658275274.754105377] [async_param_client]:     string_parameter:
[INFO] [1658275274.755029242] [async_param_client]:         successful: True
[INFO] [1658275274.755852355] [async_param_client]:         value: I smell the blood of an Englishman
[INFO] [1658275274.756844537] [async_param_client]:     other_string_parameter:
[INFO] [1658275274.758024076] [async_param_client]:         successful: True
[INFO] [1658275274.759335928] [async_param_client]:         value: One fish, two fish, Red fish, blue fish
[INFO] [1658275274.760457675] [async_param_client]:     bool_parameter:
[INFO] [1658275274.761716040] [async_param_client]:         successful: True
[INFO] [1658275274.762969724] [async_param_client]:         value: False
[INFO] [1658275274.764146652] [async_param_client]: Deleting parameters:
[INFO] [1658275274.768077905] [async_param_client]:     other_int_parameter:
[INFO] [1658275274.769359379] [async_param_client]:         successful: True
[INFO] [1658275274.770932092] [async_param_client]:         reason:
[INFO] [1658275274.771908361] [async_param_client]:     other_string_parameter:
[INFO] [1658275274.772962259] [async_param_client]:         successful: True
[INFO] [1658275274.774272581] [async_param_client]:         reason:
[INFO] [1658275274.775416707] [async_param_client]:     string_parameter:
[INFO] [1658275274.776618659] [async_param_client]:         successful: False
[INFO] [1658275274.777785719] [async_param_client]:         reason: Static parameter cannot be undeclared

Format is valid yaml and should be consistent in case we end up wanting to automate testing these demos

Copy link
Member

@jacobperron jacobperron 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 cleaning up the output!

My remaining comments are mostly about trying to simplify the code. For reference, all of the other Python demos are less than 100 LOC. Though I don't think this has to be that short, I see a few ways we can reduce complexity.

Comment on lines 30 to 31
context = rclpy.context.Context()
rclpy.init(context=context)
Copy link
Member

Choose a reason for hiding this comment

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

Correct me if I'm wrong, but I think we can just use the default context to keep things simple,

I.e. just elide passing an explicit context everywhere.

Suggested change
context = rclpy.context.Context()
rclpy.init(context=context)
rclpy.init()

Comment on lines 39 to 44
target_node.declare_parameters('', [
('int_parameter', 1),
('bool_parameter', False),
('string_parameter', 'Hello World'),
])
target_executor.add_node(target_node)
Copy link
Member

Choose a reason for hiding this comment

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

In the spirit of keeping the demo simple, can we just use a single node (ie. use the same node to create the parameters client and as the target node)? Then we can avoid creating an executor and spinning in a separate thread.

Copy link
Member Author

Choose a reason for hiding this comment

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

My original intent for having two nodes and two seperate contexts is to demonstrate the new functionality of first-class support for setting a remote nodes' parameters. I feel like having only a single node in the demo defeats that purpose since a node setting parameters for itself would presumably just use self.set_parameters.

That being said, I agree with keeping the demo simple. I think the best way to do that would be to not exhaustively run through every method offered by ParameterClient -- it is a little repetitive and overruns this demo with boilerplate code.

Copy link
Member

Choose a reason for hiding this comment

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

I suppose if we really want to demo interacting with a remote node, then that node should be run independently (i.e. in a separate process). E.g. we could add a comment to this demo that the user should first run the parameter blackboard executable (or a new python equivalent) as part of this demo.

I'm also still okay with using a single node since this is what the cpp demos do, for example.

Copy link
Member Author

Choose a reason for hiding this comment

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

Using the parameter blackboard sounds like a good idea, I'll work something out for that

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Copy link
Member

@jacobperron jacobperron left a comment

Choose a reason for hiding this comment

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

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status (unrelated cmake warning)

@jacobperron jacobperron merged commit 9c4ced3 into rolling Aug 29, 2022
@delete-merged-branch delete-merged-branch bot deleted the brianc/parameter_client branch August 29, 2022 23:52
cardboardcode pushed a commit to cardboardcode/demos that referenced this pull request Jan 23, 2023
* WIP: python examples for async parameter client

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>

* reorganize

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>

* linting & use tempfile

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>

* linting

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>

* put async_param_server node in async_param_client

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>

* address review comments

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>

* delete param demo with static and non-static param

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>

* tabs aren't valid yaml

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>

* decrease demo complexity

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>

* use parameter blackboard

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>

* add warning if wait_for_services fails to demo

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
cardboardcode pushed a commit to cardboardcode/demos that referenced this pull request Jan 23, 2023
* WIP: python examples for async parameter client

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>

* reorganize

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>

* linting & use tempfile

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>

* linting

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>

* put async_param_server node in async_param_client

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>

* address review comments

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>

* delete param demo with static and non-static param

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>

* tabs aren't valid yaml

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>

* decrease demo complexity

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>

* use parameter blackboard

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>

* add warning if wait_for_services fails to demo

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Signed-off-by: Bey Hao Yun <beyhy94@gmail.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.

2 participants