def test_seek_forward(): bag_path = str(RESOURCES_PATH / 'wbag') storage_options, converter_options = get_rosbag_options(bag_path) reader = rosbag2_py.SequentialReader() reader.open(storage_options, converter_options) # seek forward reader.seek(1822) (topic, data, t) = reader.read_next() assert topic == 'CCC' assert t == 1822 # set filter continues in same location storage_filter = rosbag2_py.StorageFilter(topics=['BBB', 'GGG']) reader.set_filter(storage_filter) (topic, data, t) = reader.read_next() assert topic == 'GGG' assert t == 1822 (topic, data, t) = reader.read_next() assert topic == 'GGG' assert t == 1822 (topic, data, t) = reader.read_next() assert topic == 'BBB' assert t == 1826
def test_seek_backward(): bag_path = str(RESOURCES_PATH / 'wbag') storage_options, converter_options = get_rosbag_options(bag_path) reader = rosbag2_py.SequentialReader() reader.open(storage_options, converter_options) # seek forward first reader.seek(1822) storage_filter = rosbag2_py.StorageFilter(topics=['BBB', 'GGG']) reader.set_filter(storage_filter) (topic, data, t) = reader.read_next() # seek backwards & filter preserved reader.seek(1408) (topic, data, t) = reader.read_next() assert topic == 'BBB' assert t == 1408 (topic, data, t) = reader.read_next() assert topic == 'GGG' assert t == 1408 (topic, data, t) = reader.read_next() assert topic == 'BBB' assert t == 1413
def test_sequential_reader(): bag_path = str(Path(__file__).parent.parent / 'resources' / 'talker') storage_options, converter_options = get_rosbag_options(bag_path) reader = rosbag2_py.SequentialReader() reader.open(storage_options, converter_options) topic_types = reader.get_all_topics_and_types() # Create a map for quicker lookup type_map = { topic_types[i].name: topic_types[i].type for i in range(len(topic_types)) } # Set filter for topic of string type storage_filter = rosbag2_py.StorageFilter(topics=['/topic']) reader.set_filter(storage_filter) msg_counter = 0 while reader.has_next(): (topic, data, t) = reader.read_next() msg_type = get_message(type_map[topic]) msg = deserialize_message(data, msg_type) assert isinstance(msg, String) assert msg.data == f'Hello, world! {msg_counter}' msg_counter += 1 # No filter reader.reset_filter() reader = rosbag2_py.SequentialReader() reader.open(storage_options, converter_options) msg_counter = 0 while reader.has_next(): (topic, data, t) = reader.read_next() msg_type = get_message(type_map[topic]) msg = deserialize_message(data, msg_type) assert isinstance(msg, Log) or isinstance(msg, String) if isinstance(msg, String): assert msg.data == f'Hello, world! {msg_counter}' msg_counter += 1
def test_reset_filter(): bag_path = str(RESOURCES_PATH / 'wbag') storage_options, converter_options = get_rosbag_options(bag_path) reader = rosbag2_py.SequentialReader() reader.open(storage_options, converter_options) # Set filter for topic of string type storage_filter = rosbag2_py.StorageFilter(topics=['AAA', 'CCC', 'DDD']) reader.set_filter(storage_filter) (topic, data, t) = reader.read_next() assert topic == 'AAA' assert t == 1001 (topic, data, t) = reader.read_next() assert topic == 'CCC' assert t == 1002 (topic, data, t) = reader.read_next() assert topic == 'AAA' assert t == 1004 # No filter and bag continues same location reader.reset_filter() (topic, data, t) = reader.read_next() assert topic == 'FFF' assert t == 1004 (topic, data, t) = reader.read_next() assert topic == 'BBB' assert t == 1004 (topic, data, t) = reader.read_next() assert topic == 'EEE' assert t == 1005
def test_sequential_reader_seek(): bag_path = str(RESOURCES_PATH / 'talker') storage_options, converter_options = get_rosbag_options(bag_path) reader = rosbag2_py.SequentialReader() reader.open(storage_options, converter_options) topic_types = reader.get_all_topics_and_types() # Create a map for quicker lookup type_map = { topic_types[i].name: topic_types[i].type for i in range(len(topic_types)) } # Seek No Filter reader = rosbag2_py.SequentialReader() reader.open(storage_options, converter_options) reader.seek(1585866237113147888) msg_counter = 5 (topic, data, t) = reader.read_next() msg_type = get_message(type_map[topic]) msg = deserialize_message(data, msg_type) assert isinstance(msg, Log) (topic, data, t) = reader.read_next() msg_type = get_message(type_map[topic]) msg = deserialize_message(data, msg_type) isinstance(msg, String) assert msg.data == f'Hello, world! {msg_counter}' msg_counter += 1 # Set Filter will continue storage_filter = rosbag2_py.StorageFilter(topics=['/topic']) reader.set_filter(storage_filter) (topic, data, t) = reader.read_next() msg_type = get_message(type_map[topic]) msg = deserialize_message(data, msg_type) isinstance(msg, String) assert msg.data == f'Hello, world! {msg_counter}' # Seek will keep filter reader.seek(1585866239113147888) msg_counter = 8 (topic, data, t) = reader.read_next() msg_type = get_message(type_map[topic]) msg = deserialize_message(data, msg_type) isinstance(msg, String) assert msg.data == f'Hello, world! {msg_counter}' msg_counter += 1 (topic, data, t) = reader.read_next() msg_type = get_message(type_map[topic]) msg = deserialize_message(data, msg_type) isinstance(msg, String) assert msg.data == f'Hello, world! {msg_counter}'