-
Notifications
You must be signed in to change notification settings - Fork 305
/clock publisher in Player #695
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2cb7131
Add /clock publishing to Player
a37da03
Add a test for clock publishing
5c36ca2
Fix linters
7a896d5
More flexible test for clock publishing
b23492b
Tweak test
131f19d
CLI optional freq for clock pub
3d1a94a
Move spinner out to rosbag2_transport
a2823fd
Loosen the tests for buildfarm windows
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
rosbag2_transport/test/rosbag2_transport/test_play_publish_clock.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| // Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include <gmock/gmock.h> | ||
|
|
||
| #include <memory> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| #include "rosbag2_transport/rosbag2_transport.hpp" | ||
| #include "rosgraph_msgs/msg/clock.hpp" | ||
| #include "test_msgs/message_fixtures.hpp" | ||
|
|
||
| #include "rosbag2_play_test_fixture.hpp" | ||
|
|
||
| using namespace ::testing; // NOLINT | ||
|
|
||
| namespace | ||
| { | ||
| rcutils_duration_value_t period_for_frequency(double frequency) | ||
| { | ||
| return static_cast<rcutils_duration_value_t>(RCUTILS_S_TO_NS(1) / frequency); | ||
| } | ||
| } // namespace | ||
|
|
||
| class ClockPublishFixture : public RosBag2PlayTestFixture | ||
| { | ||
| public: | ||
| ClockPublishFixture() | ||
| : RosBag2PlayTestFixture() | ||
| { | ||
| // Fake bag setup | ||
| auto topic_types = std::vector<rosbag2_storage::TopicMetadata>{ | ||
| {"topic1", "test_msgs/BasicTypes", "", ""}, | ||
| }; | ||
|
|
||
| std::vector<std::shared_ptr<rosbag2_storage::SerializedBagMessage>> messages; | ||
| for (size_t i = 0; i < messages_to_play_; i++) { | ||
| auto message = get_messages_basic_types()[0]; | ||
| message->int32_value = static_cast<int32_t>(i); | ||
| messages.push_back( | ||
| serialize_test_message("topic1", milliseconds_between_messages_ * i, message)); | ||
| } | ||
|
|
||
| // Player setup | ||
| auto prepared_mock_reader = std::make_unique<MockSequentialReader>(); | ||
| prepared_mock_reader->prepare(messages, topic_types); | ||
| reader_ = std::make_unique<rosbag2_cpp::Reader>(std::move(prepared_mock_reader)); | ||
|
|
||
| sub_->add_subscription<rosgraph_msgs::msg::Clock>( | ||
| "/clock", expected_clock_messages_, rclcpp::ClockQoS()); | ||
| } | ||
|
|
||
| void run_test() | ||
| { | ||
| auto await_received_messages = sub_->spin_subscriptions(); | ||
| rosbag2_transport::Rosbag2Transport rosbag2_transport(reader_, writer_); | ||
| rosbag2_transport.play(storage_options_, play_options_); | ||
| await_received_messages.get(); | ||
|
|
||
| // Check that we got enough messages | ||
| auto received_clock = sub_->get_received_messages<rosgraph_msgs::msg::Clock>("/clock"); | ||
| EXPECT_THAT(received_clock, SizeIs(Ge(expected_clock_messages_))); | ||
|
|
||
| // Check time deltas between messages | ||
| const auto expect_clock_delta = | ||
| period_for_frequency(play_options_.clock_publish_frequency) * play_options_.rate; | ||
| const auto allowed_error = static_cast<rcutils_duration_value_t>( | ||
| expect_clock_delta * error_tolerance_); | ||
| // On Windows, publishing seems to take time to "warm up", ignore the first couple messages | ||
| const auto start_message = 2; | ||
| for (size_t i = start_message; i < expected_clock_messages_ - 1; i++) { | ||
| auto current = rclcpp::Time(received_clock[i]->clock).nanoseconds(); | ||
| auto next = rclcpp::Time(received_clock[i + 1]->clock).nanoseconds(); | ||
| auto delta = next - current; | ||
| auto error = std::abs(delta - expect_clock_delta); | ||
| EXPECT_LE(error, allowed_error) << "Message was too far from next: " << i; | ||
| } | ||
| } | ||
|
|
||
| // Number of bag messages to publish | ||
| size_t messages_to_play_ = 10; | ||
| const int64_t milliseconds_between_messages_ = 50; | ||
|
|
||
| // Amount of error allowed between expected and actual clock deltas (expected to be much smaller) | ||
| const double error_tolerance_ = 0.3; | ||
|
|
||
| // Wait for just a few clock messages, we're checking the time between them, not the total count | ||
| size_t expected_clock_messages_ = 6; | ||
| }; | ||
|
|
||
| TEST_F(ClockPublishFixture, clock_is_published_at_chosen_frequency) | ||
| { | ||
| play_options_.clock_publish_frequency = 20; | ||
| run_test(); | ||
| } | ||
|
|
||
| TEST_F(ClockPublishFixture, clock_respects_playback_rate) | ||
| { | ||
| play_options_.clock_publish_frequency = 20; | ||
| play_options_.rate = 0.5; | ||
| messages_to_play_ = 5; | ||
| run_test(); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.