It's good that you're giving it a shot yourself; it gives people a better idea of your objective and shows that you're not just asking others to do it for you :).
As Akhil's answer indicates, the width
parameter in the PointCloud2
message is metadata concerning the structure of the message data and does not indicate anything about what the data physically represents.
how can I publish that in another topic?
Publishing a topic is well covered by tutorials (C++, Python) and other questions on this site.
I wanna measure the width of a box from the laser data
For your goal, you'll have to implement a perception/computer vision algorithm, which is a very broad topic, and the details are highly dependent on your application. Such open ended questions are difficult to answer in a format like this, but I'll try. Here, we want the width of a box. One option would be to train a neural network to find the box and regress its boundary, but I would save that for more complex/general cases. If we can make some valid assumptions about the circumstances, then a more direct solution is possible. The more assumptions we make, the more constraints the problem has, and (usually) the simpler the algorithm. For example, assuming a 2-dimensional world is fairly common and eliminates a lot of complexity. We could also assume the box is sitting flat on the ground.
If we assume that the box is alone in the world, then every point in the point cloud belongs to the box, and locating it is no longer an issue. Otherwise, we may use a clustering algorithm to split the point cloud into objects and compare the objects' attributes to determine which is the box of interest. How best to find the box depends on what else we expect to exist in the world.
Once we have the set of points that represents the box, we have to measure its width. Again, assumptions can make this easy, but you have to determine which are valid for the application. If we assume that a rough estimate of the box size is good enough, we can just iterate through the box points to find the two farthest apart and call that its width. It may not be the exact length of a side--maybe it's actually the box's diagonal--but maybe that's close enough.
If we specifically want the length of a side we'll have to identify that side or figure out the box's orientation. If we assume we'll always approach the box perpendicularly to a face, then we can calculate y_max - y_min = width
(the +y-axis being to our left). Otherwise, we may identify faces based on the surface normals. Then, we could group the points by surface normal and find the two most distant points within a group. This still carries the assumption that we've captured an entire side of the box in ... (more)