[service] add set_threshold_filter_enable

This commit is contained in:
zhuangzi
2025-01-17 16:38:42 +08:00
parent 3937f4f26a
commit a28040e7ad
2 changed files with 43 additions and 0 deletions
@@ -302,6 +302,9 @@ class OBCameraNode {
void setSequenceIdFilterEnableCallback(
const std::shared_ptr<std_srvs::srv::SetBool::Request>& request,
std::shared_ptr<std_srvs::srv::SetBool::Response>& response);
void setThresholdFilterEnableCallback(
const std::shared_ptr<std_srvs::srv::SetBool::Request>& request,
std::shared_ptr<std_srvs::srv::SetBool::Response>& response);
bool toggleSensor(const stream_index_pair& stream_index, bool enabled, std::string& msg);
@@ -458,6 +461,7 @@ class OBCameraNode {
rclcpp::Service<std_srvs::srv::SetBool>::SharedPtr set_sync_host_time_srv_;
rclcpp::Service<std_srvs::srv::SetBool>::SharedPtr set_decimation_filter_enable_srv_;
rclcpp::Service<std_srvs::srv::SetBool>::SharedPtr set_sequence_id_filter_enable_srv_;
rclcpp::Service<std_srvs::srv::SetBool>::SharedPtr set_threshold_filter_enable_srv_;
bool enable_sync_output_accel_gyro_ = false;
bool publish_tf_ = false;
+39
View File
@@ -194,6 +194,11 @@ void OBCameraNode::setupCameraCtrlServices() {
std::shared_ptr<SetBool::Response> response) {
setSequenceIdFilterEnableCallback(request, response);
});
set_threshold_filter_enable_srv_ = node_->create_service<SetBool>(
"set_threshold_filter_enable", [this](const std::shared_ptr<SetBool::Request> request,
std::shared_ptr<SetBool::Response> response) {
setThresholdFilterEnableCallback(request, response);
});
}
void OBCameraNode::setExposureCallback(const std::shared_ptr<SetInt32::Request>& request,
@@ -905,4 +910,38 @@ void OBCameraNode::setSequenceIdFilterEnableCallback(
response->success = false;
}
}
void OBCameraNode::setThresholdFilterEnableCallback(
const std::shared_ptr<std_srvs::srv::SetBool::Request>& request,
std::shared_ptr<std_srvs::srv::SetBool::Response>& response) {
try {
enable_threshold_filter_ = request->data;
if (enable_threshold_filter_) {
threshold_filter_max_ = node_->get_parameter("threshold_filter_max").as_int();
threshold_filter_min_ = node_->get_parameter("threshold_filter_min").as_int();
if (threshold_filter_max_ == -1 || threshold_filter_min_ == -1) {
RCLCPP_WARN(
logger_,
"Please configure the parameter 'threshold_filter_max' and 'threshold_filter_min'");
return;
}
} else {
threshold_filter_max_ = -1;
threshold_filter_min_ = -1;
node_->set_parameter(rclcpp::Parameter("threshold_filter_max", threshold_filter_max_));
node_->set_parameter(rclcpp::Parameter("threshold_filter_min", threshold_filter_min_));
}
setupDepthPostProcessFilter();
node_->set_parameter(rclcpp::Parameter("enable_threshold_filter", enable_threshold_filter_));
response->success = true;
} catch (const ob::Error& e) {
response->message = e.getMessage();
response->success = false;
} catch (const std::exception& e) {
response->message = e.what();
response->success = false;
} catch (...) {
response->message = "unknown error";
response->success = false;
}
}
} // namespace orbbec_camera