|
@@ -247,29 +247,27 @@ MC_CalParam_Struct_t MC_AssistRunMode_Gas_Process(uint16_t SensorData, MC_GearSt
|
|
|
|
|
|
/*车轮速度使用原始数据,滤波后的数据有滞后,影响控制回路*/
|
|
|
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;
|
|
|
-
|
|
|
+ SpdMotorDivWheelFlt += ((Tmp << 8) - SpdMotorDivWheelFlt) >> 6;
|
|
|
+ SpdMotorDivWheelFlted = SpdMotorDivWheelFlt >> 8;
|
|
|
|
|
|
/*在电机转速与车轮速比值,与实际速比一致时,更新速比*/
|
|
|
- if( ( MC_RunInfo.MotorSpeed > 100 ) && ( wheelSpeed > 0 ))
|
|
|
+ if(( MC_RunInfo.MotorSpeed > 100 ) && ( wheelSpeed > 0 ))
|
|
|
{
|
|
|
/*加速时,更新速比,比较法*/
|
|
|
if((wheelSpeed - wheelSpeedPre ) > 5)
|
|
|
{
|
|
|
- if(( MC_RunInfo.MotorSpeed - DbSpdMotorPre )>0)
|
|
|
+ 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时,认为是空载,此时不更新速比
|
|
@@ -292,24 +290,25 @@ MC_CalParam_Struct_t MC_AssistRunMode_Gas_Process(uint16_t SensorData, MC_GearSt
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ 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;
|
|
|
- //if(((int16_t)wheelSpeed - (int16_t)dbSpdWheelSet) < 100 )
|
|
|
- //|| (dbSpdWheelSet < 50 ) )
|
|
|
-// {
|
|
|
-
|
|
|
+ /*调试用,根据车速限速值,换算指拨对应的设定车速*/
|
|
|
+ dbSpdWheelSet = (Tmp * MC_ConfigParam1.SpeedLimit * 10 )>> 11;
|
|
|
+
|
|
|
/*电机转速设定,根据指拨大小、车轮限速值和速比,换算*/
|
|
|
SpeedSet = ((Tmp * MC_ConfigParam1.SpeedLimit * SpdProportion) / 10 >> 11); //(Tmp >> 11) * cd_Speedlimit * ( SpdProportion / 10)
|
|
|
- //SpeedSet = ((Tmp * cd_MotorSpeed) >> 11); //调试
|
|
|
|
|
|
//超过限速值,设定电机转速为0
|
|
|
- if(wheelSpeed > (MC_ConfigParam1.SpeedLimit * 10 + 10))
|
|
|
+ if(wheelSpeed > (MC_ConfigParam1.SpeedLimit * 10 + 20))
|
|
|
{
|
|
|
SpeedSet = 0;
|
|
|
}
|
|
@@ -317,29 +316,29 @@ MC_CalParam_Struct_t MC_AssistRunMode_Gas_Process(uint16_t SensorData, MC_GearSt
|
|
|
SpeedSet = (SpeedSet > 0) ? SpeedSet : 0;
|
|
|
SpeedSet = (SpeedSet < SpeedMax) ? SpeedSet : SpeedMax;
|
|
|
|
|
|
-
|
|
|
- switch (GearSt & 0x0F)//Help_mode:bit4: 0-力矩模式,1-踏频模式;低四位表示助力档位
|
|
|
+ //根据档位调整加速度
|
|
|
+ switch (GearSt & 0x0F)
|
|
|
{
|
|
|
case 0x01:
|
|
|
- accStep = StepCalc(SpeedMax,1,6500);
|
|
|
+ accStep = StepCalc(SpeedMax, 1, 6500);
|
|
|
break;
|
|
|
case 0x02:
|
|
|
- accStep = StepCalc(SpeedMax,1,6000);
|
|
|
+ accStep = StepCalc(SpeedMax, 1, 6000);
|
|
|
break;
|
|
|
case 0x03:
|
|
|
- accStep = StepCalc(SpeedMax,1,5500);
|
|
|
+ accStep = StepCalc(SpeedMax, 1, 5500);
|
|
|
break;
|
|
|
case 0x04:
|
|
|
- accStep = StepCalc(SpeedMax,1,5000);
|
|
|
+ accStep = StepCalc(SpeedMax, 1, 5000);
|
|
|
break;
|
|
|
default:
|
|
|
/*计算周期1ms, 加减速时间为 5.00s 加减速步进计算*/
|
|
|
- accStep = StepCalc(SpeedMax,1,5000);
|
|
|
+ accStep = StepCalc(SpeedMax, 1, 5000);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
/*减速步进*/
|
|
|
- decStep = StepCalc(SpeedMax,1,1000);
|
|
|
+ decStep = StepCalc(SpeedMax, 1, 1000);
|
|
|
|
|
|
/* 跟踪启动 */
|
|
|
if(MC_CalParam.Foc_Flag == RESET)
|
|
@@ -353,24 +352,85 @@ MC_CalParam_Struct_t MC_AssistRunMode_Gas_Process(uint16_t SensorData, MC_GearSt
|
|
|
}
|
|
|
|
|
|
/*速度指令的加减速处理*/
|
|
|
- SpeedSetReal = accDecProcess(SpeedSet,accStep,decStep,&SpeedSetMiddle);
|
|
|
+ #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
|
|
|
|
|
|
- /*母线电流限流*/
|
|
|
- PID_IMax.hLower_Limit_Output= -(MC_AssisParam.Gear_TURBO.Upper_Iq / 2); //Lower Limit for Output limitation
|
|
|
- PID_IMax.hUpper_Limit_Output= 0; //Upper Limit for Output limitation
|
|
|
- PID_IMax.wLower_Limit_Integral = -((MC_AssisParam.Gear_TURBO.Upper_Iq / 2) << 10); // 放大1024
|
|
|
- PID_IMax.wUpper_Limit_Integral = 0; // 放大1024
|
|
|
- SpdMotorByIdc = PID_Regulator((MC_ConfigParam1.CurrentLimit * 1000) >> 7, MC_RunInfo.BusCurrent >> 7, &PID_ConstantPower); // 母线电流闭环
|
|
|
+ /*限制母线电流*/
|
|
|
+ #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档的力矩参数*/
|
|
|
+ //最大力矩为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);
|
|
|
-// PID_MotorSpd.wLower_Limit_Integral = -((ContrlParam.Gear_4st.Upper_Iq / 2) << 10); // 放大1024
|
|
|
-// PID_MotorSpd.wUpper_Limit_Integral = ((ContrlParam.Gear_4st.Upper_Iq / 2) << 10); // 放大1024
|
|
|
- TorQueBySpd = PID_Regulator(SpeedSetReal, \
|
|
|
- MC_RunInfo.MotorSpeed , \
|
|
|
- &PID_MotorSpd); // 电机速度闭环输出
|
|
|
+ TorQueBySpd = PID_Regulator(SpeedSetReal, MC_RunInfo.MotorSpeed, &PID_MotorSpd);
|
|
|
|
|
|
TorQueBySpd += SpdMotorByIdc;
|
|
|
|
|
@@ -394,6 +454,7 @@ MC_CalParam_Struct_t MC_AssistRunMode_Gas_Process(uint16_t SensorData, MC_GearSt
|
|
|
|
|
|
uint16_t K_ByVoltage_Result = 1024;
|
|
|
uint16_t K_ByTemperature_Result = 1024;
|
|
|
+
|
|
|
#endif
|
|
|
|
|
|
//速度环控制量为0时停机,防止电机出现异响
|
|
@@ -409,7 +470,7 @@ MC_CalParam_Struct_t MC_AssistRunMode_Gas_Process(uint16_t SensorData, MC_GearSt
|
|
|
|
|
|
Ref_Speed_Temp = ((int32_t)TorQueBySpd * K_ByVoltage_Result) >> 10;
|
|
|
Ref_Speed_Temp = ((int32_t)Ref_Speed_Temp * K_ByTemperature_Result) >> 10;
|
|
|
-
|
|
|
+
|
|
|
p_MC_CalParam.Ref_Speed = (int16_t)(Ref_Speed_Temp);
|
|
|
p_MC_CalParam.Foc_Flag = SET;
|
|
|
p_MC_CalParam.AssistRunMode = MC_AssistRunMode_GAS;
|
|
@@ -1132,15 +1193,16 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_compensation(uint16_t SenorData, MC
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if(MC_RunInfo.MotorSpeed > 200)
|
|
|
- {
|
|
|
- TorqueStopDelayTime = 163800 / MC_RunInfo.MotorSpeed;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- TorqueStopDelayTime = 1200;
|
|
|
- }
|
|
|
-
|
|
|
+ if(MC_RunInfo.MotorSpeed > 200)
|
|
|
+ {
|
|
|
+ TorqueStopDelayTime = 218400 / MC_RunInfo.MotorSpeed; //60s / (电机转速 / 4.55 / 2.4) / 3,曲柄1/3圈
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ TorqueStopDelayTime = 1200;
|
|
|
+ }
|
|
|
+ TorqueStopDelayTime= (TorqueStopDelayTime < 500) ? 500 : TorqueStopDelayTime;
|
|
|
+
|
|
|
if((HAL_GetTick() - TorqueStopDelayTimeCnt) > TorqueStopDelayTime)//超时1200ms
|
|
|
{
|
|
|
MC_TorqueProcess_Param.MotorStopLock_Flag = SET;
|
|
@@ -1822,7 +1884,7 @@ void SpdProportion_calculate(void)
|
|
|
test_StandardDeviation = (int32_t)(SpdProportion_StandardDeviation );
|
|
|
SpdProportion_CAL_flag = 0;
|
|
|
/*更新速比*/
|
|
|
- if(test_StandardDeviation < 20)
|
|
|
+ if(test_StandardDeviation < 30)
|
|
|
{
|
|
|
SpdProportion = test_SpdProportionAver;
|
|
|
}
|