From 86871a4ab8b3046030a413dff8d18a53f2f2bbc2 Mon Sep 17 00:00:00 2001 From: lyq Date: Mon, 26 Jan 2026 15:17:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B8=85=E6=89=AB=E9=83=A8?= =?UTF-8?q?=E4=BB=B6=E5=88=9D=E5=A7=8B=E5=8C=96bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/base/mc/src/timer_tasks.cpp | 75 ++++++++++++--------------------- 1 file changed, 27 insertions(+), 48 deletions(-) diff --git a/src/base/mc/src/timer_tasks.cpp b/src/base/mc/src/timer_tasks.cpp index b86b9b0..b607ec0 100644 --- a/src/base/mc/src/timer_tasks.cpp +++ b/src/base/mc/src/timer_tasks.cpp @@ -35,60 +35,39 @@ void epsTimerTask(CANDriver& canctl) // 修改timer_tasks.cpp中的vcuTimerTask函数 void vcuTimerTask(CANDriver& canctl) { - static bool vcu_initialized = false; - static bool last_sweep_state = false; // 记录上一次清扫状态 - auto msg = get_safe_control(); - // 首次运行时初始化VCU控制 - if (!vcu_initialized) - { - // 发送CAN使能指令 - vcu_enable_cmd.setCANEnable(true); - canctl.sendFrame(vcu_enable_cmd.toFrame()); - // LOG_INFO("mcuTimerTask"); - vcu_initialized = true; - LOG_INFO("[VCU] CAN control enabled"); - } + // 根据清扫状态设置所有部件 + int8_t target_value = msg.sweep ? 100 : 0; // 100表示启动,0表示停止 + int8_t target_value2 = msg.sweep ? -100 : 100; // -100表示下沉,100表示抬升 - // 检查清扫状态是否变化 - bool sweep_state_changed = (msg.sweep != last_sweep_state); + // 发送CAN使能指令 + vcu_enable_cmd.setCANEnable(true); + canctl.sendFrame(vcu_enable_cmd.toFrame()); - if (sweep_state_changed) - { - // 根据清扫状态设置所有部件 - int8_t target_value = msg.sweep ? 100 : 0; // 100表示启动,0表示停止 - int8_t target_value2 = msg.sweep ? -100 : 100; // -100表示下沉,100表示抬升 + // ===== 控制0x211报文 (电机M1-M7) ===== + vcu_motor1_cmd.setByte0(msg.sweep ? 1 : 0); // 1表示正向运行,0表示停止 + vcu_motor1_cmd.setByte1(target_value); + vcu_motor1_cmd.setByte2(target_value); + 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) ===== - vcu_motor1_cmd.setByte0(msg.sweep ? 1 : 0); // 1表示正向运行,0表示停止 - vcu_motor1_cmd.setByte1(target_value); - vcu_motor1_cmd.setByte2(target_value); - 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()); - // LOG_INFO("vcuTimerTask1"); + // ===== 控制0x212报文 (电机M8和LED输出) ===== + 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()); - // ===== 控制0x212报文 (电机M8和LED输出) ===== - 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; - } + LOG_INFO_THROTTLE(1000, "[VCU] Sweep? %s", msg.sweep ? "Yes" : "No"); } // 定时器回调:BMS 查询任务