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

Revision history [back]

I believe that the problem is that in your launch file, the params are all private params (as they are in the node tag). Therefore you can either declare a private nodehandle i.e. your first line of C++ would read

ros::NodeHandle p_nh("~");

or you could use the other "bare" versions from the API i.e. your parameter calls would read something like

ros::param::param<string>("~KI", KI, "240");

I believe that the problem is that in your launch file, the params are all private params (as they are in the node tag). Therefore you can either declare a private nodehandle i.e. your first line of C++ would read

ros::NodeHandle p_nh("~");

or you could use the other "bare" versions from the API i.e. your parameter calls would read something like

ros::param::param<string>("~KI", KI, "240");

Here's a complete C++ file that does it both ways:

#include <ros/ros.h>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
    ros::init(argc, argv, "test");
    ros::NodeHandle nh("~");

    string KP = "1000";
    string KI = "240";

    nh.param<std::string>("KP", KP, "1000");
    ros::param::param<string>("~KI", KI, "240");

    ROS_INFO("KP = %s", KP.c_str());
    ROS_INFO("KI = %s", KI.c_str());

    return 0;
}

I believe that the problem is that in your launch file, the params are all private params (as they are in the node tag). Therefore you can either declare a private nodehandle i.e. your first line of C++ would read

ros::NodeHandle p_nh("~");

or you could use the "bare" versions from the API i.e. your parameter calls would read something like

ros::param::param<string>("~KI", KI, "240");

Here's a complete C++ file that does it both ways:

#include <ros/ros.h>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
    ros::init(argc, argv, "test");
    ros::NodeHandle nh("~");

    string KP = "1000";
    string KI = "240";

    nh.param<std::string>("KP", nh.param<string>("KP", KP, "1000");
    ros::param::param<string>("~KI", KI, "240");

    ROS_INFO("KP = %s", KP.c_str());
    ROS_INFO("KI = %s", KI.c_str());

    return 0;
}