ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
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:
If it doesn't show immediately, do:
Finally, I found some problems with your program.
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.