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

How to force std::vector type for fixed-length arrays in msg?

asked 2019-01-19 08:55:46 -0500

Hypomania gravatar image

updated 2019-01-19 09:18:01 -0500

Hi,

According to this page http://wiki.ros.org/msg fixed-length arrays in msg files can be interpreted as boost::array or std::vector.

Whenever I tried to apply any vector logic to a message with a fixed-length array (let's say uint8[8]) it would throw errors saying that the type is of boost::array.

How can I enforce std::vector type on fixed-sized fields inside ROS messages?

EDIT: here's an example: http://docs.ros.org/api/can_msgs/html/msg/Frame.html, I would like to have data field as std::vector without changing the field itself to uint8[].

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-01-19 09:18:12 -0500

The documentation is not saying you can use either type, it is saying that depending on the version it will either be a boost::array or a std::vector. In your case the type is boost::array so you will need to access it using that object type.

You would need to copy the data into a std::vector if you wanted to use that functionality since boost::array is a fixed length data type so cannot support the features of std::vector.

edit flag offensive delete link more

Comments

Thank you. One quick question, for that message format I would have to copy data from callback rather than pointing it with a pointer, right?

Hypomania gravatar image Hypomania  ( 2019-01-19 09:25:12 -0500 )edit

Also, do you have any references where I could look at how to properly copy boost::arrays? I am not familiar with boost at all unfortunately.

Hypomania gravatar image Hypomania  ( 2019-01-19 09:26:43 -0500 )edit
1

The reference is here, it has size() method identical to std::vector and uses [square brackets] for element access. That should cover most tasks.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-01-19 13:01:40 -0500 )edit

@PeteBlackerThe3rd, really appreciated, that looks exactly what I need!

Hypomania gravatar image Hypomania  ( 2019-01-19 13:26:41 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2019-01-19 08:55:46 -0500

Seen: 1,546 times

Last updated: Jan 19 '19