Append polygons in PolygonArray
Hey there, I am new to this forum. I just discovered the possibility to display multiple polygons at once (in my case 2D x/y bounding boxes for a radar in RViz). In this case globally I have defined in Python:
from jsk_recognition_msgs.msg import PolygonArray
BB = PolygonArray()
When entering in my callback function, I have a series of if conditions thet get executed sequentially (I am decoding a series of messages from CAN Bus using cantools). So I have something like this:
def can_callback(data):
if data.id == ..A
elif data.id == ..B
elif data.id == ..C
elif data.id == ..D
When program enters the last if (elif data.id, n times as the number of objects detected by the radar), it evaluates for each enter the four vertices of the polygon I would like to visualize. After obtaining the four Vertices namely V1, V2, V3, V4 (Point32 with z coord = 0.0 ), I append to each condition of the if the Point. (by looking at the structure of PolygonArray: PolygonArray
This is what I try to assign in the if:
elif data.id == ..D + entering with i= 0 !
/ do things/
/ obtain V1, V2, V3, V4 /
BB.polygons[i].polygon.points.append(V1)
BB.polygons[i].polygon.points.append(V2)
BB.polygons[i].polygon.points.append(V3)
BB.polygons[i].polygon.points.append(V4)
i=+ 1
I am getting as an error:
BB.polygons[i].polygon.points.append(V1) | IndexError: list index out of range
I don't know where I am getting things wrong, I don't have a clue on how to solve this. Any help is appreciated