Robotics StackExchange | Archived questions

How to create a uint24 data type

We're trying to read a radar udp packet and one of the data types is of a uint24 type. We were thinking of a couple solutions:

We could create a msg like so:

uint8[3] data

OR

uint8 data1

uint8 data2

uint8 data3

OR

we could create a new struct that could read in this data.

Does ROS have any ros-centric socket library, by any chance?

Asked by AnkilP on 2018-07-24 12:18:54 UTC

Comments

Is shoving it into a UInt32 that wasteful? (Are there a lot of uint24s in every packet?).

Asked by lucasw on 2018-07-24 12:36:11 UTC

If you want a generic ros node to send and receive network packets that belongs in a separate question- it would be very useful if someone were to make one if it doesn't already exist. #q298232 is similar but it and the answer are for TCP, but it could be extended to support either.

Asked by lucasw on 2018-07-24 12:37:06 UTC

I agree, put it in a uint32. uint24 isn't a native type to any system, it's just a truncated uint32 used for storage/transport. The compiler will probably word align the data anyway, so it'll take up exactly the same amount of space.

Asked by PeteBlackerThe3rd on 2018-07-24 12:53:42 UTC

yeah that was our first solution, however, the rest of the data have strict bit position requirements. Interestingly enough, there's only two 24 bit entries

Asked by AnkilP on 2018-07-24 13:02:33 UTC

You're not trying to have union of raw bytes from the network and ros msg are you? You need to peel apart the source data, convert individual fields as necessary, and populate a ros message field by field. If there is a big array that could go straight across though, like the uint8[] data in Image

Asked by lucasw on 2018-07-24 15:19:10 UTC

Answers