如何有效地在ROS中加载大量参数?

时间:2017-05-23 11:06:38

标签: c++ ros

与ROS相比,在ROS中加载许多参数的更好方法是什么:

double default_maxvel_xy = 3;
double default_maxvel_z = 1.5;
double default_maxvel_c = 1;
double default_maxacc_xy = 2;
double default_maxacc_z = 1;
double default_maxacc_c = 1;
double default_maxjerk_xy = 1;
double default_maxjerk_z = 1;
double default_maxjerk_c = 1;
n.param<double>("default_maxvel_xy", default_maxvel_xy, 3);
n.param<double>("default_maxvel_z", default_maxvel_z, 1.5);
n.param<double>("default_maxvel_c", default_maxvel_c, 1);
n.param<double>("default_maxacc_xy", default_maxacc_xy, 2);
n.param<double>("default_maxacc_z", default_maxacc_z, 1);
n.param<double>("default_maxacc_c", default_maxacc_c, 1);
n.param<double>("default_maxjerk_xy", default_maxjerk_xy, 1);
n.param<double>("default_maxjerk_z", default_maxjerk_z, 1);
n.param<double>("default_maxjerk_c", default_maxjerk_c, 1);

m_waypoint.max_dynamics.vel_max.linear.x = default_maxvel_xy;
m_waypoint.max_dynamics.vel_max.linear.y = default_maxvel_xy;
m_waypoint.max_dynamics.vel_max.linear.z = default_maxvel_z;
m_waypoint.max_dynamics.vel_max.angular.x = default_maxvel_c;
m_waypoint.max_dynamics.vel_max.angular.y = default_maxvel_c;
m_waypoint.max_dynamics.vel_max.angular.z = default_maxvel_c;

m_waypoint.max_dynamics.acc_max.linear.x = default_maxacc_xy;
m_waypoint.max_dynamics.acc_max.linear.y = default_maxacc_xy;
m_waypoint.max_dynamics.acc_max.linear.z = default_maxacc_z;
m_waypoint.max_dynamics.acc_max.angular.x = default_maxacc_c;
m_waypoint.max_dynamics.acc_max.angular.y = default_maxacc_c;
m_waypoint.max_dynamics.acc_max.angular.z = default_maxacc_c;

m_waypoint.max_dynamics.jerk_max.linear.x = default_maxjerk_xy;
m_waypoint.max_dynamics.jerk_max.linear.y = default_maxjerk_xy;
m_waypoint.max_dynamics.jerk_max.linear.z = default_maxjerk_z;
m_waypoint.max_dynamics.jerk_max.angular.x = default_maxjerk_c;
m_waypoint.max_dynamics.jerk_max.angular.y = default_maxjerk_c;
m_waypoint.max_dynamics.jerk_max.angular.z = default_maxjerk_c;

它的代码太多而容易出错。 我可以在yaml中创建自定义类型并将其作为一个整体加载吗?

1 个答案:

答案 0 :(得分:2)

字典(在Python意义上)可以作为地图加载,例如地图。 List(以Python的意思)可以作为向量加载,例如地图。

示例:

std::map<std::string, double> parameter_map;
ros::param::get("~my_parameter_map", parameter_map);