
I need to iterate on the msg if it is not empty and I would very much like to get the last element without iterating on the whole thing.
You ask about rospy, which would make this Python.
As you can see on wiki/msg (which documents the ROS 1 msg IDL and how it gets mapped to various programming languages), a field of type geometry_msgs/PoseStamped[] will be mapped to a Python tuple (ie: a tuple of geometry_msgs/PoseStamped instances, as many as were put in the array byt the sender).
For your use you can just consider that a list, and accessing the last element of a list can be done as follows in Python (my_msg is an instance of a message with pose_list being a field of type geometry_msgs/PoseStamped[]):
last_element = my_msg.pose_list[-1]
Iteration would be as you would normally do this with Python:
for elem in my_msg.pose_list:
# do something
Note: this is not ROS specific at all. It's all just Python.
I must be missing something because these look like basic things one should be able to do.
The reason you cannot find any specific documentation about this is because it isn't something ROS changes.
Originally posted by gvdhoorn with karma: 86574 on 2020-08-18
This answer was ACCEPTED on the original site
Post score: 3
Original comments
Comment by gbohus on 2020-08-19:
Thank you @gvdhoorn.
My mistake was not to look inside the message, but trying to iterate on/access the elements of the message itself.