Open Miker2808 opened 2 years ago
The same problem. Did you find a solution?
Afraid I did not, decided to use a solution that doesn't require ros2 bag. from my digging it seems related to the code screwing up with "rosidl" somewhere
Even after the merging, I'm still getting this error. Has anyone made any more advances?
Tank you very much.
Did you guys finish the probelem?
Guys this problem is caused by the "message_conventer.py". Here is the resolution of this problem: https://github.com/mehmetkillioglu/ros2_message_converter/issues/3#issuecomment-980434616
def _is_ros_binary_type(field_type): """ Checks if the field is a binary array one, fixed size or not list(bytearray(de(encoded_data))) _is_ros_binary_type("uint8")
False _is_ros_binary_type("uint8[]") True _is_ros_binary_type("uint8[3]") True _is_ros_binary_type("char") False _is_ros_binary_type("char[]") True _is_ros_binary_type("char[3]") True _is_ros_binary_type("octet") True """ return field_type.startswith('uint8[') or field_type.startswith('char[') or field_type.startswith('octet')
Add the octet type here.
Hi. I've added the octet type:
However, I'm still getting a similar error:
I'm using a whole bunch of custom message types, so I wonder if I should add more clauses besides uint8, char and octet. Do you know how can I check which ones to add?
Thank you in advance.
you can try modify the convert_ros_message_to_dictionary function to:
def convert_ros_message_to_dictionary(message):
"""
Takes in a ROS message and returns a Python dictionary.
Example:
ros_message = std_msgs.msg.String(data="Hello, Robot")
dict_message = convert_ros_message_to_dictionary(ros_message)
"""
dictionary = {}
if hasattr(message, 'get_fields_and_field_types'):
message_fields = message.get_fields_and_field_types()
for (field_name, field_type) in message_fields.items():
field_value = getattr(message, field_name)
dictionary[field_name] = _convert_from_ros_type(field_type, field_value)
else:
dictionary = None
return dictionary
Also, add create csv if not exist function to save_csv_file.py:
def save_csv_file(data, csv_file_name, version=0, print_out=False):
""" Save data to a csv_file_name (use it after 'read_from_all_topics').
"""
# Create csv file
import os
if not os.path.exists(os.path.dirname(csv_file_name)):
os.makedirs(os.path.dirname(csv_file_name))
...................................
This is a package that modified the code based on the above advice. You can use git clone as it is.
When attempting to run with my rosbag I generated from a simulation I received this error, tried both in ubuntu 20 and windows 10 Working on ROS2 Foxy.
` ['/simulation/d9/gps', '/simulation/d9/imu/acceleration', '/simulation/d9/imu/orientation', '/simulation/d9/imu/orientation/rate', '/simulation/d9/imu/velocity'] Traceback (most recent call last): File "/home/simteam/.local/bin/ros2bag-convert", line 8, in
sys.exit(main())
File "/home/simteam/.local/lib/python3.8/site-packages/ros2bag_convert/main.py", line 14, in main
data = read_bag.read_from_all_topics(file_url,True)
File "/home/simteam/.local/lib/python3.8/site-packages/ros2bag_convert/ros2bag_convert/read_bag.py", line 210, in read_from_all_topics
timestamps, messages = read_from_topic(bag_file, topic_names[i], print_out)
File "/home/simteam/.local/lib/python3.8/site-packages/ros2bag_convert/ros2bag_convert/read_bag.py", line 183, in read_from_topic
dic_data = message_converter.convert_ros_message_to_dictionary(msg)
File "/home/simteam/.local/lib/python3.8/site-packages/ros2bag_convert/ros2bag_convert/message_converter.py", line 243, in convert_ros_message_to_dictionary
dictionary[field_name] = _convert_from_ros_type(field_type, field_value)
File "/home/simteam/.local/lib/python3.8/site-packages/ros2bag_convert/ros2bag_convert/message_converter.py", line 259, in _convert_from_ros_type
field_value = convert_ros_message_to_dictionary(field_value)
File "/home/simteam/.local/lib/python3.8/site-packages/ros2bag_convert/ros2bag_convert/message_converter.py", line 240, in convert_ros_message_to_dictionary
message_fields = message.get_fields_and_field_types()
AttributeError: 'numpy.ndarray' object has no attribute 'get_fields_and_field_types'
`