添加遥控一键清扫功能
This commit is contained in:
parent
8dd991b677
commit
7924773826
@ -4,6 +4,7 @@
|
|||||||
#include "mqtt_report/get_config.h"
|
#include "mqtt_report/get_config.h"
|
||||||
#include "mqtt_report/report_struct.h"
|
#include "mqtt_report/report_struct.h"
|
||||||
#include "mqtt_report/fault_codes.h"
|
#include "mqtt_report/fault_codes.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
Config config; // 清扫车配置文件
|
Config config; // 清扫车配置文件
|
||||||
|
|
||||||
@ -37,7 +38,6 @@ void Msg_Handler(const mc::msg::CanFrame::SharedPtr msg)
|
|||||||
float gear_ratio = 32.0;
|
float gear_ratio = 32.0;
|
||||||
float wheel_radius = 0.15; // 轮胎半径,单位米
|
float wheel_radius = 0.15; // 轮胎半径,单位米
|
||||||
float vehicle_speed_kmh = (2 * 3.1416 * wheel_radius * (motorspeed / gear_ratio) * 60.0) / 1000.0;
|
float vehicle_speed_kmh = (2 * 3.1416 * wheel_radius * (motorspeed / gear_ratio) * 60.0) / 1000.0;
|
||||||
|
|
||||||
info_report.speed = vehicle_speed_kmh;
|
info_report.speed = vehicle_speed_kmh;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -48,6 +48,7 @@ void Msg_Handler(const mc::msg::CanFrame::SharedPtr msg)
|
|||||||
uint8_t WaterValue_l = (msg->data[1]);
|
uint8_t WaterValue_l = (msg->data[1]);
|
||||||
uint16_t WaterValue = (WaterValue_h & 0x3f) * 16 + (WaterValue_l & 0x0f);
|
uint16_t WaterValue = (WaterValue_h & 0x3f) * 16 + (WaterValue_l & 0x0f);
|
||||||
float WaterLevel = WaterValue * (-0.235) + 199.75;
|
float WaterLevel = WaterValue * (-0.235) + 199.75;
|
||||||
|
WaterLevel = std::clamp(WaterLevel, 0.0f, 180.0f);
|
||||||
info_report.waterLevel = static_cast<int>(std::round(WaterLevel / 1.8f)); // 液位百分比
|
info_report.waterLevel = static_cast<int>(std::round(WaterLevel / 1.8f)); // 液位百分比
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -221,7 +222,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
void topic_callback(const mc::msg::CanFrame::SharedPtr msg)
|
void topic_callback(const mc::msg::CanFrame::SharedPtr msg)
|
||||||
{
|
{
|
||||||
// RCLCPP_INFO(this->get_logger(), "Received CAN frame ID: %u, DLC: %u", msg->id, msg->dlc);
|
// RCLCPP_INFO(this->get_logger(), "Received CAN frame ID: %u, DLC: %u", msg->id, msg->dlc);
|
||||||
Msg_Handler(msg);
|
Msg_Handler(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -107,6 +107,32 @@ private:
|
|||||||
msg.rpm = static_cast<uint16_t>(MCU_RPM_MAX * (1016 - ch_data[1]) / (1016 - 216));
|
msg.rpm = static_cast<uint16_t>(MCU_RPM_MAX * (1016 - ch_data[1]) / (1016 - 216));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 一键清扫
|
||||||
|
if (ch_data[6] == 1792)
|
||||||
|
{
|
||||||
|
msg.main_brush_lift = false;
|
||||||
|
msg.edge_brush_lift = false;
|
||||||
|
msg.vacuum = false;
|
||||||
|
msg.spray = false;
|
||||||
|
msg.mud_flap = false;
|
||||||
|
msg.dust_shake = false;
|
||||||
|
msg.main_brush_spin = false;
|
||||||
|
msg.edge_brush_spin = false;
|
||||||
|
}
|
||||||
|
else if (ch_data[6] == 192)
|
||||||
|
{
|
||||||
|
msg.main_brush_lift = true;
|
||||||
|
msg.edge_brush_lift = true;
|
||||||
|
msg.vacuum = true;
|
||||||
|
msg.spray = true;
|
||||||
|
msg.mud_flap = true;
|
||||||
|
msg.dust_shake = true;
|
||||||
|
msg.main_brush_spin = true;
|
||||||
|
msg.edge_brush_spin = true;
|
||||||
|
msg.main_brush_pwm = 100;
|
||||||
|
msg.edge_brush_pwm = 100;
|
||||||
|
}
|
||||||
|
|
||||||
// 转向逻辑
|
// 转向逻辑
|
||||||
float target_angle = (static_cast<float>(ch_data[3]) - 800) / 800 * EPS_ANGLE_MAX;
|
float target_angle = (static_cast<float>(ch_data[3]) - 800) / 800 * EPS_ANGLE_MAX;
|
||||||
|
|
||||||
@ -135,6 +161,14 @@ private:
|
|||||||
msg.brake_time_ms = 500;
|
msg.brake_time_ms = 500;
|
||||||
msg.angle = 0;
|
msg.angle = 0;
|
||||||
msg.angle_speed = 120;
|
msg.angle_speed = 120;
|
||||||
|
msg.main_brush_lift = false;
|
||||||
|
msg.edge_brush_lift = false;
|
||||||
|
msg.vacuum = false;
|
||||||
|
msg.spray = false;
|
||||||
|
msg.mud_flap = false;
|
||||||
|
msg.dust_shake = false;
|
||||||
|
msg.main_brush_spin = false;
|
||||||
|
msg.edge_brush_spin = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data_safe)
|
if (data_safe)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user