ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Check if ROS2 Parameters Exist with RCLCPP

asked 2018-10-29 15:10:45 -0600

David Lu gravatar image

In ROS1 there was the hasParam method.

In ROS2, there doesn't seem to be a way to check if a parameter exists directly without attempting to get the value of the parameter.

A) Is there a way to check if a parameter exists that I'm missing B) If not, why not?

edit retag flag offensive close merge delete

Comments

There's no reason I'm aware of that we don't have that function, probably just haven't needed it yet. I am also working on some improvements right now so that you can have read-only parameters. Part of that is an explicit declare step for parameters, which will make "exists" make more sense.

William gravatar image William  ( 2018-10-29 18:55:57 -0600 )edit

Here's the pull request: https://github.com/ros2/rclcpp/pull/495 , it was originally started by Shane, but I'm trying to resurrect it right now. Maybe I can add an "exists" or "has" or "is_declared" like function at the same time.

William gravatar image William  ( 2018-10-29 18:57:51 -0600 )edit

@William That's what I wanted to know. If you don't end up rolling it into that PR, please ping me and I'll try to make one.

David Lu gravatar image David Lu  ( 2018-10-30 07:52:01 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-10-29 16:16:41 -0600

tfoote gravatar image

We didn't provide the specific API to check if a parameter exists. There are many ways to get that information.

First is to list the parameters and check if your parameter is in the list: http://docs.ros2.org/bouncy/api/rclcp...

Or get even more information in describe_parameters: http://docs.ros2.org/bouncy/api/rclcp...

The third is to ask for the parameter and check the return code: http://docs.ros2.org/bouncy/api/rclcp...

Depending on your use case each different one has tradeoffs. If you're going to be checking more than one parameter, the listing is likely valuable. If you want to do more the descriptions are valuable. And lastly if you just use the return code you can integrate the fallback behavior inside your accessing logic.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-10-29 15:10:45 -0600

Seen: 1,713 times

Last updated: Oct 29 '18