UnicodeDecodeError on nav2 msgs
Hello,
I would like to deserialize a nav2 message which has the type : nav2_msgs/msg/BehaviorTreeLog
Here is my code with rosbags 0.9.22 and ROS HUMBLE :
from pathlib import Path
from rosbags.highlevel import AnyReader
from rosbags.typesys import Stores, get_typestore, get_types_from_msg
bagpath = Path('/home/X/rosbag2_2024_03_21-17_04_36')
# Register types
MSG_BTL="""
builtin_interfaces/Time timestamp
int32 sec
uint32 nanosec
BehaviorTreeStatusChange[] event_log
builtin_interfaces/Time timestamp
int32 sec
uint32 nanosec
string node_name
string previous_status
string current_status
"""
MSG_BTSC = """
builtin_interfaces/Time timestamp
int32 sec
uint32 nanosec
string node_name
string previous_status
string current_status
"""
# Create a type store to use if the bag has no message definitions.
typestore = get_typestore(Stores.ROS2_HUMBLE)
typestore.register(get_types_from_msg(MSG_BTL, 'nav2_msgs/msg/BehaviorTreeLog'))
typestore.register(get_types_from_msg(MSG_BTSC, 'nav2_msgs/msg/BehaviorTreeStatusChange'))
# Create reader instance and open for reading.
with AnyReader([bagpath], default_typestore=typestore) as reader:
for connection, timestamp, rawdata in reader.messages(connections=reader.connections):
msg = reader.deserialize(rawdata, connection.msgtype)
print(msg)
Here is the trace stack :
Traceback (most recent call last):
File "/home/x/rosbag/testrosbag.py", line 41, in <module>
msg = reader.deserialize(rawdata, connection.msgtype)
File "/home/x/.local/lib/python3.10/site-packages/rosbags/highlevel/anyreader.py", line 118, in deserialize
return self._deser_ros2(rawdata, typ) if self.is2 else self._deser_ros1(rawdata, typ)
File "/home/x/.local/lib/python3.10/site-packages/rosbags/highlevel/anyreader.py", line 114, in _deser_ros2
return self.typestore.deserialize_cdr(rawdata, typ)
File "/home/x/.local/lib/python3.10/site-packages/rosbags/typesys/store.py", line 146, in deserialize_cdr
message, pos = func(rawdata[4:], 0, msgdef.cls, self)
File "<string>", line 33, in deserialize_cdr
File "<string>", line 28, in deserialize_cdr
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9a in position 28: invalid start byte
I've found the definition of nav2_msgs/msg/BehaviorTreeLog
and nav2_msgs/msg/BehaviorTreeStatusChange
with ros2 interface show
. Is it the problem ?
Here is my rosbag : rosbag2_2024_03_21-17_04_36.zip
Thanks
Edited by jordanlv1