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

What does `Int32MultiArray.layout.data_offset` mean

asked 2016-02-27 00:46:26 -0500

Here's the contents of Int32MultiArray.msg:

# Please look at the MultiArrayLayout message definition for
# documentation on all multiarrays.

MultiArrayLayout  layout        # specification of data layout
int32[]           data          # array of data

And here's the contents of MultiArrayLayout

# The multiarray declares a generic multi-dimensional array of a
# particular data type.  Dimensions are ordered from outer most
# to inner most.

MultiArrayDimension[] dim # Array of dimension properties
uint32 data_offset        # padding bytes at front of data                         (A)

# Accessors should ALWAYS be written in terms of dimension stride
# and specified outer-most dimension first.
# 
# multiarray(i,j,k) = data[data_offset + dim_stride[1]*i + dim_stride[2]*j + k]    (B)
<snip>

Uh oh - contradiction! Is .layout.data_offset the offset in bytes (A) or the offset in words (B)? If the former, how are we supposed to adjust for something unaligned like data_offset = 3?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-02-29 12:57:28 -0500

jackie gravatar image

It's true, the documentation contradicts itself for most data types. If data_offset is in bytes, then the indexing scheme described in B only applies to byte arrays.

If data_offset truly were in bytes, then it would take more complicated bitwise arithmetic to index into the array, particularly if offset were unaligned. The comment on line A should probably be changed to something like "Number of padding entries at front of data".

Of course, before changing the documentation, it might be good to understand how downstream packages are using MultiArrayLayout and if they consider data_offset to count bytes or words, but again I suspect that few users of std_msgs are doing the proper bitshifting necessary to accomodate byte padding for 32 or 64-bit int types.

Can you ticket this issue on https://github.com/ros/std_msgs? Thanks.

edit flag offensive delete link more

Comments

I've submitted an issue

eric-wieser gravatar image eric-wieser  ( 2016-02-29 17:18:52 -0500 )edit

For the record the issue is here: https://github.com/ros/std_msgs/issues/9

tfoote gravatar image tfoote  ( 2016-03-10 18:52:11 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2016-02-27 00:46:26 -0500

Seen: 850 times

Last updated: Feb 29 '16