-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement Triggered Calibration action
- Loading branch information
1 parent
f688fba
commit 453ada5
Showing
8 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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,61 @@ | ||
#include "../include/base_realsense_node.h" | ||
using namespace realsense2_camera; | ||
using namespace rs2; | ||
|
||
rclcpp_action::GoalResponse BaseRealSenseNode::TriggeredCalibrationHandleGoal(const rclcpp_action::GoalUUID & uuid, | ||
std::shared_ptr<const TriggeredCalibration::Goal> goal) | ||
{ | ||
(void)uuid; // unused parameter | ||
ROS_INFO_STREAM("TriggeredCalibrationAction: Received request with json " << goal->json); | ||
return rclcpp_action::GoalResponse::ACCEPT_AND_EXECUTE; | ||
} | ||
|
||
rclcpp_action::CancelResponse BaseRealSenseNode::TriggeredCalibrationHandleCancel(const std::shared_ptr<GoalHandleTriggeredCalibration> goal_handle) | ||
{ | ||
(void)goal_handle; // unused parameter | ||
ROS_INFO("TriggeredCalibrationAction: Received request to cancel"); | ||
return rclcpp_action::CancelResponse::ACCEPT; | ||
} | ||
|
||
void BaseRealSenseNode::TriggeredCalibrationHandleAccepted(const std::shared_ptr<GoalHandleTriggeredCalibration> goal_handle) | ||
{ | ||
using namespace std::placeholders; | ||
ROS_INFO("TriggeredCalibrationAction: Request accepted"); | ||
// this needs to return quickly to avoid blocking the executor, so spin up a new thread | ||
std::thread{std::bind(&BaseRealSenseNode::TriggeredCalibrationExecute, this, _1), goal_handle}.detach(); | ||
} | ||
|
||
void BaseRealSenseNode::TriggeredCalibrationExecute(const std::shared_ptr<GoalHandleTriggeredCalibration> goal_handle) | ||
{ | ||
ROS_INFO("TriggeredCalibrationAction: Executing..."); | ||
|
||
const auto goal = goal_handle->get_goal(); // get the TriggeredCalibration srv struct | ||
auto feedback = std::make_shared<TriggeredCalibration::Feedback>(); | ||
float & _progress = feedback->progress; | ||
auto result = std::make_shared<TriggeredCalibration::Result>(); | ||
|
||
rs2::auto_calibrated_device ac_dev = _dev.as<auto_calibrated_device>(); | ||
float health = 0.f; | ||
int timeout_ms = 120000; // 2 minutes | ||
auto ans = ac_dev.run_on_chip_calibration(goal->json, | ||
&health, | ||
[&](const float progress) {_progress = progress; }, | ||
timeout_ms); | ||
|
||
rs2::calibration_table new_calib = std::vector<uint8_t>(ans.begin() + 3, ans.end()); | ||
|
||
if (rclcpp::ok() && _progress == 100.0) | ||
{ | ||
result->calibration = vectorToJsonString(new_calib); | ||
result->health = health; | ||
goal_handle->succeed(result); | ||
ROS_DEBUG("TriggeredCalibrationExecute: Goal succeeded"); | ||
} | ||
else | ||
{ | ||
// exception must have been thrown from run_on_chip_calibration call | ||
result->calibration = ""; | ||
goal_handle->canceled(result); | ||
ROS_WARN("TriggeredCalibrationExecute: Goal failed"); | ||
} | ||
} |
This file contains 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 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 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 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,9 @@ | ||
# request | ||
string json "calib run" | ||
--- | ||
# result | ||
string calibration | ||
float32 health | ||
--- | ||
# feedback | ||
float32 progress |