Skip to content

Commit

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

* 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

* Address merge conflicts

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 fd22add commit df64ec4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
11 changes: 11 additions & 0 deletions ros2bag/ros2bag/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,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
4 changes: 2 additions & 2 deletions ros2bag/ros2bag/verb/burst.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

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
from ros2bag.api import print_error
from ros2bag.verb import VerbExtension
Expand Down Expand Up @@ -55,7 +55,7 @@ def add_arguments(self, parser, cli_name): # noqa: D102
help='Path to a yaml file defining storage specific configurations. '
'See storage plugin documentation for the format of this file.')
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(
'-n', '--num-messages', type=check_not_negative_int, default=0,
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 @@ -126,7 +127,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 df64ec4

Please sign in to comment.