-
Notifications
You must be signed in to change notification settings - Fork 157
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 param dump <node-name> #285
Conversation
Signed-off-by: artivis <jeremie.deray@canonical.com>
Signed-off-by: artivis <jeremie.deray@canonical.com>
Signed-off-by: artivis <jeremie.deray@canonical.com>
Signed-off-by: artivis <jeremie.deray@canonical.com>
Signed-off-by: artivis <jeremie.deray@canonical.com>
Signed-off-by: artivis <jeremie.deray@canonical.com>
Signed-off-by: artivis <jeremie.deray@canonical.com>
ros2param/ros2param/verb/dump.py
Outdated
return value | ||
|
||
def insert_dict(self, dict, key, value): | ||
split = key.split("/", 1) |
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'm not sure if namespaces are delimited with /
or .
as I have seen both :s .
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.
Depends what you mean by namespace.
A node namespace (the thing set with __ns:=/foo/bar
) has tokens delimited with /
. Multiple levels in a parameter name are delimited with a .
. You can get the character with this import from rclpy.parameter import PARAMETER_SEPARATOR_STRING
$ ros2 run demo_nodes_cpp parameter_blackboard __ns:=/foo/bar &
[1] 25174
...
$ ros2 node list
/foo/bar/parameter_blackboard
$ ros2 param list /foo/bar/parameter_blackboard
use_sim_time
$ ros2 param set /foo/bar/parameter_blackboard ping.pong 5
Set parameter successful
$ ros2 param list /foo/bar/parameter_blackboard
ping.pong
use_sim_time
If you're dumping to a yaml file, you can just use indentation.
$ ros2 run demo_nodes_cpp parameter_blackboard __ns:=/lidar_ns/lidar_1/lidar11 __node:=lidar111 __params:=/home/sloretz/ws/ros2/src/ros2/rcl/rcl_yaml_param_parser/test/multi_ns_correct.yaml &
[1] 25358
...
$ ros2 param list /lidar_ns/lidar_1/lidar11/lidar111
driver1.driver11.bk_sensor_specs
driver1.driver11.driver111.dx
driver1.driver11.driver111.dy
driver1.driver11.driver111.fr_sensor_specs
driver2.driver21.dx
driver2.driver21.dy
id
is_front
name
ports
use_sim_time
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 did mean "Multiple levels in a parameter name", didn't know about PARAMETER_SEPARATOR_STRING
thanks.
This new verb does dump into a yaml file using multi-level indentation for multi-level parameters, see the example in my very first comment.
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.
But how does one declare those multi-level parameters in python ?? The following does not work,
node.declare_parameter('foo.str_param', 'foo')
for topic name must not contain characters other than alphanumerics, '_', '~', '{', or '}'
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.
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.
@artivis Would you be willing to open an issue about declare_parameter('foo.str_param', 'foo')
not working on the rclpy repo? https://github.com/ros2/rclpy/issues/new
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.
Looks like an issue has been opened ros2/rclpy#373
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.
Ok great, thanks.
Before this PR to be ready for review,
|
Signed-off-by: artivis <jeremie.deray@canonical.com>
Signed-off-by: artivis <jeremie.deray@canonical.com>
2503e1f
to
a865449
Compare
PR is subject to changes once ros2/rclpy#373 is fixed. |
@artivis ros2/rclpy#377 has been merged, can this be updated? |
@kyrofa yep, I'll get to it 👍 |
Signed-off-by: artivis <jeremie.deray@canonical.com>
@sloretz This PR now uses |
@sloretz Please let me know if there is anything I can do to help push this forward. |
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.
Added a few comments
ros2param/ros2param/verb/dump.py
Outdated
|
||
# extract type specific value | ||
pvalue = response.values[0] | ||
if pvalue.type == ParameterType.PARAMETER_BOOL: |
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.
It looks like this code could be shared with ros2 param get
. In fact, here's a function with part of it. Mind moving this code to ros2param/api/__init__.py
? I'll create a ticket to follow up with get
.
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.
Done here.
ros2param/ros2param/verb/dump.py
Outdated
'--include-hidden-nodes', action='store_true', | ||
help='Consider hidden nodes as well') | ||
parser.add_argument( | ||
'--file-path', |
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.
nit, recommend --output-dir
. Despite the help text I mistakenly thought this was the name of a file. Alternatively outputing to stdout with the expectation that users will pipe to a file seems like another reasonable option.
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.
How about having both options ? Adding a --print
flag or such that take precedence over saving to a file.
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.
Sounds good to me
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.
Done 907f1be
ros2param/ros2param/verb/dump.py
Outdated
"'{node_name.full_name}': {e}".format_map(locals()), | ||
file=sys.stderr) | ||
|
||
print('Saving to: ', os.path.join(args.file_path, node_name.name + ".yaml")) |
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.
There are a few places that assume a fully qualified node name is unique, so making the output file name include the namespace seems appropriate. Recommend replacing node_name.name
with absolute_node_name.replace('/', '__')
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.
The output file name and only that ? Not sure how it works with namespaces now that the node name is the first entry in the yaml file...
Also should I filter for leading ' / '
in absolute_node_name
?
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.
The output file name and only that ?
Yeah, I was just thinking it would make this case more convenient. It looks like the second call would overwrite the first if only using node_name.name
for the file name.
ros2 param dump /left/camera --output-dir .
ros2 param dump /right/camera --output-dir .
Also should I filter for leading ' / ' in absolute_node_name ?
Sure. The absolute name always begins with /
, so that should be easy to remove.
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.
Done e41232c
@sloretz Thanks for the review, will address it asap. |
d1eb7da
to
64dad3f
Compare
Signed-off-by: artivis <jeremie.deray@canonical.com>
Signed-off-by: artivis <jeremie.deray@canonical.com>
Signed-off-by: artivis <jeremie.deray@canonical.com>
Signed-off-by: artivis <jeremie.deray@canonical.com>
Signed-off-by: artivis <jeremie.deray@canonical.com>
Signed-off-by: artivis <jeremie.deray@canonical.com>
64dad3f
to
60d5b85
Compare
Signed-off-by: artivis <jeremie.deray@canonical.com>
Signed-off-by: artivis <jeremie.deray@canonical.com>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz<sloretz@openrobotics.org> Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
0ba7042
to
0f1b534
Compare
@artivis Looks like there are some linter complaints. Mind addressing them? https://ci.ros2.org/job/ci_linux/7667/testReport/junit/ros2param.test/test_flake8/test_flake8/ |
@@ -127,5 +127,5 @@ def main(self, *, args): # noqa: D102 | |||
file_name = absolute_node_name.replace('/', '__') | |||
|
|||
print('Saving to: ', os.path.join(args.output_dir, file_name + '.yaml')) | |||
with open(os.path.join(args.output_dir, node_name.name + '.yaml'), 'w') as yaml_file: | |||
with open(os.path.join(args.output_dir, file_name + '.yaml'), 'w') as yaml_file: |
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.
Oups ><
I'll take care of it no problem. However that linter test passes on my machine. Do I have something mis-configured or something ? |
Typically that is the case, yeah. Flake8 has an annoying behavior that it will only run the linters that are installed, so if you forget one, it just won't run it. Anyway, I'd suggest re-running through the installation instructions, which should fetch the ones you are missing. |
Signed-off-by: artivis <jeremie.deray@canonical.com>
d9d2b88
to
f989bcf
Compare
@clalancette Thanks, I was indeed missing some linters 👍.
Any idea ? |
Yeah, I see those as well. I think those are just warnings from Python itself, and can be safely ignored. At least, they don't seem to cause problems in CI or in the code itself. |
Ok, thanks 👍 |
ros2param/test/test_verb_dump.py
Outdated
|
||
# Make sure the file was not create, thus '--print' did preempt | ||
expected_err = '[Errno 2] No such file or directory: ' \ | ||
"'{not_generated_param_file}'".format_map(locals()) |
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.
Looks like the error text is slightly different on windows. Maybe relax this check to assert 'No such file or directory' in context.exception
?
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.
That's surprising.
See 7b508a0.
Signed-off-by: artivis <jeremie.deray@canonical.com>
@sloretz Genuine curiosity, does the ci kicks in from keywords ? Can anyone launch it ?? |
@artivis The CI jobs for all platforms are started manually. The ros2 build farm supports PR jobs which would run an ubuntu job automatically, but it looks like this repo isn't yet set up for that |
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.
CI looks good. Thanks for the PR @artivis !
Add the
param dump <node-name>
which dumps the parameters of a given node to a yaml file.From the test, the following
generates the yaml file (
test_node.yaml
) :