I am trying to pass a value to a parameter in a node via the launch file.
I created a basic node that would print the parameter it read or it would give an error saying no parameter.
even though I pass a parameter the node is not able to read it.
I have added the code of the launch file and node below.
Launch File:
<launch>
<arg name="station" />
<node pkg="param_from_launch" type="trial" name="trial">
<param name="param_1" value="$(arg station)"/>
</node>
</launch>
C++ Node:
#include "ros/ros.h"
#include <iostream>
int main(int argc, char **argv)
{
// Set up ROS.
ros::init(argc, argv, "trial");
ros::NodeHandle n("~"); // private namespace
int param_1;
n.param<int>("param_from_launch", param_1, 0);
if(n.param("param_from_launch", param_1)){
ROS_INFO("param_from_launch: %d", param_1);
}
else{
ROS_ERROR("NO PARAM");
}
// Let ROS handle all callbacks.
ros::spin();
return 0;
} // end main()
running the node separately gives me the expected output: param_from_launch: 0
. but when running the launch file I get
[ERROR] [1644580954.583154879]: NO PARAM
Originally posted by NOVA1323 on ROS Answers with karma: 3 on 2022-02-11
Post score: 0