Ask Your Question
0

Accessing point32 under geometry_msgs/PolygonStamped

asked 2017-07-19 01:36:04 -0500

BotLover gravatar image

Hi, I am new to ROS so excuse me for the silly doubt. There is a topic being published by a package, of type geometry_msgs/PolygonStamped. On executing rosmsg show this is what I got std_msgs/Header header uint32 seq time stamp string frame_id geometry_msgs/Polygon polygon geometry_msgs/Point32[] points float32 x float32 y float32 z Now I want to subscribe this topic and access Point x,y,z. How do I do it? Thanks in advance!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-07-19 02:02:16 -0500

mgruhler gravatar image

Follow this tutorial, the Subscriber part, exchange std_msgs/String with geometry_msgs/PolygonStamped and then access with msg->polygon.points[i].x etc. Note that points is actually an std::vector so make sure to access this correctly.

edit flag offensive delete link more

Comments

my callback function looks like void Callback(const PolygonStampedConstPtr& poly). Inside callback I am doing float u = poly->polygon.points.x; float v = poly->polygon.points.y;. But according to your answer what should my i be?

BotLover gravatar image BotLover  ( 2017-07-19 03:09:30 -0500 )edit

i depends on the vector. You have multiple elements, so it should be within the range of the number of polygons. You could also iterate over the full vector...

mgruhler gravatar image mgruhler  ( 2017-07-19 05:49:56 -0500 )edit

It solved my problem. Thanks mig. I also want the time difference between consecutive calls to callback function. Can you tell how it would be done? I was thinking of difference b/w ros::time::now, but don't know how to use it!

BotLover gravatar image BotLover  ( 2017-07-19 12:03:34 -0500 )edit

please post a new question..

mgruhler gravatar image mgruhler  ( 2017-07-20 01:14:40 -0500 )edit

Yaa got it!

BotLover gravatar image BotLover  ( 2017-07-22 15:28:29 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-07-19 01:36:04 -0500

Seen: 1,261 times

Last updated: Jul 19 '17