You got to create a function that reads the parameters.
For instance:
void readParams(const ros::NodeHandle& nh)
{
nh.param<std::string>("ns" , ns , "custom_image");
nh.param<double>("/"+ns+"/color/a" , color_a , 1.0);
nh.param<double>("/"+ns+"/color/b" , color_b , 0.0);
nh.param<double>("/"+ns+"/color/g" , color_g , 0.0);
nh.param<double>("/"+ns+"/color/r" , color_r , 1.0);
}
The example above is reading color parameters, where the following parameters:
ns , color_a ,color_b , color_g , color_r
are declared in a .yaml file as follows:
# Node namespace
ns: 'custom_image'
# color parameters
color: { 'r': 1.0, 'g': 0.0, 'b': 0.0, 'a': 1.0 }
Thus, nh.param() is a function that receives three arguments:
argument 1 is a string with the name of the parameter as it appears to your ros environment.
argument 2 is a global variable that you should have declared prior to call this function. In this example, ns is a string variable, and color_a , color_b , color_g and color_r are double.
argument 3 is a default value that will be parsed to your variable (argument 2) just in case the parameter declared (argument 1) cannot be found.
In summary, as long as your parameters are visible in your ros environment, this function will read it by looking for argument 1, and store its value to the variable in argument 2.
Now that you have your readParams() function. You only have to call it parsing your node handle.
For instance, in my main() function I did:
ros::init(argc , argv , "custom_image");
ROS_INFO("Initializing my node...");
ros::NodeHandle nh;
readParams(nh);
After that, you can print the variables' values, as they are storing their respective parameters.
(If you need more help, take a look at: http://wiki.ros.org/roscpp/Overview/P... )