0
$\begingroup$

Rosanswers logo

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.


Originally posted by hansolo on ROS Answers with karma: 78 on 2018-10-19

Post score: 0


Original comments

Comment by gvdhoorn on 2018-10-19:
Please add the bit from your launch file where you start your node.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by hansolo with karma: 78 on 2018-10-20

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.