Skip to content

Commit af69ecd

Browse files
committed
WIP
1 parent 2717ab1 commit af69ecd

File tree

4 files changed

+46
-20
lines changed

4 files changed

+46
-20
lines changed

nebula_hw_interfaces/include/nebula_hw_interfaces/nebula_hw_interfaces_hesai/hesai_cmd_response.hpp

+17-17
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,9 @@ struct HesaiLidarStatus
354354
big_uint32_buf_t system_uptime;
355355
big_uint16_buf_t motor_speed;
356356
big_int32_buf_t temperature[8];
357-
uint8_t gps_pps_lock;
358-
uint8_t gps_gprmc_status;
359-
big_uint32_buf_t startup_times;
357+
uint8_t gps_pps_lock;//wrong
358+
uint8_t gps_gprmc_status;//wrong
359+
big_uint32_buf_t startup_times;//wrong
360360
big_uint32_buf_t total_operation_time;
361361
uint8_t ptp_clock_status;
362362
uint8_t reserved[5]; // FIXME: 4 bytes labeled as humidity in OT128 datasheet
@@ -528,22 +528,22 @@ struct HesaiLidarMonitor
528528

529529
struct HesaiFaultModeInfo
530530
{
531-
char work_mode;
532-
char fault_code[4];
531+
uint8_t work_mode;
532+
uint8_t fault_code;
533533

534534
[[nodiscard]] std::string describeWorkMode() const
535535
{
536-
std::string prefix = std::string(&work_mode, 1) + " - ";
536+
std::string prefix = std::to_string(work_mode) + " - ";
537537
switch (work_mode) {
538-
case '0':
538+
case 0:
539539
return prefix + "Energy-Saving";
540-
case '1':
540+
case 1:
541541
return prefix + "Standard";
542-
case '2':
542+
case 2:
543543
return prefix + "Standby";
544-
case '3':
544+
case 3:
545545
return prefix + "High-Temp-Shutdown";
546-
case '4':
546+
case 4:
547547
return prefix + "Other-Shutdown";
548548
}
549549

@@ -552,9 +552,6 @@ struct HesaiFaultModeInfo
552552

553553
[[nodiscard]] std::string describeFaultCode() const
554554
{
555-
std::string hex = std::string(fault_code, sizeof(fault_code));
556-
uint8_t fault_code = std::stoul(hex, nullptr, 16);
557-
558555
std::bitset<8> bits{fault_code};
559556
std::vector<std::string> fault_messages;
560557

@@ -582,13 +579,16 @@ struct HesaiFaultModeInfo
582579
return "OK";
583580
}
584581

585-
return "Fault code " + hex + ": " + boost::join(fault_messages, ", ");
582+
std::stringstream ss;
583+
ss << "0x" << std::hex << std::setfill('0') << std::setw(2) << fault_code;
584+
585+
return "Fault code " + ss.str() + ": " + boost::join(fault_messages, ", ");
586586
}
587587

588588
bool ok()
589589
{
590-
bool work_mode_ok = work_mode != '3' && work_mode != '4';
591-
bool fault_code_ok = std::strncmp(fault_code, "0x00", sizeof(fault_code));
590+
bool work_mode_ok = work_mode < 3;
591+
bool fault_code_ok = fault_code == 0;
592592
return work_mode_ok && fault_code_ok;
593593
}
594594

nebula_hw_interfaces/src/nebula_hesai_hw_interfaces/hesai_hw_interface.cpp

+19-2
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,10 @@ Status HesaiHwInterface::SetControlPort(
451451

452452
Status HesaiHwInterface::SetLidarRange(int method, std::vector<unsigned char> data)
453453
{
454+
if (sensor_configuration_->sensor_model == SensorModel::HESAI_PANDARAT128) {
455+
return Status::OK;
456+
}
457+
454458
// 0 - for all channels : 5-1 bytes
455459
// 1 - for each channel : 323-1 bytes
456460
// 2 - multi-section FOV : 1347-1 bytes
@@ -465,6 +469,10 @@ Status HesaiHwInterface::SetLidarRange(int method, std::vector<unsigned char> da
465469

466470
Status HesaiHwInterface::SetLidarRange(int start, int end)
467471
{
472+
if (sensor_configuration_->sensor_model == SensorModel::HESAI_PANDARAT128) {
473+
return Status::OK;
474+
}
475+
468476
// 0 - for all channels : 5-1 bytes
469477
// 1 - for each channel : 323-1 bytes
470478
// 2 - multi-section FOV : 1347-1 bytes
@@ -483,6 +491,10 @@ Status HesaiHwInterface::SetLidarRange(int start, int end)
483491

484492
HesaiLidarRangeAll HesaiHwInterface::GetLidarRange()
485493
{
494+
if (sensor_configuration_->sensor_model == SensorModel::HESAI_PANDARAT128) {
495+
return HesaiLidarRangeAll();
496+
}
497+
486498
auto response_or_err = SendReceive(PTC_COMMAND_GET_LIDAR_RANGE);
487499
auto response = response_or_err.value_or_throw(PrettyPrintPTCError(response_or_err.error_or({})));
488500

@@ -1295,9 +1307,14 @@ template <typename T>
12951307
T HesaiHwInterface::CheckSizeAndParse(const std::vector<uint8_t> & data)
12961308
{
12971309
if (data.size() < sizeof(T)) {
1298-
throw std::runtime_error("Attempted to parse too-small payload");
1310+
std::stringstream ss{};
1311+
ss << "Attempted to parse too-small payload: expected " << sizeof(T) << ", got " << data.size();
1312+
throw std::runtime_error(ss.str());
12991313
} else if (data.size() > sizeof(T)) {
1300-
PrintError("Sensor returned longer payload than expected. Will parse anyway.");
1314+
std::stringstream ss{};
1315+
ss << "Sensor returned too-large payload: expected " << sizeof(T) << ", got " << data.size()
1316+
<< ". Will parse anyway.";
1317+
PrintError(ss.str());
13011318
}
13021319

13031320
T parsed;

nebula_ros/include/nebula_ros/hesai/hw_monitor/tcp_fault_mode_info_provider.hpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ class TcpFaultModeInfoProvider : public DiagnosticProvider
6262
diagnostics.add("operation_mode", current_data_->describeWorkMode());
6363
diagnostics.add("faults", current_data_->describeFaultCode());
6464

65-
diagnostics.summary(diagnostic_msgs::msg::DiagnosticStatus::OK, "");
65+
if (current_data_->ok()) {
66+
diagnostics.summary(diagnostic_msgs::msg::DiagnosticStatus::OK, "");
67+
return;
68+
}
69+
70+
diagnostics.summary(diagnostic_msgs::msg::DiagnosticStatus::ERROR, "");
6671
}
6772

6873
std::unique_ptr<HesaiFaultModeInfo> current_data_;

nebula_ros/src/hesai/hw_monitor_wrapper.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "nebula_ros/hesai/hw_monitor/http_lidar_monitpr_provider.hpp"
88
#include "nebula_ros/hesai/hw_monitor/tcp_lidar_monitor_provider.hpp"
99
#include "nebula_ros/hesai/hw_monitor/tcp_lidar_status_provider.hpp"
10+
#include "nebula_ros/hesai/hw_monitor/tcp_fault_mode_info_provider.hpp"
1011

1112
#include <nebula_common/nebula_common.hpp>
1213

@@ -83,6 +84,9 @@ HesaiHwMonitorWrapper::getDiagnosticProviders(drivers::SensorModel sensor_model)
8384
result.push_back(status_provider);
8485

8586
if (sensor_model == drivers::SensorModel::HESAI_PANDARAT128) {
87+
auto fault_info_provider = std::make_shared<hw_monitor::TcpFaultModeInfoProvider>();
88+
result.push_back(fault_info_provider);
89+
8690
return result;
8791
}
8892

0 commit comments

Comments
 (0)