From 083d062792e6fa56466772e78a219d9bd8f916e9 Mon Sep 17 00:00:00 2001 From: liumin Date: Mon, 8 Dec 2025 22:19:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=87=87=E9=9B=86=E7=94=B5?= =?UTF-8?q?=E6=B1=A0=E7=94=B5=E5=8E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eth-xip/sf/app/app_differential_drive.c | 23 ++++---- .../app_demo/eth-xip/sf/app/app_power.c | 14 ++++- .../app_demo/eth-xip/sf/app/app_power.h | 5 ++ .../app_demo/eth-xip/sf/app/app_request.c | 8 +-- .../app_demo/eth-xip/sf/interface.c | 3 + .../app_demo/eth-xip/sf/interface.h | 55 +++++++++++++++---- .../app_demo/eth-xip/sf/interface_can.c | 22 ++++++-- .../app_demo/eth-xip/sf/interface_can.h | 2 +- 8 files changed, 98 insertions(+), 34 deletions(-) diff --git a/boards/e3_176_ref/app_demo/eth-xip/sf/app/app_differential_drive.c b/boards/e3_176_ref/app_demo/eth-xip/sf/app/app_differential_drive.c index 11a39e4..5fe3c14 100644 --- a/boards/e3_176_ref/app_demo/eth-xip/sf/app/app_differential_drive.c +++ b/boards/e3_176_ref/app_demo/eth-xip/sf/app/app_differential_drive.c @@ -39,7 +39,6 @@ void setMotorOutput(float *out_torq, float max_torque, uint16_t feed_power, uint un_motor_output1.bit_data.MotCon_1Signal4 = (uint16_t)(-abs_left_front_speed); un_motor_output2.bit_data.MotCon_1Signal3 = (uint16_t)(abs_left_rear_speed); - } @@ -171,13 +170,13 @@ void distributeTorque(float rpm1, float rpm2, float total_torque, float* torque1 if (fabs(total_torque) < 0.001f) { *torque1 = 0.0f; *torque2 = 0.0f; - return; + return; } // // 保护条件:当两电机均静止时采用平均分配策略 // if (fabs(rpm1) < 0.001f && fabs(rpm2) < 0.001f) { // *torque1 = total_torque / 2.0f; -// *torque2 = total_torque / 2.0f; +// *torque2 = total_torque / 2.0f; // return; // } @@ -624,17 +623,17 @@ static void diffInput(void *signal_id) diff_data.desired_speed = diff_data.desired_speed * 0.01f; diff_data.desired_curvature = diff_data.desired_curvature * 0.0001f; // 遥控器速度映射,参数含义为:输入速度,死区,最大输入,最大输出,低速输入,低速输出 - diff_data.desired_speed = mapRemoteControlSpeed(diff_data.desired_speed, 0.1, 20, 5, 5, 0.5); + diff_data.desired_speed = mapRemoteControlSpeed(diff_data.desired_speed, 0.5, 20, 5, 5, 0.5); diff_data.desired_curvature = mapRemoteControlSpeed(diff_data.desired_curvature, 0.1, 2, 2, 1, 0.5); - if(diff_data.desired_speed >= 0)//20250320 增加根据速度大小来决定方向,解决后退时转弯反向的问题 - { - diff_data.desired_curvature = diff_data.desired_curvature; - } - else - { - diff_data.desired_curvature = -diff_data.desired_curvature; - } +// if(diff_data.desired_speed >= 0)//20250320 增加根据速度大小来决定方向,解决后退时转弯反向的问题 基站车不需要加换相,转向方式和比亚迪一样 +// { +// diff_data.desired_curvature = diff_data.desired_curvature; +// } +// else +// { +// diff_data.desired_curvature = -diff_data.desired_curvature; +// } } } else if ( (signal_id == &un_manual_computer_input) && (diff_data.mode == MODE_AUTO) ) diff --git a/boards/e3_176_ref/app_demo/eth-xip/sf/app/app_power.c b/boards/e3_176_ref/app_demo/eth-xip/sf/app/app_power.c index 8d0ce8a..6a13c36 100644 --- a/boards/e3_176_ref/app_demo/eth-xip/sf/app/app_power.c +++ b/boards/e3_176_ref/app_demo/eth-xip/sf/app/app_power.c @@ -25,7 +25,7 @@ typedef struct { uint8_t is_power_on; Timer timer; uint8_t old_is_power_on; - Timer timer1; + Timer timer1; } PowerButton; // 全局变量 @@ -332,6 +332,15 @@ static void powerInput(void *signal_id) } +void bmsProcess(void *signal_id)//读取电压 +{ + (void)signal_id; + + power_data.high_battery_voltage = (float)un_bms_input.bit_data.bus_voltage / 100.0; + power_data.low_battery_voltage = (float)un_bms_input.bit_data.low_voltage / 100.0; + +} + // APP模块的初始化 void powerAppInit(void) @@ -357,6 +366,9 @@ void powerAppInit(void) timerInit(&power_data.timer1); subscribe(&power_data.timer1, wakeupProcess); timerStart(&power_data.timer1, 500, 1); // 周期调用 + + subscribe(&un_bms_input, bmsProcess); + //预充定时器 timerInit(&power_data.timer_pre_charge); diff --git a/boards/e3_176_ref/app_demo/eth-xip/sf/app/app_power.h b/boards/e3_176_ref/app_demo/eth-xip/sf/app/app_power.h index 0cebf81..30a933e 100644 --- a/boards/e3_176_ref/app_demo/eth-xip/sf/app/app_power.h +++ b/boards/e3_176_ref/app_demo/eth-xip/sf/app/app_power.h @@ -31,6 +31,7 @@ typedef struct { Timer timer; // 定时器 Timer timer1; Timer timer_pre_charge; // 预充定时器 + Timer timer2; //请求采集电源时间 PowerState last_state; // 上一次状态 uint8_t emergency_stop_switch; // 急停开关 uint8_t high_voltage_switch; // 高压开关 @@ -39,6 +40,10 @@ typedef struct { uint8_t emergency_stop; // 急停状态 uint8_t pre_charge_finish; // 预充完成标志位 uint8_t old_state; // 上一次状态 + + float low_battery_voltage; // 低压电池电压,单位V + float high_battery_voltage; // 高压电池电压,单位V + } PowerSystem; // 声明外部变量 diff --git a/boards/e3_176_ref/app_demo/eth-xip/sf/app/app_request.c b/boards/e3_176_ref/app_demo/eth-xip/sf/app/app_request.c index f271dcb..641c10f 100644 --- a/boards/e3_176_ref/app_demo/eth-xip/sf/app/app_request.c +++ b/boards/e3_176_ref/app_demo/eth-xip/sf/app/app_request.c @@ -293,9 +293,9 @@ static void requestInput(void *signal_id) } else if(signal_id == &un_bms_input) { - un_vehicle_Info_output.bit_data.battery_voltage = un_bms_input.bit_data.bus_voltage/10;//电池电压读取得的10mV,所以输出的是100mV单位,所以缩小10倍 - un_vehicle_Info_output.bit_data.battery_soc = un_bms_input.bit_data.soc;//SOC - un_vehicle_Info_output.bit_data.battery_current = un_bms_input.bit_data.bus_current;//电池电流 +// un_vehicle_Info_output.bit_data.battery_voltage = un_bms_input.bit_data.bus_voltage/10;//电池电压读取得的10mV,所以输出的是100mV单位,所以缩小10倍 +// un_vehicle_Info_output.bit_data.battery_soc = un_bms_input.bit_data.soc;//SOC +// un_vehicle_Info_output.bit_data.battery_current = un_bms_input.bit_data.bus_current;//电池电流 } else if(signal_id == &un_motor_input1) { @@ -322,7 +322,7 @@ static void requestInput(void *signal_id) } else if(signal_id == &un_manual_computer_input) { - memcpy(&un_manual_control_output.arr[0],&(un_manual_computer_input.arr[0]),12);//手柄拷贝 +// memcpy(&un_manual_control_output.arr[0],&(un_manual_computer_input.arr[0]),12);//手柄拷贝 } else if(signal_id == ðernet_fault_Info) { diff --git a/boards/e3_176_ref/app_demo/eth-xip/sf/interface.c b/boards/e3_176_ref/app_demo/eth-xip/sf/interface.c index af11eb1..5c08c5b 100644 --- a/boards/e3_176_ref/app_demo/eth-xip/sf/interface.c +++ b/boards/e3_176_ref/app_demo/eth-xip/sf/interface.c @@ -54,6 +54,9 @@ UnSdoOutput un_sdo_output8 ;//设定右电机 UnSdoOutput un_sdo_output9 ;//输入 UnSdoOutput un_sdo_output10 ;//输入 + +UnBMSRequest un_bms_request ;//BMS 请求 + //IO口 UnSwSample un_sw_sample ;//采集 diff --git a/boards/e3_176_ref/app_demo/eth-xip/sf/interface.h b/boards/e3_176_ref/app_demo/eth-xip/sf/interface.h index ac6c7a5..33caa35 100644 --- a/boards/e3_176_ref/app_demo/eth-xip/sf/interface.h +++ b/boards/e3_176_ref/app_demo/eth-xip/sf/interface.h @@ -124,18 +124,12 @@ typedef union _UnMotorTempInput // 接收BMS输入 typedef struct _StrBmsInput { -//----接收0x100---------------------------------- +//----接收0x301---------------------------------- // 多字节数据,高位在前,低位在后 - unsigned int bus_voltage : 16; // 母线电压 单位为10mV - unsigned int bus_current : 16; // 母线电流 单位为10mA - unsigned int remainder_capacity : 16; // 剩余容量 单位为10mAh 充电为正,放电为负 - unsigned int crc1 : 16; //crc -//----接收0x101---------------------------------- - // 多字节数据,高位在前,低位在后 - unsigned int full_capacity : 16; // 充满容量 单位为10mAh - unsigned int Discharge_times : 16; // 放电循环次数 单位为1次 - unsigned int soc : 16; // soc 1% - unsigned int crc2 : 16; //crc + uint16_t bus_voltage ; // 母线电压 单位为0.01V + uint16_t low_voltage ; // 母线电流 单位为0.01V + uint16_t channel3 ; // 保留通道 + uint16_t crc1 ; // } StrBmsInput; typedef union _UnBmsInput @@ -667,6 +661,37 @@ typedef union _UnComputerOutput } UnComputerOutput; +// BMS数据请求结构体 +typedef struct _StrBMSRequest +{ + uint16_t reserved1; + uint16_t reserved2; + uint16_t reserved3; + uint16_t reserved4; +} StrBMSRequest; + +typedef union _UnBMSRequest +{ + StrBMSRequest bit_data; // 使用定义的结构体变量名 + uint8_t arr[sizeof(StrBMSRequest)]; // 通过结构体类型确定大小 +} UnBMSRequest; + + +//// BMS数据输入结构体 +//typedef struct _StrBMSIntput +//{ +// uint16_t reserved1; +// uint16_t reserved2; +// uint16_t reserved3; +// uint16_t reserved4; +//} StrBMSIntput; +// +//typedef union _UnBMSRequest +//{ +// StrBMSIntput bit_data; // 使用定义的结构体变量名 +// uint8_t arr[sizeof(StrBMSIntput)]; // 通过结构体类型确定大小 +//} UnBMSIntput; + // 车辆信息,输出给上位机 @@ -886,6 +911,13 @@ typedef union _UnAutoControlOutput + + + + + + + //-----IO口--------------------------------------------------------------- // 电压信号输出,到遥控器 typedef struct _StrVoltageSignalOutput @@ -942,6 +974,7 @@ extern UnSdoOutput un_sdo_output6 ;//设定右 extern UnSdoOutput un_sdo_output7 ;//使能右电机 extern UnSdoOutput un_sdo_output8 ;//设定右电机模式 +extern UnBMSRequest un_bms_request ;//BMS 请求 //串口 extern UnRemoteControlInput un_remote_control_input; //遥控器输入 diff --git a/boards/e3_176_ref/app_demo/eth-xip/sf/interface_can.c b/boards/e3_176_ref/app_demo/eth-xip/sf/interface_can.c index e225a77..089874f 100644 --- a/boards/e3_176_ref/app_demo/eth-xip/sf/interface_can.c +++ b/boards/e3_176_ref/app_demo/eth-xip/sf/interface_can.c @@ -538,7 +538,8 @@ void flexcan_Receive_callback_6(flexcan_handle_t *handle, flexcan_status_e status, uint32_t result, void *userData) { - flexcan_frame_t *buf = (flexcan_frame_t *)userData; + flexcan_frame_t *buf = (flexcan_frame_t *)userData; + uint8_t i = 0; //-------------------------------------------------------------- switch (status) { @@ -559,6 +560,16 @@ void flexcan_Receive_callback_6(flexcan_handle_t *handle, printf("Feed dog flag received %d\n",getCurrentTime()); } } + else if(BMS_INPUT_ID1 == (buf->id))//յιID + { + for(i = 0; i < (buf->length); i++) + { + un_bms_input.arr[i+8] = buf->dataBuffer[i]; + } + //ź + publishMessage(&un_bms_input, 1); + } + else { } @@ -1166,7 +1177,10 @@ void canSendAll(void *signal_id) CanData[5] = 0xFF; CAN_Send_Msg(&can_handle_1, MOTOR_OUTPUT_ID_1, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData,CanData, 8, 17);//1 - CAN_Send_Msg(&can_handle_2, MOTOR_OUTPUT_ID_2, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData,CanData, 8, 17);//1 + CAN_Send_Msg(&can_handle_2, MOTOR_OUTPUT_ID_2, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData,CanData, 8, 17);//1 + + CAN_Send_Msg(&can_handle_6, BMS_INPUT_ID1, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData,CanData, 8, 17);//BMS + } @@ -1344,9 +1358,7 @@ void canInterfaceInit(void) subscribe(&un_sdo_output5, processSdoOutput5); subscribe(&un_sdo_output6, processSdoOutput6); subscribe(&un_sdo_output7, processSdoOutput7); - subscribe(&un_sdo_output8, processSdoOutput8); - - + subscribe(&un_sdo_output8, processSdoOutput8); timerStart(&can_timer_interface1,10,1);//1msһ diff --git a/boards/e3_176_ref/app_demo/eth-xip/sf/interface_can.h b/boards/e3_176_ref/app_demo/eth-xip/sf/interface_can.h index d074385..6f0004b 100644 --- a/boards/e3_176_ref/app_demo/eth-xip/sf/interface_can.h +++ b/boards/e3_176_ref/app_demo/eth-xip/sf/interface_can.h @@ -72,7 +72,7 @@ -#define BMS_INPUT_ID1 0x100 +#define BMS_INPUT_ID1 0x301 #define BMS_INPUT_ID2 0x101 #define REMOTE_ID 0x12000023 //#define TEMP_MODULE_INPUT_ID_1 0x301