How to read yaml file correctly when spawning models?
Hello, I want to read the yaml file when spawning a model. But the model plugin cannot read parameters while they can be displayed in a terminal. So how to read yaml file correctly when spawning models?
Part of the launch file:
<node name="sdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen" args="-sdf -model lunarveh -file $(find lunarveh_description)/models/model.sdf">
<rosparam file="$(find lunarveh_description)/config/wheel_pid.yaml" command="load" />
</node>
Part of the plugin:
std::vector<float> read_front_wheel_pid, read_rear_wheel_pid;
this->n.getParam("front_wheel_pid", read_front_wheel_pid);
this->n.getParam("rear_wheel_pid", read_rear_wheel_pid);
if (this->n.getParam("rear_wheel_pid", read_rear_wheel_pid))
ROS_INFO("get value: %f", read_rear_wheel_pid[0]);
else
ROS_INFO("did not get value");
The yaml file is:
front_wheel_pid: [50.0, 0.5, 0.0]
rear_wheel_pid: [1000.0, 0.0, 0.0]
When running it shows:
[ INFO] [1627436039.252123233]: did not get value
But I can read the parameters in a terminal:
mu@mu-TM1703:~/mu$ rosparam get /sdf_spawner/front_wheel_pid
- 50.0
- 0.5
- 0.0
I use Ubuntu 20.04, ROS Noetic, Gazebo 11. Thank you!