Skip to content

Commit

Permalink
fix ros reader
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoBrizi committed Jun 6, 2024
1 parent 3891156 commit cc46d2c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
10 changes: 5 additions & 5 deletions python/vbr_devkit/datasets/ros.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ def __init__(self, data_dir: Union[Path, Sequence[Path]], topics: List[str] = No
print("rosbags library not installed, run 'pip install -U rosbags'")
sys.exit(-1)

if isinstance(data_dir, Path):
self.sequence_id = os.path.basename(data_dir).split(".")[0]
if data_dir.is_file():
#self.sequence_id = os.path.basename(data_dir).split(".")[0]
self.bag = AnyReader([data_dir])
else:
self.sequence_id = os.path.basename(data_dir[0]).split(".")[0]
self.bag = AnyReader(data_dir)
#self.sequence_id = os.path.basename(data_dir[0]).split(".")[0]
self.bag = AnyReader(natsort.natsorted([bag for bag in list(data_dir.glob("*.bag"))]))
print("Reading multiple .bag files in directory:")
print("\n".join(natsort.natsorted([path.name for path in self.bag.paths])))
print("\n".join([path.name for path in self.bag.paths]))

self.bag.open()
connections = self.bag.connections
Expand Down
17 changes: 13 additions & 4 deletions python/vbr_devkit/tools/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,19 @@ def convert(to: Annotated[OutputDataInterface, typer.Argument(help="Desired data
Path, typer.Argument(help="Output directory in which the data will be stored", show_default=False)],
) -> None:
console.print(f"Converting {input_dir} to {to} format at {output_dir}")
with RosReader(input_dir) as reader:
with OutputDataInterface_lut[to](output_dir) as writer:
for timestamp, topic, message in track(reader, description="Processing..."):
writer.publish(timestamp, topic, message)
if to == OutputDataInterface.ros2:
if not input_dir.is_dir():
print("Processing...")
convert.convert(input_dir, output_dir / input_dir.stem)
else:
for item in track(list(input_dir.iterdir()), description="Processing..."):
if item.suffix == '.bag':
convert.convert(item, output_dir / item.stem)
else:
with RosReader(input_dir) as reader:
with OutputDataInterface_lut[to](output_dir) as writer:
for timestamp, topic, message in track(reader, description="Processing..."):
writer.publish(timestamp, topic, message)
console.print(":tada: Completed")


Expand Down

0 comments on commit cc46d2c

Please sign in to comment.