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

Better msg implementation for random, complicated shape in 2D

asked 2012-06-07 15:35:30 -0600

130s gravatar image

updated 2012-06-08 06:24:01 -0600

I want to design a .msg that represents a line with irregular shape. What would be the best optimal option especially utilizing existing ROS msg types as much as possible? Example image:

image description(Image obtained from

The line like red curvy one in this figure is my target. For now, whether the line draws a cycle can be ignored for my purpose (to represent non-cyclic line is another design discussion).

My idea is:

geometry_msgs/Point[] dotsOnLine
# The order of Point objects in the array can be determined by certain algorithm. Not a focus in this discussion.

I found sensor_msgs/RegionOfInterest might be a good fit for rectangular/squares, but I guess not for irregular shapes. I'm asking particularly because I'm afraid I might be missing good existing msg types (I've only looked at common_msgs).

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-06-07 17:01:38 -0600

Eric Perko gravatar image

I'd say this is exactly what you are looking for: geometry_msgs/PolygonStamped. That contains a standard header as well as a geometry_msgs/Polygon message that is basically the same as yours (but uses 32-bit floats instead of 64-bit doubles).

A bonus to using geometry_msgs/PolygonStamped instead of the non-stamped version or your own message is that you get the RVIZ Polygon display for free :-)

edit flag offensive delete link more


+1; sounds perfect incl. RViz feature except that I'm not yet sure how the msg type works when the line doesn't go cyclic which I'm trying to figure out now. Also I need to know how sparse the points can become so that ROS detects the line closes its loop.

130s gravatar image 130s  ( 2012-06-08 14:20:19 -0600 )edit

Take a look at (the embedded Polygon message). It states that the assumption is that the first and last points are connected, so it can't represent non-closed polygons. I don't think there are any sparseness constraints...

Eric Perko gravatar image Eric Perko  ( 2012-06-08 19:56:57 -0600 )edit

Yeah I saw that doc too, & I just tested with a simple code out of curiosity (e.g. what error would I get if loop not closed etc.). Turned out to me that ROS compensates the miss-match b/w 2 pts so that the line represented by PolygonStamped always closed-loops. My sample code:

130s gravatar image 130s  ( 2012-06-11 07:06:28 -0600 )edit

Question Tools


Asked: 2012-06-07 15:35:30 -0600

Seen: 1,084 times

Last updated: Jun 08 '12