|
@@ -207,25 +207,7 @@ MC_AssistRunMode_Struct_t MC_JudgeAsistRunMode_Process(MC_SupportFlag_Struct_t G
|
|
|
}
|
|
|
|
|
|
/*指拨模式相关变量*/
|
|
|
-
|
|
|
-static int32_t SpdMotorDivWheelFlt=0;
|
|
|
-int16_t SpdProportion=490; //车轮电机速度比
|
|
|
-static uint16_t SpdProportion_buff_CNT=0;
|
|
|
-uint8_t SpdProportion_CAL_flag=0;
|
|
|
-static uint16_t SpdProportion_Save_CNT=0;
|
|
|
-uint16_t SpdProportion_buff[100]={0};
|
|
|
-float SpdProportion_StandardDeviation=0;
|
|
|
-int32_t test_StandardDeviation=0;
|
|
|
-uint16_t test_SpdProportionAver=0;
|
|
|
int32_t SpeedSetMiddle=0;
|
|
|
-int16_t dbSpdWheelSet=0; //调试用
|
|
|
-
|
|
|
-int16_t wheelSpeed=0;
|
|
|
-static int16_t DbSpdMotorPre=0;
|
|
|
-static int16_t wheelSpeedPre=0;
|
|
|
-int16_t SpdMotorDivWheel=0;
|
|
|
-int16_t SpdMotorDivWheelFlted=0;
|
|
|
-int16_t SpeedMax = 0; // 最高时速
|
|
|
int16_t SpeedSet = 0; // 速度设定值
|
|
|
uint32_t accStep = 0; // 加速时间步进
|
|
|
uint32_t decStep = 0; // 减速时间步进
|
|
@@ -240,75 +222,18 @@ MC_CalParam_Struct_t MC_AssistRunMode_Gas_Process(uint16_t SensorData, MC_GearSt
|
|
|
int16_t TorQueBySpd = 0;
|
|
|
int32_t Ref_Speed_Temp;
|
|
|
int16_t SpdMotorByIdc = 0;
|
|
|
+ uint16_t SpeedMax = 235;
|
|
|
|
|
|
MC_CalParam_Struct_t p_MC_CalParam = {MC_AssistRunMode_INVALID, 0, 0, RESET};
|
|
|
|
|
|
- //...插入指拨处理
|
|
|
-
|
|
|
- /*车轮速度使用原始数据,滤波后的数据有滞后,影响控制回路*/
|
|
|
- wheelSpeed = (int16_t)MC_SpeedSensorData.Speed_Data;
|
|
|
-
|
|
|
- /*实时计算电机转速与车轮速的比值*/
|
|
|
- SpdMotorDivWheel = (uint32_t)(MC_RunInfo.MotorSpeed * 100) / wheelSpeed ;
|
|
|
- Tmp = SpdMotorDivWheel;
|
|
|
- SpdMotorDivWheelFlt += ((Tmp << 8) - SpdMotorDivWheelFlt) >> 6;
|
|
|
- SpdMotorDivWheelFlted = SpdMotorDivWheelFlt >> 8;
|
|
|
-
|
|
|
- /*在电机转速与车轮速比值,与实际速比一致时,更新速比*/
|
|
|
- if(( MC_RunInfo.MotorSpeed > 100 ) && ( wheelSpeed > 0 ))
|
|
|
- {
|
|
|
- /*加速时,更新速比,比较法*/
|
|
|
- if((wheelSpeed - wheelSpeedPre ) > 5)
|
|
|
- {
|
|
|
- if(( MC_RunInfo.MotorSpeed - DbSpdMotorPre ) > 0)
|
|
|
- {
|
|
|
- SpdProportion = SpdMotorDivWheel ;
|
|
|
- }
|
|
|
- DbSpdMotorPre = MC_RunInfo.MotorSpeed;
|
|
|
- }
|
|
|
- wheelSpeedPre = wheelSpeed;
|
|
|
-
|
|
|
- /*求标准差,速比稳定后,更新速比*/
|
|
|
- /*此处将数据保存到数组中,标准差计算,时间较长,放在主循环进行*/
|
|
|
- if((SpdProportion_CAL_flag==0) && (MC_CalParam.Ref_Speed > 25)) //电机力矩控制量低于25时,认为是空载,此时不更新速比
|
|
|
- {
|
|
|
- SpdProportion_Save_CNT++;
|
|
|
- /*40ms保存一次数据到数组*/
|
|
|
- if(SpdProportion_Save_CNT >= 40 )
|
|
|
- {
|
|
|
- SpdProportion_Save_CNT = 0;
|
|
|
-
|
|
|
- SpdProportion_buff[SpdProportion_buff_CNT] = SpdMotorDivWheelFlted;
|
|
|
- SpdProportion_buff_CNT++;
|
|
|
- if( SpdProportion_buff_CNT >=50 )
|
|
|
- {
|
|
|
- SpdProportion_buff_CNT = 0;
|
|
|
-
|
|
|
- /*标志位置1,主循环里求标准差*/
|
|
|
- SpdProportion_CAL_flag = 1;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- wheelSpeedPre = wheelSpeed;
|
|
|
- DbSpdMotorPre = MC_RunInfo.MotorSpeed;
|
|
|
- }
|
|
|
-
|
|
|
- /*电机最高速度,上位机配置参数*/
|
|
|
- SpeedMax = MC_MotorParam.Rate_Speed;
|
|
|
Tmp = SensorData + 50 ; //加50偏移量,确保能达到最大值2048
|
|
|
Tmp = Tmp > 2048 ? 2048 : Tmp;
|
|
|
|
|
|
- /*调试用,根据车速限速值,换算指拨对应的设定车速*/
|
|
|
- dbSpdWheelSet = (Tmp * MC_ConfigParam1.SpeedLimit * 10 )>> 11;
|
|
|
-
|
|
|
/*电机转速设定,根据指拨大小、车轮限速值和速比,换算*/
|
|
|
- SpeedSet = ((Tmp * MC_ConfigParam1.SpeedLimit * SpdProportion) / 10 >> 11); //(Tmp >> 11) * cd_Speedlimit * ( SpdProportion / 10)
|
|
|
-
|
|
|
+ SpeedSet = (Tmp * SpeedMax >> 11);//马达最高转速200rpm
|
|
|
+
|
|
|
//超过限速值,设定电机转速为0
|
|
|
- if(wheelSpeed > (MC_ConfigParam1.SpeedLimit * 10 + 20))
|
|
|
+ if(MC_RunInfo.BikeSpeed > (8 * 10))
|
|
|
{
|
|
|
SpeedSet = 0;
|
|
|
}
|
|
@@ -320,16 +245,16 @@ MC_CalParam_Struct_t MC_AssistRunMode_Gas_Process(uint16_t SensorData, MC_GearSt
|
|
|
switch (GearSt & 0x0F)
|
|
|
{
|
|
|
case 0x01:
|
|
|
- accStep = StepCalc(SpeedMax, 1, 6500);
|
|
|
+ accStep = StepCalc(SpeedMax, 1, 6912);
|
|
|
break;
|
|
|
case 0x02:
|
|
|
- accStep = StepCalc(SpeedMax, 1, 6000);
|
|
|
+ accStep = StepCalc(SpeedMax, 1, 5760);
|
|
|
break;
|
|
|
case 0x03:
|
|
|
- accStep = StepCalc(SpeedMax, 1, 5500);
|
|
|
+ accStep = StepCalc(SpeedMax, 1, 4800);
|
|
|
break;
|
|
|
case 0x04:
|
|
|
- accStep = StepCalc(SpeedMax, 1, 5000);
|
|
|
+ accStep = StepCalc(SpeedMax, 1, 4000);
|
|
|
break;
|
|
|
default:
|
|
|
/*计算周期1ms, 加减速时间为 5.00s 加减速步进计算*/
|
|
@@ -343,7 +268,6 @@ MC_CalParam_Struct_t MC_AssistRunMode_Gas_Process(uint16_t SensorData, MC_GearSt
|
|
|
/* 跟踪启动 */
|
|
|
if(MC_CalParam.Foc_Flag == RESET)
|
|
|
{
|
|
|
- //MotorStartFlg = 1;
|
|
|
if(MC_RunInfo.MotorSpeed > 100)
|
|
|
{
|
|
|
SpeedSetReal = MC_RunInfo.MotorSpeed;
|
|
@@ -351,83 +275,13 @@ MC_CalParam_Struct_t MC_AssistRunMode_Gas_Process(uint16_t SensorData, MC_GearSt
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /*速度指令的加减速处理*/
|
|
|
- #if 1 //根据档位设定最高速度
|
|
|
-
|
|
|
- switch(GearSt & 0x0F)
|
|
|
- {
|
|
|
- case 0x01:
|
|
|
- SpeedSetReal = accDecProcess((SpeedSet * 9) >> 4, accStep, decStep, &SpeedSetMiddle);
|
|
|
- break;
|
|
|
- case 0x02:
|
|
|
- SpeedSetReal = accDecProcess((SpeedSet * 11) >> 4, accStep, decStep, &SpeedSetMiddle);
|
|
|
- break;
|
|
|
- case 0x03:
|
|
|
- SpeedSetReal = accDecProcess((SpeedSet * 13) >> 4, accStep, decStep, &SpeedSetMiddle);
|
|
|
- break;
|
|
|
- case 0x04:
|
|
|
- SpeedSetReal = accDecProcess(SpeedSet, accStep, decStep, &SpeedSetMiddle);
|
|
|
- break;
|
|
|
- default:
|
|
|
- SpeedSetReal = accDecProcess(SpeedSet, accStep, decStep, &SpeedSetMiddle);
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- #else
|
|
|
-
|
|
|
+ //速度指令的加减速处理
|
|
|
SpeedSetReal = accDecProcess(SpeedSet, accStep, decStep, &SpeedSetMiddle);
|
|
|
-
|
|
|
- #endif
|
|
|
|
|
|
- /*限制母线电流*/
|
|
|
- #if 0 //根据档位设定最大电流,电流环在内环,不稳定
|
|
|
-
|
|
|
- static uint16_t CurrentLimitPresent; //限流实际值,做升降速处理
|
|
|
- uint16_t CurrentLimitSet; //限流设置值,不同助力档位更新
|
|
|
-
|
|
|
- switch(GearSt & 0x0F)
|
|
|
- {
|
|
|
- case 0x01://ECO
|
|
|
- {
|
|
|
- CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_ECO.CurrentMax_K * MC_ConfigParam1.CurrentLimit * 1000 >> 17);
|
|
|
- CurrentLimitPresent = MC_DataSet_Linear_Process(CurrentLimitSet, CurrentLimitPresent, 5 ,1);
|
|
|
- break;
|
|
|
- }
|
|
|
- case 0x02://NORM
|
|
|
- {
|
|
|
- CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_NORM.CurrentMax_K * MC_ConfigParam1.CurrentLimit * 1000 >> 17);
|
|
|
- CurrentLimitPresent = MC_DataSet_Linear_Process(CurrentLimitSet, CurrentLimitPresent, 5 ,1);
|
|
|
- break;
|
|
|
- }
|
|
|
- case 0x03://SPORT
|
|
|
- {
|
|
|
- CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_SPORT.CurrentMax_K * MC_ConfigParam1.CurrentLimit * 1000 >> 17);
|
|
|
- CurrentLimitPresent = MC_DataSet_Linear_Process(CurrentLimitSet, CurrentLimitPresent, 5 ,1);
|
|
|
- break;
|
|
|
- }
|
|
|
- case 0x04://TURBO
|
|
|
- {
|
|
|
- CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_TURBO.CurrentMax_K * MC_ConfigParam1.CurrentLimit * 1000 >> 17);
|
|
|
- CurrentLimitPresent = MC_DataSet_Linear_Process(CurrentLimitSet, CurrentLimitPresent, 5 ,1);
|
|
|
- break;
|
|
|
- }
|
|
|
- default://SMART
|
|
|
- {
|
|
|
- CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_SMART.CurrentMax_K * MC_ConfigParam1.CurrentLimit * 1000 >> 17);
|
|
|
- CurrentLimitPresent = MC_DataSet_Linear_Process(CurrentLimitSet, CurrentLimitPresent, 5 ,1);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- SpdMotorByIdc = PID_Regulator(CurrentLimitPresent, MC_RunInfo.BusCurrent >> 7, &PID_ConstantPower);
|
|
|
-
|
|
|
- #else
|
|
|
-
|
|
|
+ //限制母线电流
|
|
|
SpdMotorByIdc = PID_Regulator((MC_ConfigParam1.CurrentLimit * 1000) >> 7, MC_RunInfo.BusCurrent >> 7, &PID_ConstantPower);
|
|
|
|
|
|
- #endif
|
|
|
-
|
|
|
- /* 电机速度闭环 */
|
|
|
- //最大力矩为4档的力矩参数
|
|
|
+ //电机速度闭环
|
|
|
PID_MotorSpd.hLower_Limit_Output= -(MC_AssisParam.Gear_TURBO.Upper_Iq / 2);
|
|
|
PID_MotorSpd.hUpper_Limit_Output= (MC_AssisParam.Gear_TURBO.Upper_Iq / 2);
|
|
|
TorQueBySpd = PID_Regulator(SpeedSetReal, MC_RunInfo.MotorSpeed, &PID_MotorSpd);
|
|
@@ -1263,7 +1117,6 @@ void MC_CalParam_Cal(MC_WorkMode_Struct_t p_MC_WorkMode, \
|
|
|
MC_AssistRunMode_ShiftFlag = SET;
|
|
|
|
|
|
SpeedSetMiddle = 0; //指拨模式,清零速度中间量
|
|
|
- SpdMotorDivWheelFlt = 0;
|
|
|
}
|
|
|
}
|
|
|
//助力模式处理
|
|
@@ -1359,21 +1212,3 @@ void MC_MotorStar(FlagStatus* StarFlag)
|
|
|
*StarFlag = SET;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-/*
|
|
|
-指拨模式计算速比,计算费时,在主循环调用
|
|
|
-*/
|
|
|
-void SpdProportion_calculate(void)
|
|
|
-{
|
|
|
- if(SpdProportion_CAL_flag==1)
|
|
|
- {
|
|
|
- SpdProportion_StandardDeviation = Standard_deviation_aver(SpdProportion_buff, 50, &test_SpdProportionAver);
|
|
|
- test_StandardDeviation = (int32_t)(SpdProportion_StandardDeviation );
|
|
|
- SpdProportion_CAL_flag = 0;
|
|
|
- /*更新速比*/
|
|
|
- if(test_StandardDeviation < 30)
|
|
|
- {
|
|
|
- SpdProportion = test_SpdProportionAver;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|