title: PointCloud2 Storage Format
body: <p>I am trying to implement in FPGA a ROS publisher node of PointCloud2 messages. As a first step, i have already implemented a publisher node on the FPGA that is publishing strings. Now, i am trying to do the same but for the PointCloud2 message format.</p>
  <p>It is very simple to understand how a string is stored, basically each character is converted to its ASCII value and stored (as it can be seen <a href="http://wiki.ros.org/ROS/Connection%20Header" rel="nofollow noreferrer">here</a>). On the other hand, a PointCloud2 is a complex data type that is not so easy to understand.</p>
  <p>I have made some progress on understanding how the metadata of a PointCloud2 is stored, however, it is being very difficult to understand the storage of the data part of the PointCloud2 data type. To simplify, I have also tried a PointCloud2 with only one point but i couldn't decode it either. I know that the X, Y and Z are sequentially ordered with 4 bytes each (the datatype is a Float32). Therefore, i can isolate the 4 bytes corresponding to one of the coordinates. I have tried to assign to the X coordinate the values from 0 to 17 (in decimal). This are the values stored when using these values (they are all in decimal):</p>
  <p>1 = [0, 0, 128, 63] -&gt; little-endian so, the most significant byte is 63 followed by, 128, 0, 0</p>
  <p>2 = [0, 0, 0, 64]</p>
  <p>3 = [0, 0, 64, 64]</p>
  <p>4 = [0, 0, 128, 64]</p>
  <p>5 = [0, 0, 160, 64]</p>
  <p>6 = [0, 0, 192, 64]</p>
  <p>7 = [0, 0, 224, 64]</p>
  <p>8 = [0, 0, 0, 65]</p>
  <p>9 = [0, 0, 16, 65]</p>
  <p>10 = [0, 0, 32, 65]</p>
  <p>11 = [0, 0, 48, 65]</p>
  <p>12 = [0, 0, 64, 65]</p>
  <p>13 = [0, 0, 80, 65]</p>
  <p>14 = [0, 0, 96, 65]</p>
  <p>15 = [0, 0, 112, 65]</p>
  <p>16 = [0, 0, 128, 65]</p>
  <p>17 = [0, 0, 136, 65]</p>
  <p>So, my question is, how are the values stored? Supposedly the data part is stored in binary blobs according to <a href="http://docs.ros.org/en/api/sensor_msgs/html/msg/PointCloud2.html" rel="nofollow noreferrer">here</a>. However, i don't understand what does this mean and how it works. Also, i have not found any concrete example on how to convert a decimal value to this representation.</p>
  <p>For a PointCloud2 with X, Y and Z my current understanding is the following (<a href="https://imgbb.com/72XdjCc" rel="nofollow noreferrer">here</a> is the corresponding data):</p>
  <p>header:</p>
  <ul>
  <li>seq (4 bytes)</li>
  <li>stamp (8 bytes)</li>
  <li>frame_id (1 byte per character)</li>
  </ul>
  <p>height: 4 bytes</p>
  <p>width: 4 bytes</p>
  <p>fields:</p>
  <ul>
  <li>number of fields (4 bytes)</li>
  </ul>
  <p>field 1</p>
  <ul>
  <li>dimension (4 bytes)</li>
  <li>name (1 byte)</li>
  <li>offset (4 bytes)</li>
  <li>datatype (1 byte)</li>
  <li>count (4 bytes)</li>
  </ul>
  <p>field 2</p>
  <ul>
  <li>dimension (4 bytes)</li>
  <li>name (1 byte)</li>
  <li>offset (4 bytes)</li>
  <li>datatype (1 byte)</li>
  <li>count (4 bytes)</li>
  </ul>
  <p>field 3</p>
  <ul>
  <li>dimension (4 bytes)</li>
  <li>name (1 byte)</li>
  <li>offset (4 bytes)</li>
  <li>datatype (1 byte)</li>
  <li>count (4 bytes)</li>
  </ul>
  <p>is_bigendian: 1 byte</p>
  <p>point_step: 4 bytes</p>
  <p>row_step: 4 bytes</p>
  <p>size: 4 bytes</p>
  <p>data: size bytes</p>
  <p>is_dense: 1 byte</p>