Ask Your Question
0

YAML File Not Loading files

asked 2016-08-02 17:44:09 -0500

Pototo gravatar image

updated 2016-08-02 17:49:31 -0500

Folks,

I created my a YAML file. When I change the parameters in my YAML, then don't change in my code. I created the yaml inside my launch folder:

yaml_file.yaml

min_user_distance: 0.9 ...

myClass.cpp

  class myClass
  {
     ros::NodeHandle nh_;

     public:
          myClass(int32_t user_id)
          : it_(nh_)
          {
              std::cout << "\n---------------------------\n";
              std::cout << "Object Parameters (CAMERA):\n---------------------------\n";
              //parameters from a YAML File
              nh_.param("min_user_distance", min_user_distance_, 0.9);
              std::cout << "min_user_distance = " << min_user_distance_ << "\n";
              nh_.param("max_user_distance", max_user_distance_, 1.8);
              std::cout << "max_user_distance = " << max_user_distance_ << "\n";
            }
   }

And this is how I load the yaml in my my_launch_file. launch

  <node name="my_node" pkg="my_package" type="my_node" output="screen">
      <rosparam file="$(find my_packge)/launch/yaml_file.yaml"/>
  </node>

When I change the value in the yaml file, the computer still prints 0.9 for the min_user_distance_ (which is the default value). Why does it always pick the default value?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-08-02 20:27:51 -0500

Mark Rose gravatar image

According to the documentation of the <rosparam> tag ( http://wiki.ros.org/roslaunch/XML/ros... ):

The <rosparam> tag can be put inside of a <node> tag, in which case the parameter is treated like a private name.

So your code to get the parameters should use private names:

nh_.param("~min_user_distance", min_user_distance_, 0.9);
std::cout << "min_user_distance = " << min_user_distance_ << "\n";
nh_.param("~max_user_distance", max_user_distance_, 1.8);
std::cout << "max_user_distance = " << max_user_distance_ << "\n";

Alternatively, to create global parameters put the <rosparam> tag outside the <node> tag.

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

1 follower

Stats

Asked: 2016-08-02 17:44:09 -0500

Seen: 122 times

Last updated: Aug 02 '16