增加驱动两路刹车电机

This commit is contained in:
2025-07-06 10:57:41 +08:00
parent 9b3f5819ac
commit 8c9396e1f5
7 changed files with 50 additions and 26 deletions

View File

@@ -47,36 +47,25 @@ static void brakeOutput(void *signal_id)
{
case 1: // 电机前进状态
un_h_bridge_output.bit_data.channel_01 = setBrakeOn();
un_h_bridge_output.bit_data.channel_04 = setBrakeOn();
un_h_bridge_output.bit_data.channel_02 = setBrakeOff();
un_h_bridge_output.bit_data.channel_03 = setBrakeOff();
un_h_bridge_output.bit_data.sleep_01 = setBrakeOn();
un_h_bridge_output.bit_data.sleep_02 = setBrakeOn(); // 正转
un_inf_can_kgf_output1.bit_data.KGF13 = setBrakeOff(); // 抱闸继电器
un_inf_can_kgf_output1.bit_data.KGF14 = setBrakeOff(); // 抱闸继电器
un_h_bridge_output1.bit_data.channel_01 = setBrakeOn();
un_h_bridge_output1.bit_data.channel_02 = setBrakeOff();
printf("Brake: Motor forward\n");
break;
case 2: // 电机后退状态
un_h_bridge_output.bit_data.channel_01 = setBrakeOff();
un_h_bridge_output.bit_data.channel_04 = setBrakeOff();
un_h_bridge_output.bit_data.channel_02 = setBrakeOn();
un_h_bridge_output.bit_data.channel_03 = setBrakeOn();
un_h_bridge_output.bit_data.sleep_01 = setBrakeOn();
un_h_bridge_output.bit_data.sleep_02 = setBrakeOn(); // 反转
un_inf_can_kgf_output1.bit_data.KGF13 = setBrakeOn(); // 抱闸继电器
un_inf_can_kgf_output1.bit_data.KGF14 = setBrakeOn(); // 抱闸继电器
un_h_bridge_output.bit_data.channel_02 = setBrakeOn();
un_h_bridge_output1.bit_data.channel_01 = setBrakeOff();
un_h_bridge_output1.bit_data.channel_02 = setBrakeOn();
printf("Brake: Motor reverse\n");
break;
default:
un_h_bridge_output.bit_data.channel_01 = setBrakeOff();
un_h_bridge_output.bit_data.channel_04 = setBrakeOff();
un_h_bridge_output.bit_data.channel_02 = setBrakeOff();
un_h_bridge_output.bit_data.channel_03 = setBrakeOff();
un_h_bridge_output.bit_data.sleep_01 = setBrakeOff();
un_h_bridge_output.bit_data.sleep_02 = setBrakeOff(); // 关闭
un_h_bridge_output1.bit_data.channel_01 = setBrakeOff();
un_h_bridge_output1.bit_data.channel_02 = setBrakeOff();
printf("Brake: Motor off\n");
break;
}
@@ -100,6 +89,14 @@ static void brakeTimerProcess(void *signal_id)
{
brake_data.state = BRAKE_STATE_APPLYING_BRAKE;
brake_data.brake_motor_state = 1;
if( 0 == brake_data.brake_direction)
{
brake_data.brake_motor_state = 1;
}
else
{
brake_data.brake_motor_state = 2;
}
brakeOutput(NULL);
timerStart(&brake_data.brake_apply_timer, (uint32_t)(getParam("brk_on")), 0);
}
@@ -111,6 +108,14 @@ static void brakeTimerProcess(void *signal_id)
brake_data.state = BRAKE_STATE_RELEASING_BRAKE;
brake_data.brake_motor_state = 2;
brakeOutput(NULL);
if( 0 == brake_data.brake_direction)
{
brake_data.brake_motor_state = 2;
}
else
{
brake_data.brake_motor_state = 1;
}
timerStart(&brake_data.brake_release_timer, (uint32_t)(getParam("brk_off")), 0);
}
break;
@@ -182,6 +187,14 @@ static void brakeInput(void *signal_id)
}
void paramUpdate(void *signal_id)
{
brake_data.brake_direction = (uint8_t)getParam("brk_rev");
timerStart(&brake_data.brake_param_timer, 1000, 1);
}
// 修改APP模块的初始化函数
void brakeAppInit(void)
{
@@ -205,6 +218,7 @@ void brakeAppInit(void)
timerInit(&brake_data.brake_timer);
timerInit(&brake_data.brake_apply_timer);
timerInit(&brake_data.brake_release_timer);
timerInit(&brake_data.brake_param_timer);
// 订阅输入信号,处理刹车逻辑
subscribe(&un_sw_sample, brakeInput);
@@ -212,13 +226,16 @@ void brakeAppInit(void)
subscribe(&can_fault_info, brakeInput);
subscribe(&ethernet_fault_Info, brakeInput);
// 订阅定时器信号,用于状态机的定时处理
subscribe(&brake_data.brake_timer, brakeTimerProcess);
subscribe(&brake_data.brake_apply_timer, brakeTimerProcess);
subscribe(&brake_data.brake_release_timer, brakeTimerProcess);
subscribe(&brake_data.brake_param_timer, paramUpdate);
// 启动定时器,定期调用 brakeTimerProcess
timerStart(&brake_data.brake_timer, 500, 1);
timerStart(&brake_data.brake_param_timer, 1000, 1);
printf("app_brake: initial OK \n");
}

View File

@@ -29,7 +29,8 @@ typedef struct BrakeSystem
uint8_t brake_command; // 刹车命令变量1表示刹车,2表示释放
uint8_t brake_motor_state; // 刹车电机状态变量0停止,1前进,2后退
uint8_t brake_command_in_progress; // 刹车命令执行状态0表示空闲,1表示正在执行
uint8_t brake_direction;
uint8_t emergency_stop_switch; // 急停开关
uint8_t remote_emergency_stop; // 遥控器急停开关
uint8_t remote_fault; // 遥控器故障
@@ -41,6 +42,7 @@ typedef struct BrakeSystem
uint8_t old_brake_position; // 旧的刹车位置
Timer brake_apply_timer; // 刹车定时器
Timer brake_release_timer; // 释放刹车定时器
Timer brake_param_timer; //参数更新时间
} BrakeSystem;

View File

@@ -52,6 +52,7 @@ extern "C"
X(Ocrv_il) \
X(Ocrv_ol) \
X(minTorq) \
X(brk_rev) \
X(test)
// 定义一个包含所有参数名称的结构体