Skip to content

Commit cc46d2c

Browse files
committed
fix ros reader
1 parent 3891156 commit cc46d2c

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

python/vbr_devkit/datasets/ros.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ def __init__(self, data_dir: Union[Path, Sequence[Path]], topics: List[str] = No
2323
print("rosbags library not installed, run 'pip install -U rosbags'")
2424
sys.exit(-1)
2525

26-
if isinstance(data_dir, Path):
27-
self.sequence_id = os.path.basename(data_dir).split(".")[0]
26+
if data_dir.is_file():
27+
#self.sequence_id = os.path.basename(data_dir).split(".")[0]
2828
self.bag = AnyReader([data_dir])
2929
else:
30-
self.sequence_id = os.path.basename(data_dir[0]).split(".")[0]
31-
self.bag = AnyReader(data_dir)
30+
#self.sequence_id = os.path.basename(data_dir[0]).split(".")[0]
31+
self.bag = AnyReader(natsort.natsorted([bag for bag in list(data_dir.glob("*.bag"))]))
3232
print("Reading multiple .bag files in directory:")
33-
print("\n".join(natsort.natsorted([path.name for path in self.bag.paths])))
33+
print("\n".join([path.name for path in self.bag.paths]))
3434

3535
self.bag.open()
3636
connections = self.bag.connections

python/vbr_devkit/tools/run.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,19 @@ def convert(to: Annotated[OutputDataInterface, typer.Argument(help="Desired data
6464
Path, typer.Argument(help="Output directory in which the data will be stored", show_default=False)],
6565
) -> None:
6666
console.print(f"Converting {input_dir} to {to} format at {output_dir}")
67-
with RosReader(input_dir) as reader:
68-
with OutputDataInterface_lut[to](output_dir) as writer:
69-
for timestamp, topic, message in track(reader, description="Processing..."):
70-
writer.publish(timestamp, topic, message)
67+
if to == OutputDataInterface.ros2:
68+
if not input_dir.is_dir():
69+
print("Processing...")
70+
convert.convert(input_dir, output_dir / input_dir.stem)
71+
else:
72+
for item in track(list(input_dir.iterdir()), description="Processing..."):
73+
if item.suffix == '.bag':
74+
convert.convert(item, output_dir / item.stem)
75+
else:
76+
with RosReader(input_dir) as reader:
77+
with OutputDataInterface_lut[to](output_dir) as writer:
78+
for timestamp, topic, message in track(reader, description="Processing..."):
79+
writer.publish(timestamp, topic, message)
7180
console.print(":tada: Completed")
7281

7382

0 commit comments

Comments
 (0)