[ros-users] How to set the value in an array for a message

Brian Gerkey gerkey at willowgarage.com
Sat Jan 29 18:39:02 UTC 2011


On Thu, Jan 27, 2011 at 3:41 PM, Huo, Zhiyu (MU-Student)
<zhiyuhuo at mail.mizzou.edu> wrote:
> I have a problem of setting the value of an array in a message. I write a
> node that used to talk to a LRF and publish the topic of the message type of
> LaserScan. However, I can not set the value of the array msg.ranges[] in
> this message. The node break when I trying to give a value to an element of
> that array.

You probably need to allocate space first.  E.g., if you want to put
in 100 range readings:
  msg.ranges.resize(100);

Check the docs on C++ vectors to learn more, e.g.:
http://www.cplusplus.com/reference/stl/vector/

	brian.



More information about the ros-users mailing list