rospy ColorRGBA array messages changing all vectors
So I'm trying to make certain LED's change color on certain events, I wrote a small program to test these changes
import rospy
from ledtracker.msg import ColorArray
from std_msgs.msg import ColorRGBA
def publisher():
pub = rospy.Publisher('/ledscape_ros/array', ColorArray, queue_size=10)
rospy.init_node('userstracker_vectors', anonymous=True)
rate=rospy.Rate(0.2)
msg = ColorRGBA()
msg.r = 0.0
msg.g = 0.0
msg.b = 255.0
msg.a = 255.0
msga = ColorArray()
for i in range(221):
msga.leds.append(msg)
while not rospy.is_shutdown():
rospy.loginfo('Publishing')
msga.leds[10].r = 255.0
pub.publish(msga)
rate.sleep()
if __name__ == '__main__':
try:
publisher()
except rospy.ROSInterruptException:
pass
If i try this, all LED's get colored red. I tried adding:
msg2 = ColorRGBA()
msg2.r = 255.0
msga.leds.insert(10, msg2)
print(msga.leds[10])
print(msga.leds[11])
to see if that would help the problem but it didn't , this time it correctly colors only the 10th LED but then after the first iteration it continues to color the 11th and then the 12th and so forth till it has colored all LED's after the 10th. Is there something I'm missing on how to publish this array?
the message is simply
std_msgs/ColorRGBA[] leds
Thanks in advance!