方法一. getParam
例:获取rate,使用ros::NodeHandle。
.cpp文件中:
ros::init(argc, argv, "path_show");
ros::NodeHandle n("~");
double rate;
n.getParam("rosRate", rate);
ros::Rate r(rate);
launch文件中:
<node name = "discrete_sim" pkg = "formation_show" type = "discrete_sim" output = "screen">
<param name = "rosRate" type="double" value = "2.0"/>
</node>
方法二:ros::param::get
例:获取obs_num,使用launch file中的node name和param name结合。
.cpp文件中:
ros::init(argc, argv, "random");
ros::NodeHandle node;
int obs_num = 0;
ros::param::get("/traj_opti_node1/obstacle_num", obs_num);
launch文件中:
<node name="traj_opti_node1" pkg="grad_traj_optimization" type="text_input" output="screen">
<param name="obstacle_num" value="9" type="int">
</node>