YAML文件
joint1_gains: {p: 7.0, i: 8.0, d: 9.0}
源文件
#include <ros/ros.h>
int main(int argc, char** argv)
{
ros::init(argc, argv, "read_param_node");
ros::NodeHandle n;
double P_gain, D_gain, I_gain;
ROS_WARN("rosparam start");
if (n.getParam("/gains/p", P_gain)) {
ROS_WARN("proportional gain set to %f", P_gain);
}
else {
ROS_WARN("Can't load param of P");
}
ros::spin()
return 0;
}
launch
文件
<launch>
<rosparam command="load" file="$(find ros_learning)/param/gains.yaml"/>
<node name="read_param_node" pkg="ros_learning" type="read_param_node" output="screen" />
</launch>