-
Notifications
You must be signed in to change notification settings - Fork 292
Add Record, Stop, StartDiscovery, StopDiscovery and IsDiscoveryRunning services for Recorder #2248
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
base: rolling
Are you sure you want to change the base?
Conversation
|
@ros-pull-request-builder retest this please |
|
@christophebedard @fujitatomoya Friendly ping here for review. Or maybe @ahcorde or @Barry-Xu-2018 some of you can review this PR? |
Barry-Xu-2018
left a comment
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.
LGTM.
I have a small question.
In RecorderImpl::stop(), in_recording_ is set to false only after the stop processing is completed.
rosbag2/rosbag2_transport/src/rosbag2_transport/recorder.cpp
Lines 321 to 334 in a8b9c82
| void RecorderImpl::stop() | |
| { | |
| std::lock_guard<std::mutex> state_lock(start_stop_transition_mutex_); | |
| if (!in_recording_) { | |
| RCLCPP_DEBUG(node->get_logger(), "Recording has already been stopped or not running."); | |
| return; | |
| } | |
| stop_discovery(); | |
| pause(); | |
| subscriptions_.clear(); | |
| writer_->close(); // Call writer->close() to finalize current bag file and write metadata | |
| in_recording_ = false; |
In RecorderImpl::record(), in_recording_ is set to true before record processing is complete.
rosbag2/rosbag2_transport/src/rosbag2_transport/recorder.cpp
Lines 353 to 356 in a8b9c82
| void RecorderImpl::record(const std::string & uri) | |
| { | |
| std::lock_guard<std::mutex> state_lock(start_stop_transition_mutex_); | |
| if (in_recording_.exchange(true)) { |
In RecorderImpl::stop(), is it possible to set in_recording_ to false before stop processing is started ? (I'm not sure if there were any specific considerations for current implementation.)
Considering that there is some processing time between when RecorderImpl::stop() is called and when in_recording_ is set to false, if a service callback is invoked during this period, the first check of in_recording_ would be meaningless.
srv_stop_ = node->create_service<rosbag2_interfaces::srv::Stop>(
"~/stop",
[this](
const std::shared_ptr<rmw_request_id_t>/* request_header */,
const std::shared_ptr<rosbag2_interfaces::srv::Stop::Request>/* request */,
const std::shared_ptr<rosbag2_interfaces::srv::Stop::Response>/* response */)
{
if (!in_recording_) {
RCLCPP_WARN(node->get_logger(),
"Received Stop request while not in recording. Ignoring request.");
} else {
try {
this->stop();
} catch (const std::exception & e) {
RCLCPP_ERROR(node->get_logger(), "Error during Stop request: %s", e.what());
}
}
}
);|
@Barry-Xu-2018, good question and catch-up. rosbag2/rosbag2_transport/src/rosbag2_transport/recorder.cpp Lines 353 to 356 in a8b9c82
You are right, we shall set I made a fix in my last 0b2e478 commit |
|
@christophebedard @fujitatomoya @ahcorde This PR was reviewed, and findings were addressed. Can some of you formally approve this PR or review it additionally? |
|
Pulls: #2248 |
Signed-off-by: Michael Orlov <[email protected]>
Signed-off-by: Michael Orlov <[email protected]>
Signed-off-by: Michael Orlov <[email protected]>
- Rationale: We use in_recording_ check in service calls, therefore the recorder and all its underlying data types shall be fully initialized and ready before we set this flag to true. Signed-off-by: Michael Orlov <[email protected]>
Signed-off-by: Michael Orlov <[email protected]>
2978286 to
06e26d2
Compare
|
Made a rebase and resolved conflicts. |
|
@ahcorde @fujitatomoya A friendly ping for a formal approval or additional review here. |
|
Re-run CI after rebase and fixing conflicts |
fujitatomoya
left a comment
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.
just a few minor comments. overall lgtm with all comments are resolved.
| --- | ||
| # True if discovery is running, false otherwise | ||
| bool running | ||
|
|
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.
(this comment does not block the PR)
although i understand there is already ~/is_paused as a service (this is consistent for the current implementation), i would use a read only parameter instead here. this is purely a state query with no side effects, and i believe exactly what parameters are designed for. in this way, we can reduce service endpoint to take advantage of internal parameter service.
| const std::shared_ptr<rosbag2_interfaces::srv::Record::Request> request, | ||
| const std::shared_ptr<rosbag2_interfaces::srv::Record::Response> response) | ||
| { | ||
| if (in_recording_) { |
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.
are we missing mutex here?
| if (in_recording_) { | |
| std::lock_guard<std::mutex> state_lock(start_stop_transition_mutex_); | |
| if (in_recording_) { |
| const std::shared_ptr<rosbag2_interfaces::srv::Stop::Request>/* request */, | ||
| const std::shared_ptr<rosbag2_interfaces::srv::Stop::Response>/* response */) | ||
| { | ||
| if (!in_recording_) { |
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.
same here?
| if (!in_recording_) { | |
| std::lock_guard<std::mutex> state_lock(start_stop_transition_mutex_); | |
| if (!in_recording_) { |
| try { | ||
| this->stop(); | ||
| } catch (const std::exception & e) { | ||
| RCLCPP_ERROR(node->get_logger(), "Error during Stop request: %s", e.what()); |
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.
probably we can consider adding return_code/error_string to the Stop response for consistency with other services? errors are only logged, not returned to the caller.
| #include <algorithm> | ||
| #include <chrono> | ||
| #include <cstdint> | ||
| #include <condition_variable> |
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.
is this required to add? doesn't appear to be used.
Description
This PR is a replacement for the stale PR #1840 and adds the following services to the
rosbag2_transport::RecorderRecord
Stop
StartDiscovery
StopDiscovery
IsDiscoveryRunning
Fixes Add record, stop, start_discovery and stop_discovery services for rosbag2_transport::Recorder #1634
Relates #[FEA] Support distributed recording to get ultra high performance. #1548
Is this user-facing behavior change?
Yes. The user will have the ability to manage the Rosbag2 recorder instance remotely via the service calls.
Did you use Generative AI?
Yes. I am using GitHub Copilot, GPT-5.0, mostly to help me with tests and Doxygen comments.
Additional Information
No APi/ABI breaking changes -> can be backported