-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add play-until functionality #962
Conversation
Signed-off-by: Geoffrey Biggs <[email protected]>
Signed-off-by: Geoffrey Biggs <[email protected]>
Signed-off-by: Geoffrey Biggs <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass!
"play", &rosbag2_py::Player::play, py::arg("storage_options"), py::arg( | ||
"play_options"), py::arg("duration") = std::nullopt) | ||
.def( | ||
"play_until", &rosbag2_py::Player::play, py::arg("storage_options"), py::arg( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gbiggs should be rosbag2_py::Player::play_until
instead?
"play_options"), py::arg("duration") = std::nullopt) | ||
.def( | ||
"play_until", &rosbag2_py::Player::play, py::arg("storage_options"), py::arg( | ||
"play_options"), py::arg("timestamp") = std::nullopt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gbiggs hmm, shouldn't timestamp
be mandatory for play_until()
?
const rcutils_duration_value_t duration = | ||
static_cast<rcutils_duration_value_t>(request->duration.sec) * | ||
static_cast<rcutils_duration_value_t>(1000000000) + | ||
static_cast<rcutils_duration_value_t>(request->duration.nanosec); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gbiggs nit: consider
const rcutils_duration_value_t duration = | |
static_cast<rcutils_duration_value_t>(request->duration.sec) * | |
static_cast<rcutils_duration_value_t>(1000000000) + | |
static_cast<rcutils_duration_value_t>(request->duration.nanosec); | |
const rcutils_duration_value_t duration = | |
rclcpp::Duration(request->duration).nanoseconds(); |
const rcutils_time_point_value_t timestamp = | ||
static_cast<rcutils_time_point_value_t>(request->time.sec) * | ||
static_cast<rcutils_time_point_value_t>(1000000000) + | ||
static_cast<rcutils_time_point_value_t>(request->time.nanosec); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gbiggs nit: consider
const rcutils_time_point_value_t timestamp = | |
static_cast<rcutils_time_point_value_t>(request->time.sec) * | |
static_cast<rcutils_time_point_value_t>(1000000000) + | |
static_cast<rcutils_time_point_value_t>(request->time.nanosec); | |
const rcutils_time_point_value_t timestamp = | |
rclcpp::Time(request->time).nanoseconds(); |
// Do not move on until sleep_until returns true | ||
// It will always sleep, so this is not a tight busy loop on pause |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gbiggs this should probably be relocated after the next if
clause and before the while
loop.
std::move( | ||
reader), storage_options_, play_options_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gbiggs nit: can we collapse this two lines into one?
{ | ||
auto await_received_messages = sub_->spin_subscriptions(); | ||
|
||
player_->play(std::chrono::nanoseconds(std::chrono::milliseconds(1000)).count()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gbiggs fyi: you could also do
player_->play(std::chrono::nanoseconds(std::chrono::milliseconds(1000)).count()); | |
player_->play(RCUTILS_MS_TO_NS(1000)); |
or equivalently
player_->play(std::chrono::nanoseconds(std::chrono::milliseconds(1000)).count()); | |
player_->play(RCUTILS_S_TO_NS(1)); |
Same everywhere else.
auto replayed_test_primitives = sub_->get_received_messages<test_msgs::msg::BasicTypes>( | ||
kTopic1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gbiggs nit:
auto replayed_test_primitives = sub_->get_received_messages<test_msgs::msg::BasicTypes>( | |
kTopic1); | |
auto replayed_test_primitives = | |
sub_->get_received_messages<test_msgs::msg::BasicTypes>(kTopic1); |
Same elsewhere.
std::future<void> await_received_messages_; | ||
}; | ||
|
||
TEST_F(RosBag2PlayForTestFixture, play_for_all_are_played_due_to_duration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gbiggs nit^N: test case names read a bit awkward. For instance, how about play_for_a_long_duration_publishes_some
here?
EXPECT_THAT(replayed_test_primitives, SizeIs(0u)); | ||
|
||
auto replayed_test_arrays = sub_->get_received_messages<test_msgs::msg::Arrays>("/topic2"); | ||
// All messages should have arrived. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gbiggs leftover?
Before proceeding to fix this PR, I'd like to know your preference on the implementation @MichaelOrlov and @hidmic . We proposed and discussed this in the meeting group on 2021-05-21. The feature request changed a bit to be: "play until timepoint" rather than "play until next message of topic T" since then. Also, we needed to have this functionality in another rosbag2 fork first that should be compliant with foxy. As a consequence, this patch looks so odd at first (likewise to #960 at first). We aimed for API compatibility or minimal changes across ros2 releases. That said, we are eager to push to get these changes in before the code freeze (as everyone else contributing :)) and hoping you could make some time to guide us to get these changes in. Looking forward to hearing your thoughts. |
@agalbachicar @gbiggs I think you will need to rebase first and rework this PR since we already have |
Closing in favour of #1005 |
* Implements play until on top of play for. Signed-off-by: Agustin Alba Chicar <[email protected]> * Adds python bindings Signed-off-by: Agustin Alba Chicar <[email protected]> * Adds test for play until. Signed-off-by: Agustin Alba Chicar <[email protected]> * Fixes variable name. Signed-off-by: Agustin Alba Chicar <[email protected]> * Adds the same docstring for play_until and play_duration options than in PlayOptions to clarify usage. Signed-off-by: Agustin Alba Chicar <[email protected]> * Updates the CLI to combine the seconds and nanoseconds part of the playback_until stamp Signed-off-by: Agustin Alba Chicar <[email protected]> * Changes to play verb parameters: - Unifies the use of '-' instead of '_' to split words in arguments. - Uses mutually exclusive arguments: --playback-until-sec and --playback-until-nsec to pass the timestamp. Signed-off-by: Agustin Alba Chicar <[email protected]> * Solves review comments. - Adds test cases to the player. - Renames play_until and similar occurrences to contain timestamp. - Renames play_for and similar occurrences to not contain for and include duration. Signed-off-by: Agustin Alba Chicar <[email protected]> * Solves review comments to tests. Signed-off-by: Agustin Alba Chicar <[email protected]> * Modifies play_until_is_equal_to_the_total_duration The test body now evaluates a bag whose duration is exactly the same as given timestamp in PlayOptions. Signed-off-by: Agustin Alba Chicar <[email protected]>
This PR adds the ability to play until a given timestamp.
This work was co-authored by @agalbachicar.
This PR requires #960 to be merged first (at which point it will probably need to be rebased).