0
$\begingroup$

Rosanswers logo

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


Originally posted by tomurillo on ROS Answers with karma: 55 on 2011-09-06

Post score: 5

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

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.


Originally posted by dornhege with karma: 31395 on 2011-09-06

This answer was ACCEPTED on the original site

Post score: 4

$\endgroup$
0
$\begingroup$

Rosanswers logo

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.


Originally posted by hersh with karma: 1351 on 2011-09-12

This answer was NOT ACCEPTED on the original site

Post score: 16


Original comments

Comment by tomurillo on 2011-09-15:
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!

Comment by user23fj239 on 2016-04-30:
The hint for a different id reallly helped, thank you!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.