Compare commits
3 Commits
5211cd55dc
...
45a853b86c
| Author | SHA1 | Date | |
|---|---|---|---|
| 45a853b86c | |||
| 61fd82ee18 | |||
| 86871a4ab8 |
@ -35,60 +35,39 @@ void epsTimerTask(CANDriver& canctl)
|
|||||||
// 修改timer_tasks.cpp中的vcuTimerTask函数
|
// 修改timer_tasks.cpp中的vcuTimerTask函数
|
||||||
void vcuTimerTask(CANDriver& canctl)
|
void vcuTimerTask(CANDriver& canctl)
|
||||||
{
|
{
|
||||||
static bool vcu_initialized = false;
|
|
||||||
static bool last_sweep_state = false; // 记录上一次清扫状态
|
|
||||||
|
|
||||||
auto msg = get_safe_control();
|
auto msg = get_safe_control();
|
||||||
|
|
||||||
// 首次运行时初始化VCU控制
|
// 根据清扫状态设置所有部件
|
||||||
if (!vcu_initialized)
|
int8_t target_value = msg.sweep ? 100 : 0; // 100表示启动,0表示停止
|
||||||
{
|
int8_t target_value2 = msg.sweep ? -100 : 100; // -100表示下沉,100表示抬升
|
||||||
// 发送CAN使能指令
|
|
||||||
vcu_enable_cmd.setCANEnable(true);
|
|
||||||
canctl.sendFrame(vcu_enable_cmd.toFrame());
|
|
||||||
// LOG_INFO("mcuTimerTask");
|
|
||||||
vcu_initialized = true;
|
|
||||||
LOG_INFO("[VCU] CAN control enabled");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查清扫状态是否变化
|
// 发送CAN使能指令
|
||||||
bool sweep_state_changed = (msg.sweep != last_sweep_state);
|
vcu_enable_cmd.setCANEnable(true);
|
||||||
|
canctl.sendFrame(vcu_enable_cmd.toFrame());
|
||||||
|
|
||||||
if (sweep_state_changed)
|
// ===== 控制0x211报文 (电机M1-M7) =====
|
||||||
{
|
vcu_motor1_cmd.setByte0(msg.sweep ? 1 : 0); // 1表示正向运行,0表示停止
|
||||||
// 根据清扫状态设置所有部件
|
vcu_motor1_cmd.setByte1(target_value);
|
||||||
int8_t target_value = msg.sweep ? 100 : 0; // 100表示启动,0表示停止
|
vcu_motor1_cmd.setByte2(target_value);
|
||||||
int8_t target_value2 = msg.sweep ? -100 : 100; // -100表示下沉,100表示抬升
|
vcu_motor1_cmd.setByte3(target_value);
|
||||||
|
vcu_motor1_cmd.setByte4(target_value2);
|
||||||
|
vcu_motor1_cmd.setByte5(target_value2);
|
||||||
|
vcu_motor1_cmd.setByte6(target_value);
|
||||||
|
vcu_motor1_cmd.setByte7(target_value);
|
||||||
|
canctl.sendFrame(vcu_motor1_cmd.toFrame());
|
||||||
|
|
||||||
// ===== 控制0x211报文 (电机M1-M7) =====
|
// ===== 控制0x212报文 (电机M8和LED输出) =====
|
||||||
vcu_motor1_cmd.setByte0(msg.sweep ? 1 : 0); // 1表示正向运行,0表示停止
|
vcu_motor2_cmd.setByte0(target_value);
|
||||||
vcu_motor1_cmd.setByte1(target_value);
|
vcu_motor2_cmd.setByte1(target_value);
|
||||||
vcu_motor1_cmd.setByte2(target_value);
|
vcu_motor2_cmd.setByte2(target_value);
|
||||||
vcu_motor1_cmd.setByte3(target_value);
|
vcu_motor2_cmd.setByte3(target_value);
|
||||||
vcu_motor1_cmd.setByte4(target_value2);
|
vcu_motor2_cmd.setByte4(target_value);
|
||||||
vcu_motor1_cmd.setByte5(target_value2);
|
vcu_motor2_cmd.setByte5(target_value);
|
||||||
vcu_motor1_cmd.setByte6(target_value);
|
vcu_motor2_cmd.setByte6(target_value);
|
||||||
vcu_motor1_cmd.setByte7(target_value);
|
vcu_motor2_cmd.setByte7(target_value);
|
||||||
canctl.sendFrame(vcu_motor1_cmd.toFrame());
|
canctl.sendFrame(vcu_motor2_cmd.toFrame());
|
||||||
// LOG_INFO("vcuTimerTask1");
|
|
||||||
|
|
||||||
// ===== 控制0x212报文 (电机M8和LED输出) =====
|
LOG_INFO_THROTTLE(1000, "[VCU] Sweep? %s", msg.sweep ? "Yes" : "No");
|
||||||
vcu_motor2_cmd.setByte0(target_value);
|
|
||||||
vcu_motor2_cmd.setByte1(target_value);
|
|
||||||
vcu_motor2_cmd.setByte2(target_value);
|
|
||||||
vcu_motor2_cmd.setByte3(target_value);
|
|
||||||
vcu_motor2_cmd.setByte4(target_value);
|
|
||||||
vcu_motor2_cmd.setByte5(target_value);
|
|
||||||
vcu_motor2_cmd.setByte6(target_value);
|
|
||||||
vcu_motor2_cmd.setByte7(target_value);
|
|
||||||
canctl.sendFrame(vcu_motor2_cmd.toFrame());
|
|
||||||
// LOG_INFO("vcuTimerTask2");
|
|
||||||
|
|
||||||
// LOG_INFO("[VCU] Sweep mode %s", msg.sweep ? "activated" : "deactivated");
|
|
||||||
|
|
||||||
// 更新状态记录
|
|
||||||
last_sweep_state = msg.sweep;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 定时器回调:BMS 查询任务
|
// 定时器回调:BMS 查询任务
|
||||||
|
|||||||
@ -50,8 +50,8 @@ void CanDecoder::handle_bms_100(const sweeperMsg::CanFrame& msg)
|
|||||||
ctx_.info.chargeStatus = (current >= 0);
|
ctx_.info.chargeStatus = (current >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_INFO("[0x100] 总电压: %.2f V, 电流: %.2f A, 剩余容量: %.2f Ah, 是否在充电: %s", voltage, current, capacity,
|
// LOG_INFO("[0x100] 总电压: %.2f V, 电流: %.2f A, 剩余容量: %.2f Ah, 是否在充电: %s", voltage, current, capacity,
|
||||||
((current >= 0) ? "是" : "否"));
|
// ((current >= 0) ? "是" : "否"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CanDecoder::handle_bms_101(const sweeperMsg::CanFrame& msg)
|
void CanDecoder::handle_bms_101(const sweeperMsg::CanFrame& msg)
|
||||||
|
|||||||
@ -44,7 +44,4 @@ sleep 0.2
|
|||||||
ros2 launch fu fu.launch.py &
|
ros2 launch fu fu.launch.py &
|
||||||
sleep 0.2
|
sleep 0.2
|
||||||
|
|
||||||
ros2 run pub_gps pub_gps_node &
|
|
||||||
sleep 0.2
|
|
||||||
|
|
||||||
wait
|
wait
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user