Ask Your Question
0

Can't get double parameter in node (C++)

asked 2018-10-19 11:13:12 -0600

hansolo gravatar image

I have a launch file with:

  <arg name="INTENSITY" default="1.2" />
  <param name="my_intensity" type="double" value="$(arg INTENSITY)" />

The same launch file starts a ROS node, my_node . In my_node's main method I have the following, to get that parameter:

  ros::init(argc, argv, "my_node");
  ros::NodeHandle nh;
  string param_name;
  if(!nh.searchParam("/my_intensity", param_name) ){
    ROS_ERROR("Can't find param.");
    return -1;
  }

  double it;
  ros::param::get(param_name, it);  

  ROS_INFO("Intensity is %f.", it);
  ...

Running this prints Intensity is 0.0.. Although when I run rosparam get /my_intensity in a terminal window I get the correct value (1.2).

When I change the type of it to string, what I get is an empty string. The same approach always worked for my other nodes. So I am really confused. What may be causing this behavior?

Thank you.

System: Ubuntu 16.04, ros-kinetic.

edit retag flag offensive close merge delete

Comments

1

Please add the bit from your launch file where you start your node.

gvdhoorn gravatar imagegvdhoorn ( 2018-10-19 11:27:55 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-10-20 07:38:08 -0600

hansolo gravatar image

Ok, I found the reason after poking some more. The same node was subscribing to a topic with the same name (my_intensity). Also, the topic name was remapped to another name in node launch. I used a separate name for the parameter and topic name to solve it.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2018-10-19 11:13:12 -0600

Seen: 376 times

Last updated: Oct 20 '18