Ask Your Question

Assign C++ Array to ROS Msg Array

asked 2016-04-22 16:01:53 -0500

atp gravatar image

How do I assign a C++ array to a ROS message array? In particular, how do I do this for a float64[9] array?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2016-04-23 20:21:37 -0500

robustify gravatar image

The std_msgs/Float64MultiArray message should do what you want:

The message structure has a single field called data which can be treated as a std::vector<double> type in your C++ node. If you know it will be a fixed array of 9 values, just allocate 9 elements in the vector after declaring the message variable:

std_msgs::Float64MultiArray array_msg;;

You can then publish and subscribe to a topic to transmit array messages between your nodes.

I hope this helps!

edit flag offensive delete link more

answered 2018-07-13 00:41:24 -0500

float64[9] is defined as of type boost::array<double,ul9>, so try following declaration:

boost::array<double, ul9> array_msg
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-04-22 16:01:53 -0500

Seen: 8,806 times

Last updated: Apr 23 '16