ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Passing Matrices as params in Launch Files

asked 2019-04-30 16:01:15 -0500

jbu gravatar image

I'd like to pass the data contained within a matrix as a parameter to several nodes in a launch file. This link states how to pass in std::vector<...> params for bools, ints, doubles, etc. Is it possible to pass in something like a std::vector< std::vector<int> > via the launch file?

I'm looking for something similar to this answer: given a launch file

<launch>
<node name="..." ...>
     <rosparam param="matrix">
         [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
     </rosparam>
</node>
</launch>

I'd like to recover the value of matrix within the node by calling something similar to:

std::vector<std::vector<int> > matrix;
nh.getParam("matrix", matrix);

This method didn't work when I tried it though. Is there another way this can be done?

(I'm using ROS Kinetic on Ubuntu 16.04)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-04-30 23:08:15 -0500

rumman gravatar image

Robot localization package is a great example for something like this

you can define your 2d matrix as a param as shown in this example: https://github.com/cra-ros-pkg/robot_...

you can then parse it back using the example here: https://github.com/cra-ros-pkg/robot_...

edit flag offensive delete link more

Comments

1

So essentially this works by reshaping the matrix into a 1D array, passing it in along with the matrix row length, then iterating over the elements to reconstruct each row. That seems like a good alternative.

jbu gravatar image jbu  ( 2019-05-01 10:58:32 -0500 )edit
1

Yes that is correct. Just keep in mind, if all the parameters are not specified with a decimal point, you will have to use stringstream to handle them

rumman gravatar image rumman  ( 2019-05-01 12:01:41 -0500 )edit

Question Tools

3 followers

Stats

Asked: 2019-04-30 16:01:15 -0500

Seen: 1,826 times

Last updated: Apr 30 '19