0
$\begingroup$

Good day everyone,

I've been struggling with this for two days now. and I can't seem to find a solution. I have a dictionary with topic names and their types, what is the correct module to read the message using rcl?

while reader.has_next():
    topic, message, timestamp = reader.read_next()
    if topic in topic_names:
        message_type_str = topics_dict.get(topic)
        msg = _rclpy.rclpy_deserialize(message, message_type_str)
        print(msg)
        # msg_type = get_message(msg_type_str)
        # msg = deserialize_message(message, msg_type)
        # print(msg)
        # print(topic)
        # print(message_type)
        # print("===================================")
$\endgroup$

1 Answer 1

1
$\begingroup$

I found the solution, for anyone that is interested the correct method is as below:

topic_types = reader.get_all_topics_and_types()
type_map = {topic_types[i].name: topic_types[i].type for i in range(len(topic_types))}

storage_filter = rosbag2_py.StorageFilter(topics=topic_names)
reader.set_filter (storage_filter)

while reader.has_next():
    topic, message, timestamp = reader.read_next()
    message_type = get_message(type_map[topic])
    msg = deserialize_message (message, message_type)
    print (msg)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.