Skip to content

Commit

Permalink
[humble] Allow to specify start offset from CLI arguments equal to 0.…
Browse files Browse the repository at this point in the history
…0 for the rosbag2 player (backport #1682) (#1715)

* fix(start-offset): allow specifying a start offset of 0 (#1682)

Signed-off-by: Rein Appeldoorn <[email protected]>
(cherry picked from commit 8297cb0)

# Conflicts:
#	ros2bag/ros2bag/verb/burst.py

* Resolve merge conflicts. Delete "burst.py". Humble doesn't have it.

Signed-off-by: Michael Orlov <[email protected]>

---------

Signed-off-by: Michael Orlov <[email protected]>
Co-authored-by: Rein Appeldoorn <[email protected]>
Co-authored-by: Michael Orlov <[email protected]>
  • Loading branch information
3 people authored Jun 13, 2024
1 parent b2277fa commit 579fddf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions ros2bag/ros2bag/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ def check_positive_float(value: Any) -> float:
raise ArgumentTypeError('{} is not the valid type (float)'.format(value))


def check_not_negative_float(value: Any) -> float:
"""Argparse validator to verify that a value is a float and that not negative."""
try:
fvalue = float(value)
if fvalue < 0.0:
raise ArgumentTypeError(f'Value {value} is less than zero.')
return fvalue
except ValueError:
raise ArgumentTypeError('{} is not the valid type (float)'.format(value))


def check_path_exists(value: Any) -> str:
"""Argparse validator to verify a path exists."""
try:
Expand Down
3 changes: 2 additions & 1 deletion ros2bag/ros2bag/verb/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from rclpy.qos import InvalidQoSProfileException
from ros2bag.api import add_standard_reader_args
from ros2bag.api import check_not_negative_float
from ros2bag.api import check_not_negative_int
from ros2bag.api import check_positive_float
from ros2bag.api import convert_yaml_to_qos_profile
Expand Down Expand Up @@ -85,7 +86,7 @@ def add_arguments(self, parser, cli_name): # noqa: D102
'-p', '--start-paused', action='store_true', default=False,
help='Start the playback player in a paused state.')
parser.add_argument(
'--start-offset', type=check_positive_float, default=0.0,
'--start-offset', type=check_not_negative_float, default=0.0,
help='Start the playback player this many seconds into the bag file.')
parser.add_argument(
'--wait-for-all-acked', type=check_not_negative_int, default=-1,
Expand Down

0 comments on commit 579fddf

Please sign in to comment.