From 3a37151e7b8662db52a9c93a65056aa0cd4a115b Mon Sep 17 00:00:00 2001 From: Max SCHMELLER Date: Fri, 28 Jun 2024 15:57:06 +0900 Subject: [PATCH] chore(hesai): fix clang-tidy errors --- .../hesai_cmd_response.hpp | 8 +++---- .../hesai_hw_interface.hpp | 4 ++-- .../hesai_hw_interface.cpp | 15 +++++------- nebula_ros/src/hesai/hesai_ros_wrapper.cpp | 23 ++++++++++++++++++- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/nebula_hw_interfaces/include/nebula_hw_interfaces/nebula_hw_interfaces_hesai/hesai_cmd_response.hpp b/nebula_hw_interfaces/include/nebula_hw_interfaces/nebula_hw_interfaces_hesai/hesai_cmd_response.hpp index 54e757224..f3bb7b073 100644 --- a/nebula_hw_interfaces/include/nebula_hw_interfaces/nebula_hw_interfaces_hesai/hesai_cmd_response.hpp +++ b/nebula_hw_interfaces/include/nebula_hw_interfaces/nebula_hw_interfaces_hesai/hesai_cmd_response.hpp @@ -218,7 +218,7 @@ struct HesaiInventory return os; } - std::string get_str_model() + std::string get_str_model() const { switch (model) { case 0: @@ -400,7 +400,7 @@ struct HesaiLidarStatus return os; } - std::string get_str_gps_pps_lock() + [[nodiscard]] std::string get_str_gps_pps_lock() const { switch (gps_pps_lock) { case 1: @@ -411,7 +411,7 @@ struct HesaiLidarStatus return "Unknown"; } } - std::string get_str_gps_gprmc_status() + [[nodiscard]] std::string get_str_gps_gprmc_status() const { switch (gps_gprmc_status) { case 1: @@ -422,7 +422,7 @@ struct HesaiLidarStatus return "Unknown"; } } - std::string get_str_ptp_clock_status() + [[nodiscard]] std::string get_str_ptp_clock_status() const { switch (ptp_clock_status) { case 0: diff --git a/nebula_hw_interfaces/include/nebula_hw_interfaces/nebula_hw_interfaces_hesai/hesai_hw_interface.hpp b/nebula_hw_interfaces/include/nebula_hw_interfaces/nebula_hw_interfaces_hesai/hesai_hw_interface.hpp index 668469b2e..a029ae224 100644 --- a/nebula_hw_interfaces/include/nebula_hw_interfaces/nebula_hw_interfaces_hesai/hesai_hw_interface.hpp +++ b/nebula_hw_interfaces/include/nebula_hw_interfaces/nebula_hw_interfaces_hesai/hesai_hw_interface.hpp @@ -122,10 +122,10 @@ class HesaiHwInterface uint8_t error_flags = 0; uint8_t ptc_error_code = 0; - bool ok() { return !error_flags && !ptc_error_code; } + [[nodiscard]] bool ok() const { return !error_flags && !ptc_error_code; } }; - typedef nebula::util::expected, ptc_error_t> ptc_cmd_result_t; + using ptc_cmd_result_t = nebula::util::expected, ptc_error_t>; std::unique_ptr<::drivers::common::IoContext> cloud_io_context_; std::shared_ptr m_owned_ctx; diff --git a/nebula_hw_interfaces/src/nebula_hesai_hw_interfaces/hesai_hw_interface.cpp b/nebula_hw_interfaces/src/nebula_hesai_hw_interfaces/hesai_hw_interface.cpp index 06dcb37dc..2bdaf3e6e 100644 --- a/nebula_hw_interfaces/src/nebula_hesai_hw_interfaces/hesai_hw_interface.cpp +++ b/nebula_hw_interfaces/src/nebula_hesai_hw_interfaces/hesai_hw_interface.cpp @@ -11,9 +11,7 @@ #include -namespace nebula -{ -namespace drivers +namespace nebula::drivers { HesaiHwInterface::HesaiHwInterface() : cloud_io_context_{new ::drivers::common::IoContext(1)}, @@ -1266,16 +1264,16 @@ std::string HesaiHwInterface::PrettyPrintPTCError(ptc_error_t error_code) std::vector nebula_errors; if (error_flags & TCP_ERROR_INCOMPLETE_RESPONSE) { - nebula_errors.push_back("Incomplete response payload"); + nebula_errors.emplace_back("Incomplete response payload"); } if (error_flags & TCP_ERROR_TIMEOUT) { - nebula_errors.push_back("Request timeout"); + nebula_errors.emplace_back("Request timeout"); } if (error_flags & TCP_ERROR_UNEXPECTED_PAYLOAD) { - nebula_errors.push_back("Received payload but expected payload length 0"); + nebula_errors.emplace_back("Received payload but expected payload length 0"); } if (error_flags & TCP_ERROR_UNRELATED_RESPONSE) { - nebula_errors.push_back("Received unrelated response"); + nebula_errors.emplace_back("Received unrelated response"); } ss << boost::algorithm::join(nebula_errors, ", "); @@ -1297,5 +1295,4 @@ T HesaiHwInterface::CheckSizeAndParse(const std::vector & data) return parsed; } -} // namespace drivers -} // namespace nebula +} // namespace nebula::drivers diff --git a/nebula_ros/src/hesai/hesai_ros_wrapper.cpp b/nebula_ros/src/hesai/hesai_ros_wrapper.cpp index 279b5bb3b..a96398cf1 100644 --- a/nebula_ros/src/hesai/hesai_ros_wrapper.cpp +++ b/nebula_ros/src/hesai/hesai_ros_wrapper.cpp @@ -17,6 +17,8 @@ namespace nebula { namespace ros { +using std::get; + HesaiRosWrapper::HesaiRosWrapper(const rclcpp::NodeOptions & options) : rclcpp::Node("hesai_ros_wrapper", rclcpp::NodeOptions(options).use_intra_process_comms(true)), wrapper_status_(Status::NOT_INITIALIZED), @@ -50,6 +52,25 @@ HesaiRosWrapper::HesaiRosWrapper(const rclcpp::NodeOptions & options) (std::stringstream() << "No valid calibration found: " << calibration_result.error()).str()); } + if (hw_interface_wrapper_) { + auto cloud_min = sensor_cfg_ptr_->cloud_min_angle / 10.f; + auto cloud_max = sensor_cfg_ptr_->cloud_max_angle / 10.f; + + auto padding = calibration_result.value()->getFovPadding(); + cloud_min += get<0>(padding); + cloud_max += get<1>(padding); + + if (cloud_min < 0) { + cloud_min += 360; + } + + if (cloud_max > 360) { + cloud_max -= 360; + } + + hw_interface_wrapper_->HwInterface()->setHardwareFov(cloud_min, cloud_max); + } + decoder_wrapper_.emplace(this, sensor_cfg_ptr_, calibration_result.value()); RCLCPP_DEBUG(get_logger(), "Starting stream"); @@ -394,7 +415,7 @@ HesaiRosWrapper::get_calibration_result_t HesaiRosWrapper::GetCalibrationData( } // If a sensor is connected, try to download and save its calibration data - if (!ignore_others && launch_hw_) { + if (!ignore_others && hw_interface_wrapper_) { try { auto raw_data = hw_interface_wrapper_->HwInterface()->GetLidarCalibrationBytes(); RCLCPP_INFO(logger, "Downloaded calibration data from sensor.");