Rviz visualization of cube trajectories from green to red
#!/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, queue_size=10)
rospy.init_node('register')
markerArray = MarkerArray()
count = 0 MARKERS_MAX = 100
while not rospy.is_shutdown():
# We add the new marker to the MarkerArray, removing the oldest marker from it when necessary for x in range(0,10): marker = Marker() marker.header.frame_id = "/map" marker.type = marker.CUBE # set our shape to be a cube marker.action = marker.ADD marker.scale.x = 1.0 marker.scale.y = 1.0 marker.scale.z = 1.0 marker.color.a = 1.0 marker.color.r = (50 + (x*2)) / float (255) marker.color.g = 170 / float (255) marker.color.b = 25 / float (255) marker.pose.orientation.w = 1.0 marker.pose.position.x = 0 marker.pose.position.y = 0 marker.pose.position.z = 0
#Remove marker when necessary
#Adding new marker each time in the Marker Array
if(count > MARKERS_MAX):
markerArray.markers.pop(0)
markerArray.markers.append(marker)
# Renumber the marker IDs
id = 0
for i in markerArray.markers:
i.id = id
id += 1
# Publish the MarkerArray
publisher.publish(markerArray)
count += 1
rospy.sleep(0.01)
So I am trying to create a trajectory from position in x going from 0 to 1 with color changing from green to red.
So far this is the code that I have and testing. It is publishing but does not seem to change color and only one box appears.
Any suggestions?