ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
2 | No.2 Revision |
I finally ended up setting the parameter by using a launch file for my node.
Example:
Launch file:
<launch>
<rosparam param="x_vector">[1.0, 2.0,
3.0]</rosparam>
<node name="my_node" pkg="my_package" type="my_node" />
</launch>
Then in your node, get the vector like this:
std::vector<double> x_vec;
std::vector<double> x_vec_default = {1.0, 0.5, 0.5, 1.0};
n.param<std::vector<double> >("x_vector", x_vec, x_vec_default);
And x_vec
will hold the values given in the launch file, or the contents in x_vec_default
if the x_vector
is not available as a parameter (for example if launching the node without the launch file).