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

Search parameters in namespaces does not work

asked 2021-04-28 05:07:06 -0500

ros_newbie96 gravatar image

Hi,

I am using ROS melodic on Ubuntu18.04.

I have the following code snippet:

  ros::init(argc, argv, "parameters");
  ros::NodeHandle n;
  double param_in_namespace = 7.0;
  std::string namespace;
  n.setParam("/namespace/param", param_in_namespace);
  n.searchParam("param", namespace);

I would expect that the "namespace" variable has the value "/namespace/param" but when I execute this example, I get an empty string for namespace.

Is that how it should work, or is my expected value wrong?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-04-28 06:32:31 -0500

gvdhoorn gravatar image

I have the following code snippet:

  ros::init(argc, argv, "parameters");
  ros::NodeHandle n;
  double param_in_namespace = 7.0;
  std::string namespace;
  n.setParam("/namespace/param", param_in_namespace);
  n.searchParam("param", namespace);

I would expect that the "namespace" variable has the value "/namespace/param" but when I execute this example, I get an empty string for namespace.

Without knowing in which namespace you start your node, I believe this is by-design.

From the roscpp: Searching for Parameter Keys page (emphasis mine):

There are times where you want to get a parameter from the closest namespace. For example, if you have a "robot_name" parameter, you just want to search upwards from your private namespace until you find a matching parameter.

Note how it says "search upwards".

The code you show places a parameter in /namespace, but if your node is not started in namespace as well, it's likely param will not be found, as /namespace would be below the namespace in which your node is running (which is probably the global namespace).

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-04-28 05:07:06 -0500

Seen: 145 times

Last updated: Apr 28 '21