Get all key/value pairs from custom ROS2 message
I've created a custom message that's setup similar to the following
int64 a
int64 b
int64 c
Is there a way to grab all the key/value pairs or just the values in order such that I can iterate over them? I'm imagining something like grabbing key/value pairs from dicts in Python:
for k, v in d.items():
# perform some operation on k/v pair
I'm using ROS2 Dashing on Ubuntu 18.04
If you want to iterate over individual values, why not present them as an iterable type (MultiArray)?
you don't really indicate which language you're interested in (the Python bit seems to be to illustrate the kind of functionality you're after), but in C++, you could perhaps take a look at facontidavide/ros2_introspection.
Without more context as to why you're looking to do this it seems like a strange question, as consumers of ROS messages (whether ROS 1 or ROS 2) typically know beforehand what they're receiving (as topics are typed).
@crnewton I thought about using an array and that would definitely work. The only reason for trying to find a different way with the format I put above is for readability and to have explicit names for the values
@gvdhoorn my apologies for not making it clear. I'm using Python for implementation. The context is that this message sends values to a serial interface node which just redirects the message data to the serial port