Auto commit at 2025-05-27 08:42:33

This commit is contained in:
root 2025-05-27 08:42:33 +08:00
parent ab26100687
commit f967a1ef92
3 changed files with 106 additions and 107 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
/build/ /build/
/install/ /install/
/log/ /log/
/auto_git_push.sh

6
a.sh
View File

@ -1,6 +0,0 @@
sudo ip link set can0 down
sudo ip link set can0 up type can bitrate 500000
sudo chmod 666 /dev/ttyUSB5
sudo chmod 666 /dev/ttyUSB5
source install/setup.bash
#sudo insmod drivers/usb/serial/pl2303.ko

View File

@ -6,6 +6,9 @@
#include "mc/msg/mc_ctrl.hpp" #include "mc/msg/mc_ctrl.hpp"
#include "mc/msg/can_frame.hpp" #include "mc/msg/can_frame.hpp"
constexpr float EPS_GEAR_RATIO = 16.5f;
constexpr float DELTA_T = 0.02f; // 20ms
class SBUSNode : public rclcpp::Node class SBUSNode : public rclcpp::Node
{ {
public: public:
@ -54,25 +57,25 @@ private:
// 定时器回调函数,用于周期性发布控制指令 // 定时器回调函数,用于周期性发布控制指令
void timer_callback() void timer_callback()
{ {
int MCU_RPM_MAX = config.mcu_rpm_max; static int MCU_RPM_MAX = config.mcu_rpm_max;
float EPS_ANGLE_MAX = config.eps_angle_max; static float EPS_ANGLE_MAX = config.eps_angle_max;
constexpr float EPS_GEAR_RATIO = 16.5f;
constexpr float DELTA_T = 0.02f; // 20ms bool data_safe = uart_handler_->get_data_safe(); // 获取数据安全性
auto msg = mc::msg::McCtrl(); // 控制消息对象 auto msg = mc::msg::McCtrl(); // 控制消息对象
uint16_t ch_data[8]; // 各通道遥控数据
// 获取各通道遥控数据 if (data_safe) // 数据安全,进行数据解析并发布
uint16_t ch_data[8]; {
// 获取数据安全性 // 赋值与打印
bool data_safe = uart_handler_->get_data_safe();
for (int i = 0; i < 8; ++i) for (int i = 0; i < 8; ++i)
{ {
ch_data[i] = uart_handler_->get_channel_value(i); ch_data[i] = uart_handler_->get_channel_value(i);
printf("ch[%d]:%d ", i, ch_data[i]); printf("ch[%d]:%d ", i, ch_data[i]);
} }
printf("\n"); printf("\n");
// 是否使能车辆控制
if (ch_data[6] == 192) if (ch_data[6] == 192) // 是否使能车辆控制
{ {
msg.mcu_enabled = true; msg.mcu_enabled = true;
msg.brake = 0; msg.brake = 0;
@ -152,9 +155,8 @@ private:
msg.angle = target_angle; msg.angle = target_angle;
msg.angle_speed = can_speed; msg.angle_speed = can_speed;
} }
else else // 未使能状态,发送安全默认控制指令
{ {
// 未使能状态,发送安全默认控制指令
msg.mcu_enabled = false; msg.mcu_enabled = false;
msg.brake = 1; msg.brake = 1;
msg.gear = 0; msg.gear = 0;
@ -172,8 +174,9 @@ private:
msg.edge_brush_spin = false; msg.edge_brush_spin = false;
} }
if (data_safe) // 发布控制消息
{ pub_->publish(msg);
RCLCPP_INFO_STREAM(this->get_logger(), "Publishing ControlMsg:" RCLCPP_INFO_STREAM(this->get_logger(), "Publishing ControlMsg:"
<< "\n mcu_enabled: " << msg.mcu_enabled << "\n mcu_enabled: " << msg.mcu_enabled
<< "\n brake: " << static_cast<int>(msg.brake) << "\n brake: " << static_cast<int>(msg.brake)
@ -197,8 +200,10 @@ private:
<< "\n edge_brush_spin: " << msg.edge_brush_spin << "\n edge_brush_spin: " << msg.edge_brush_spin
<< "\n main_brush_pwm: " << static_cast<int>(msg.main_brush_pwm) << "\n main_brush_pwm: " << static_cast<int>(msg.main_brush_pwm)
<< "\n edge_brush_pwm: " << static_cast<int>(msg.edge_brush_pwm)); << "\n edge_brush_pwm: " << static_cast<int>(msg.edge_brush_pwm));
}
pub_->publish(msg); // 发布控制消息 else
{
return; // 下次循环,等待数据安全
} }
} }