參數服務器實現的功能:修改參數後,不需要重新編譯,節點啓動時生效;
動態調參實現的功能:修改參數後,不需要重新編譯,無需重新啓動節點;
這個一元堆棧包含dynamic_reconfigure包,它提供了一種方法,可以在任何時候更改節點參數,而無需重新啓動節點。
目前,dynamic_reconfigure的重點是提供一種標準方法,將節點參數的子集公開給外部重新配置。客戶機程序,例如GUIs,可以查詢節點的可重構參數集,包括它們的名稱、類型和範圍,並向用戶提供定製的接口。這對於硬件驅動程序特別有用,但具有更廣泛的適用性。
源代碼: git https://github.com/ros/dynamic_reconfigure.git (branch: master)
第一部分:動態調參的應用
1.dynparam命令行工具
dynparam工具支持節點的命令行重新配置,以及將它們的配置加載和轉儲到文件中。要運行dynparam,輸入:
$ rosrun dynamic_reconfigure dynparam COMMAND
當前支持的命令是:
- dynparam list : list configurable nodes
- dynparam get : get node configuration
- dynparam set : configure node
- dynparam set_from_parameters : copy configuration from parameter server
- dynparam dump : dump configuration to file
- dynparam load : load configuration from file
具體指令如下
1.羅列所有可以動態調參的節點
$ rosrun dynamic_reconfigure dynparam list
範例:
firefly@firefly:~$ rosrun dynamic_reconfigure dynparam list
/amcl
/move_base
/move_base/TrajectoryPlannerROS
/move_base/global_costmap
/move_base/global_costmap/inflation_layer
/move_base/global_costmap/obstacle_layer
/move_base/local_costmap
/move_base/local_costmap/inflation_layer
/move_base/local_costmap/obstacle_layer
/velocity_smoother
2.獲取一個可以動態調參的節點的動態參數配置
$ rosrun dynamic_reconfigure dynparam get /node
範例:
firefly@firefly:~$ rosrun dynamic_reconfigure dynparam get /move_base/local_costmap/inflation_layer
{'inflate_unknown': False, 'cost_scaling_factor': 20.0, 'inflation_radius': 0.28, 'enabled': True, 'groups': {'cost_scaling_factor': 20.0, 'parent': 0, 'inflation_radius': 0.28, 'groups': {}, 'id': 0, 'name': 'Default', 'parameters': {}, 'enabled': True, 'state': True, 'inflate_unknown': False, 'type': ''}}
firefly@firefly:~$ rosrun dynamic_reconfigure dynparam get /move_base/TrajectoryPlannerROS
{'max_vel_theta': 1.0, 'vtheta_samples': 20, 'min_vel_x': 0.0, 'heading_lookahead': 0.325, 'restore_defaults': False, 'heading_scoring': False, 'min_vel_theta': -1.0, 'angular_sim_granularity': 0.025, 'holonomic_robot': False, 'acc_lim_x': 0.2, 'acc_lim_y': 0.0, 'heading_scoring_timestep': 0.8, 'dwa': True, 'oscillation_reset_dist': 0.1, 'escape_vel': -0.1, 'sim_time': 2.5, 'y_vels': '-0.3,-0.1,0.1,-0.3', 'simple_attractor': False, 'acc_lim_theta': 1.8, 'min_in_place_vel_theta': 0.05, 'gdist_scale': 0.3, 'groups': {'max_vel_theta': 1.0, 'simple_attractor': False, 'y_vels': '-0.3,-0.1,0.1,-0.3', 'parent': 0, 'acc_lim_theta': 1.8, 'min_in_place_vel_theta': 0.05, 'dwa': True, 'vtheta_samples': 20, 'min_vel_theta': -1.0, 'heading_lookahead': 0.325, 'gdist_scale': 0.3, 'groups': {}, 'heading_scoring': False, 'min_vel_x': 0.0, 'id': 0, 'angular_sim_granularity': 0.025, 'holonomic_robot': False, 'name': 'Default', 'parameters': {}, 'acc_lim_x': 0.2, 'acc_lim_y': 0.0, 'escape_reset_theta': 1.57079632679, 'restore_defaults': False, 'occdist_scale': 0.8, 'vx_samples': 8, 'heading_scoring_timestep': 0.8, 'state': True, 'sim_time': 2.5, 'pdist_scale': 0.8, 'max_vel_x': 0.2, 'sim_granularity': 0.025, 'type': '', 'escape_reset_dist': 0.1, 'oscillation_reset_dist': 0.1, 'escape_vel': -0.1}, 'escape_reset_theta': 1.57079632679, 'occdist_scale': 0.8, 'vx_samples': 8, 'pdist_scale': 0.8, 'max_vel_x': 0.2, 'sim_granularity': 0.025, 'escape_reset_dist': 0.1}
3.給一個節點的動態參數賦值value
單個參數
$ rosrun dynamic_reconfigure dynparam set /node parameter_name value
or多個參數(set node_name yaml_dictionary)
$ rosrun dynamic_reconfigure dynparam set wge100_camera "{'camera_url':'foo', 'brightness':58}"
範例:
rosrun dynamic_reconfigure dynparam set /move_base/local_costmap/inflation_layer inflation_radius 0.01
4.從參數服務器加載數據
rosrun dynamic_reconfigure dynparam set_from_parameters /node
5.將動態參數配置存到yaml配置文件中
rosrun dynamic_reconfigure dynparam set_from_parameters /node
6.從yaml配置文件中加載配置動態參數
$ rosrun dynamic_reconfigure dynparam load /node dump.yaml
第二部分:動態參數服務的建立
2.在C++程序中應用dynamic_reconfigure
- 安裝dynamic_reconfigure軟件包
sudo apt-get install -y ros-kinetic-dynamic-reconfigure
- 在參數服務器中添加參數
- 使用dynamic_reconfigure動態調節節點參數