[ros-users] Message construction with memcpy

Bill Morris morris at ee.ccny.cuny.edu
Thu Jul 8 23:21:00 UTC 2010


I am wondering if there is a suggested method for constructing a message
directly from binary data stored in memory.

Right now I read in data from a serial port into a buffer and once I
have a complete chunk of data I memcpy it into a struct. I then copy
each item in the struct into the message, item by item. I would like to
avoid copying each item individually by name.

Are the following structs and messages laid out in memory the same way?
Are there byte order or alignment issues I should be aware of if i
attempt to create a message using memcpy?

Do I want to deserialize or serialize the message? Is there
documentation for this somewhere? Is there a better way to do this?

    struct IMU
    {
      int angle_nick;
      int angle_roll;
      int angle_yaw;
      short acc_x;
      short acc_y;
      short acc_z;
    };

IMU.msg
int32 angle_nick
int32 angle_roll
int32 angle_yaw
int16 acc_x
int16 acc_y
int16 acc_z





More information about the ros-users mailing list