增加采集电池电压

This commit is contained in:
2025-12-08 22:19:02 +08:00
parent f40bb7707b
commit 083d062792
8 changed files with 98 additions and 34 deletions

View File

@@ -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);
}
@@ -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) )

View File

@@ -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)
@@ -358,6 +367,9 @@ void powerAppInit(void)
subscribe(&power_data.timer1, wakeupProcess);
timerStart(&power_data.timer1, 500, 1); // 周期调用
subscribe(&un_bms_input, bmsProcess);
//预充定时器
timerInit(&power_data.timer_pre_charge);
subscribe(&power_data.timer_pre_charge, powerTimerProcess);

View File

@@ -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;
// 声明外部变量

View File

@@ -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 == &ethernet_fault_Info)
{

View File

@@ -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 ;//采集

View File

@@ -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; //遥控器输入

View File

@@ -539,6 +539,7 @@ void flexcan_Receive_callback_6(flexcan_handle_t *handle,
void *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))//<2F><><EFBFBD>յ<EFBFBD>ι<EFBFBD><CEB9>ID
{
for(i = 0; i < (buf->length); i++)
{
un_bms_input.arr[i+8] = buf->dataBuffer[i];
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
publishMessage(&un_bms_input, 1);
}
else
{
}
@@ -1167,6 +1178,9 @@ void canSendAll(void *signal_id)
CAN_Send_Msg(&can_handle_1, MOTOR_OUTPUT_ID_1, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData,CanData, 8, 17);//<2F><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CAN_Send_Msg(&can_handle_2, MOTOR_OUTPUT_ID_2, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData,CanData, 8, 17);//<2F><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CAN_Send_Msg(&can_handle_6, BMS_INPUT_ID1, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData,CanData, 8, 17);//BMS <20><><EFBFBD><EFBFBD>
}
@@ -1346,8 +1360,6 @@ void canInterfaceInit(void)
subscribe(&un_sdo_output7, processSdoOutput7);
subscribe(&un_sdo_output8, processSdoOutput8);
timerStart(&can_timer_interface1,10,1);//1ms<6D><73><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
timerStart(&can_timer_interface2,100,1);//100ms<6D><73><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>

View File

@@ -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