Ask Your Question
4

plotting a MarkerArray of spheres with rviz

asked 2011-09-06 21:35:41 -0500

tomurillo gravatar image

updated 2014-01-28 17:10:21 -0500

ngrennan gravatar image

Hi,

I'm trying to plot a number of sphere markers at a time, appending them to a MarkerArray and then publishing it, using python. Here's part of my code:

topic = 'visualization_marker_array'
publisher = rospy.Publisher(topic, MarkerArray)

rospy.init_node('register')

markerArray = MarkerArray()

while not rospy.is_shutdown():

   # ... here I get the data I want to plot into a vector called trans

   marker = Marker()
   marker.header.frame_id = "/neck"
   marker.type = marker.SPHERE
   marker.action = marker.ADD
   marker.scale.x = 0.2
   marker.scale.y = 0.2
   marker.scale.z = 0.2
   marker.color.a = 1.0
   marker.pose.orientation.w = 1.0
   marker.pose.position.x = trans[0]
   marker.pose.position.y = trans[1]
   marker.pose.position.z = trans[2]

   # We add the new marker to the MarkerArray, removing the oldest marker from it when necessary
   if(count > MARKERS_MAX):
    markerArray.markers.pop(0)
   else:
    count += 1
   markerArray.markers.append(marker)


# Publish the MarkerArray
publisher.publish(markerArray)

However, I'm getting the following warning and no markers are being shown in rviz:

"Could not process inbound connection: topic types do not match: [visualization_msgs/Marker] vs. [visualization_msgs/MarkerArray]{'topic': '/visualization_marker_array', 'tcp_nodelay': '0', 'md5sum': 'bc7602ad2ba78f4cbe1c23250683bdc0', 'type': 'visualization_msgs/Marker', 'callerid': '/rviz_1315381483544111031'}"

Does anyone know how to properly rend a MarkerArray like this?

Thanks in advance

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
4

answered 2011-09-06 22:21:10 -0500

dornhege gravatar image

updated 2012-07-12 03:21:42 -0500

Try removing the "_array" after the topic name in rviz.

PS: For sending a list of spheres there is actually a dedicated marker type which is more efficient than sending a marker array.

edit flag offensive delete link more
13

answered 2011-09-12 10:07:13 -0500

hersh gravatar image

In the ROS Electric version of rviz (the latest version), MarkerArray is a proper display type, you no longer need to go indirectly through the Marker display type. To show the data from the program you posted, in rviz do:

  • Click the "Add" button in the "Displays" area.
  • Choose "MarkerArray" in the type list.
  • Click "OK"

If it doesn't show immediately, do:

  • Click on the "Marker Array Topic" line in the new display entry. This should make an elipsis ("...") button appear.
  • Click the "..." button.
  • A dialog with currently-published MarkerArray topics should appear.
  • Click on "visualization_marker_array" (or whatever you have named it).
  • Click "OK"

Finally, I found some problems with your program.

  • The "id" field of the Marker message needs to be filled out, otherwise every entry in the MarkerArray will have id=0, which means only one of them will be displayed. Additionally, the IDs should not just increase indefinitely or the old marker positions will not be erased.
  • The default marker color is black, and I use a black background in rviz, so I couldn't see them until I set marker.color.r = 1.0, marker.color.g = 1.0, etc.

Here is a program I wrote to test all this, inspired by your code:

#!/usr/bin/env python

import roslib; roslib.load_manifest('visualization_marker_tutorials')
from visualization_msgs.msg import Marker
from visualization_msgs.msg import MarkerArray
import rospy
import math

topic = 'visualization_marker_array'
publisher = rospy.Publisher(topic, MarkerArray)

rospy.init_node('register')

markerArray = MarkerArray()

count = 0
MARKERS_MAX = 100

while not rospy.is_shutdown():

   marker = Marker()
   marker.header.frame_id = "/neck"
   marker.type = marker.SPHERE
   marker.action = marker.ADD
   marker.scale.x = 0.2
   marker.scale.y = 0.2
   marker.scale.z = 0.2
   marker.color.a = 1.0
   marker.color.r = 1.0
   marker.color.g = 1.0
   marker.color.b = 0.0
   marker.pose.orientation.w = 1.0
   marker.pose.position.x = math.cos(count / 50.0)
   marker.pose.position.y = math.cos(count / 40.0) 
   marker.pose.position.z = math.cos(count / 30.0) 

   # We add the new marker to the MarkerArray, removing the oldest
   # marker from it when necessary
   if(count > MARKERS_MAX):
       markerArray.markers.pop(0)

   markerArray.markers.append(marker)

   # Renumber the marker IDs
   id = 0
   for m in markerArray.markers:
       m.id = id
       id += 1

   # Publish the MarkerArray
   publisher.publish(markerArray)

   count += 1

   rospy.sleep(0.01)

Note this code presumes you have the visualization_tutorials stack installed: it references the visualization_marker_tutorials package manifest. Also, you need to set the Fixed Frame in rviz to "neck" if you don't have a TF frame published for that.

If it works, it is pretty mesmerizing.

edit flag offensive delete link more

Comments

1
You're definitely right, I forgot to add a unique ID for each Marker of the MarkerArray. The color wasn't a problem in my case since I have a grey background set on rviz, but good suggestion anyway. Thanks to both dornhege and hersh for helping me out, now it works like a wonder!
tomurillo gravatar imagetomurillo ( 2011-09-15 20:26:03 -0500 )edit

The hint for a different id reallly helped, thank you!

user23fj239 gravatar imageuser23fj239 ( 2016-04-30 03:30:26 -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

Stats

Asked: 2011-09-06 21:35:41 -0500

Seen: 18,701 times

Last updated: Jul 12 '12