ROS Namespace related confusion
I am developing a ROS Package on ROS Indigo in Ubuntu 14.04 LTS OS.
The package contains a launch file with the following content:
<launch>
<arg name="host" default="172.17.69.137"/>
<arg name="port" default="1357"/>
<arg name="timeout" default="1000"/>
<arg name="model" default="$(find my_package)/files/robot.urdf"/>
<param name="robot_description" command="$(find xacro)/xacro --inorder $(arg model)"/>
<param name="use_gui" value="true"/>
<node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher"/>
<node name="receiver" pkg="my_package" type="receiver" output="screen">
<param name="host" value="$(arg host)" />
<param name="port" value="$(arg port)" />
<param name="timeout" value="$(arg timeout)" />
</node>
</launch>
The CPP source file uses the above parameters as shown below:
ros::init(argc, argv, "receive_potentio", ros::init_options::AnonymousName);
ros::NodeHandle nh;
ros::Publisher jointStatePub = nh.advertise<sensor_msgs::JointState>("joint_states", 1);
std::string host;
int timeout, port;
// the following doesn't work. However when relative is
// used, i.e. ros::NodeHandle nh("~") it works!
nh.getParam("host", host);
nh.getParam("port", port);
nh.getParam("timeout", timeout);
The absolute namespace defined in this way i.e., ros::NodeHandle nh
doesn't get params nh.getParam("host", host)
. But when relative is used ros::NodeHandle nh("~")
, param nh.getParam("host", host)
works. However in this case ros::Publisher jointStatePub
doesn't work!
I think I am missing something obvious here. How do I make both of the work together?
How does a
Publisher
"not work" exactly?