Ask Your Question
0

MarkerArray to vector

asked 2019-04-18 03:16:37 -0500

RalLpezMartn gravatar image

I am trying to get some information which is being published in RViz from other nodes I did not programmed. I checked the type of messages are being post in the topics I am interested in. The one that is giving me problems is the MarkerArray type of message. I know this type have inside different Marker type. Therefore I imported both Marker and MarkerArray from visualization_msg.msgs (I am programming the node in Python, in Ubuntu 16.04). I checked the message type and I want to obtain all the position of the markers. Hence, I tried printing msg.markers.pose.position.x and msg.markers.points.x but both of them trigger the same error, msg.markers does not have that attribute. Actually it does not have any of the attributes it should but others. Those are the attributes I am getting with:

dir(msg.markers)

['__add__',  '__class__', '__contains__', '__delattr__',       '__delitem__', '__delslice__',       '__doc__', '__eq__', '__format__',       '__ge__', '__getattribute__',       '__getitem__', '__getslice__',       '__gt__', '__hash__', '__iadd__',       '__imul__', '__init__', '__iter__',      '__le__', '__len__', '__lt__',       '__mul__', '__ne__', '__new__',       '__reduce__', '__reduce_ex__',       '__repr__', '__reversed__',       '__rmul__', '__setattr__',       '__setitem__', '__setslice__',       '__sizeof__', '__str__',       '__subclasshook__', 'append',       'count', 'extend', 'index', 'insert',    'pop', 'remove', 'reverse', 'sort']

Do I have to declare the markers as something else to be able to obtain those data? I know Markers are supposed to be just to print but it is the only topic with the data I need to use.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-04-18 03:30:54 -0500

gvdhoorn gravatar image

updated 2019-04-18 03:34:45 -0500

This is quite similar to #q321354, but in Python and with a different message type.

visualization_msgs/MarkerArray has a single field:

visualization_msgs/Marker[] markers

markers is an unbounded array (or list). For Python, those are mapped onto tuples (see wiki/msg).

Hence, I tried printing msg.markers.pose.position.x and msg.markers.points.x but both of them trigger the same error, msg.markers does not have that attribute

If msg is a MarkerArray, you must first select one of the elements in the markers tuple before you can access any of the properties of that Marker.

So to access the second Marker in the markers tuple, you'd do:

msg.markers[1].pose.position.x

(after making sure it actually contains at least two markers, of course)

edit flag offensive delete link more

Comments

And similar to #q321354, this is a Python question, not something ROS specific.

gvdhoorn gravatar image gvdhoorn  ( 2019-04-18 03:31:54 -0500 )edit

Well that was quick and extremely useful. Haven't work with this kind of elements ever. That solved it perfectly, thank you so much.

RalLpezMartn gravatar image RalLpezMartn  ( 2019-04-18 04:20:28 -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: 2019-04-18 03:16:37 -0500

Seen: 516 times

Last updated: Apr 18 '19