|
@@ -34,7 +34,7 @@ FlagStatus MC_StarFlag = RESET;
|
|
|
|
|
|
/*************************局部函数定义***********************/
|
|
|
//限流值线性变化处理
|
|
|
-uint16_t MC_CurrentLimit_Linear_Process(uint16_t SetData, uint16_t PresentData)
|
|
|
+uint16_t MC_CurrentLimit_Linear_Process(uint16_t SetData, uint16_t PresentData, uint16_t AddCnt, uint16_t DecCnt)
|
|
|
{
|
|
|
int16_t ErrorData;
|
|
|
uint16_t Result;
|
|
@@ -42,11 +42,25 @@ uint16_t MC_CurrentLimit_Linear_Process(uint16_t SetData, uint16_t PresentData)
|
|
|
ErrorData = SetData - PresentData;
|
|
|
if(ErrorData > 0) //升速
|
|
|
{
|
|
|
- Result = PresentData + 5;
|
|
|
+ if(ErrorData >= AddCnt)
|
|
|
+ {
|
|
|
+ Result = PresentData + AddCnt;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Result = SetData;
|
|
|
+ }
|
|
|
}
|
|
|
else if(ErrorData < 0) //降速
|
|
|
{
|
|
|
- Result = PresentData - 1;
|
|
|
+ if((-ErrorData) >= DecCnt)
|
|
|
+ {
|
|
|
+ Result = PresentData - DecCnt;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Result = SetData;
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -57,13 +71,13 @@ uint16_t MC_CurrentLimit_Linear_Process(uint16_t SetData, uint16_t PresentData)
|
|
|
}
|
|
|
|
|
|
//助力模式判断处理
|
|
|
-MC_AssistRunMode_Struct_t MC_JudgeAsistRunMode_Process(uint16_t GasSensorData, MC_GearSt_Struct_t GearSt, TrueOrFalse_Flag_Struct_t Break_Flag)
|
|
|
+MC_AssistRunMode_Struct_t MC_JudgeAsistRunMode_Process(uint16_t GasSensorData, MC_GearSt_Struct_t GearSt, TrueOrFalse_Flag_Struct_t Break_Flag, TrueOrFalse_Flag_Struct_t GearSensor_Flag)
|
|
|
{
|
|
|
MC_AssistRunMode_Struct_t MC_AssistRunMode_Result;
|
|
|
|
|
|
if(MC_ErrorCode.Code == 0) // 无故障
|
|
|
{
|
|
|
- if((GearSt != MC_GearSt_OFF) && (Break_Flag == FALSE))
|
|
|
+ if((GearSt != MC_GearSt_OFF) && (Break_Flag == FALSE) && (GearSensor_Flag == FALSE))
|
|
|
{
|
|
|
//进入指拨模式
|
|
|
if(GasSensorData > 100)
|
|
@@ -97,12 +111,16 @@ MC_AssistRunMode_Struct_t MC_JudgeAsistRunMode_Process(uint16_t GasSensorData, M
|
|
|
{
|
|
|
MC_AssistRunMode_Result = MC_AssistRunMode_INVALID;
|
|
|
}
|
|
|
+ Power12V_Driver_Process(SET);
|
|
|
}
|
|
|
else //存在故障
|
|
|
{
|
|
|
MC_AssistRunMode_Result = MC_AssistRunMode_INVALID;
|
|
|
MC_ControlCode.GearSt = MC_GearSt_OFF;
|
|
|
MC_ControlCode_Back.GearSt = (MC_GearSt_Struct_t)~MC_ControlCode.GearSt;
|
|
|
+ #if 0
|
|
|
+ Power12V_Driver_Process(RESET);
|
|
|
+ #endif
|
|
|
}
|
|
|
|
|
|
return MC_AssistRunMode_Result;
|
|
@@ -339,16 +357,14 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if(MC_RunInfo.MotorSpeed > 300)
|
|
|
+ if(MC_RunInfo.MotorSpeed > 200)
|
|
|
{
|
|
|
- TorqueStopDelayTime = 327600 / MC_RunInfo.MotorSpeed + 200;
|
|
|
+ TorqueStopDelayTime = 163800 / MC_RunInfo.MotorSpeed;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
TorqueStopDelayTime = 1200;
|
|
|
}
|
|
|
- TorqueStopDelayTime = (TorqueStopDelayTime > 1200) ? 1200 : TorqueStopDelayTime;
|
|
|
- TorqueStopDelayTime = (TorqueStopDelayTime < 300) ? 300 : TorqueStopDelayTime;
|
|
|
|
|
|
if((HAL_GetTick() - TorqueStopDelayTimeCnt) > TorqueStopDelayTime)//超时1200ms
|
|
|
{
|
|
@@ -357,7 +373,7 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
|
|
|
}
|
|
|
|
|
|
//启动值判断
|
|
|
- if(MC_RunInfo.BikeSpeed > 60)
|
|
|
+ if(MC_RunInfo.BikeSpeed > 60)
|
|
|
{
|
|
|
TorqueStartData = (MC_TorqueCorrectParam.StarData < 200 ? 150 \
|
|
|
: (MC_TorqueCorrectParam.StarData > 700 ? 525 \
|
|
@@ -426,8 +442,8 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
|
|
|
Torque_Temp = (Torque_Temp > MC_AssisParam.Gear_ECO.Upper_Iq) ? MC_AssisParam.Gear_ECO.Upper_Iq : Torque_Temp;
|
|
|
|
|
|
//限流参数设置
|
|
|
- CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_ECO.CurrentMax_K * MC_ConfigParam.CurrentLimit * 1000 >> 17);
|
|
|
- CurrentLimitPresent = CurrentLimitSet * 100;
|
|
|
+ CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_ECO.CurrentMax_K * MC_ConfigParam.CurrentLimit * 1000 >> 17) * 100;
|
|
|
+ CurrentLimitPresent = MC_CurrentLimit_Linear_Process(CurrentLimitSet, CurrentLimitPresent, 5 ,1);
|
|
|
PID_IMax.hLower_Limit_Output = -(MC_AssisParam.Gear_ECO.Upper_Iq); //Lower Limit for Output limitation
|
|
|
PID_IMax.hUpper_Limit_Output = 0; //Upper Limit for Output limitation
|
|
|
PID_IMax.wLower_Limit_Integral = -(MC_AssisParam.Gear_ECO.Upper_Iq << 10); // 放大1024
|
|
@@ -457,8 +473,8 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
|
|
|
Torque_Temp = (Torque_Temp > MC_AssisParam.Gear_NORM.Upper_Iq) ? MC_AssisParam.Gear_NORM.Upper_Iq : Torque_Temp;
|
|
|
|
|
|
//限流参数设置
|
|
|
- CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_NORM.CurrentMax_K * MC_ConfigParam.CurrentLimit * 1000 >> 17);
|
|
|
- CurrentLimitPresent = CurrentLimitSet * 100;
|
|
|
+ CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_NORM.CurrentMax_K * MC_ConfigParam.CurrentLimit * 1000 >> 17) * 100;
|
|
|
+ CurrentLimitPresent = MC_CurrentLimit_Linear_Process(CurrentLimitSet, CurrentLimitPresent, 5 ,1);
|
|
|
PID_IMax.hLower_Limit_Output = -(MC_AssisParam.Gear_NORM.Upper_Iq); //Lower Limit for Output limitation
|
|
|
PID_IMax.hUpper_Limit_Output = 0; //Upper Limit for Output limitation
|
|
|
PID_IMax.wLower_Limit_Integral = -(MC_AssisParam.Gear_NORM.Upper_Iq << 10); // 放大1024
|
|
@@ -489,7 +505,7 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
|
|
|
|
|
|
//限流参数设置
|
|
|
CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_SPORT.CurrentMax_K * MC_ConfigParam.CurrentLimit * 1000 >> 17) * MC_CadenceLimit_K;
|
|
|
- CurrentLimitPresent = MC_CurrentLimit_Linear_Process(CurrentLimitSet, CurrentLimitPresent);
|
|
|
+ CurrentLimitPresent = MC_CurrentLimit_Linear_Process(CurrentLimitSet, CurrentLimitPresent, 5 ,1);
|
|
|
PID_IMax.hLower_Limit_Output = -(MC_AssisParam.Gear_SPORT.Upper_Iq); //Lower Limit for Output limitation
|
|
|
PID_IMax.hUpper_Limit_Output = 0; //Upper Limit for Output limitation
|
|
|
PID_IMax.wLower_Limit_Integral = -(MC_AssisParam.Gear_SPORT.Upper_Iq << 10); // 放大1024
|
|
@@ -520,7 +536,7 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
|
|
|
|
|
|
//限流参数设置
|
|
|
CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_TURBO.CurrentMax_K * MC_ConfigParam.CurrentLimit * 1000 >> 17) * MC_CadenceLimit_K;
|
|
|
- CurrentLimitPresent = MC_CurrentLimit_Linear_Process(CurrentLimitSet, CurrentLimitPresent);
|
|
|
+ CurrentLimitPresent = MC_CurrentLimit_Linear_Process(CurrentLimitSet, CurrentLimitPresent, 5 ,1);
|
|
|
PID_IMax.hLower_Limit_Output = -(MC_AssisParam.Gear_TURBO.Upper_Iq); //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 << 10); // 放大1024
|
|
@@ -548,7 +564,7 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
|
|
|
|
|
|
//限流参数设置
|
|
|
CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_SMART.CurrentMax_K * MC_ConfigParam.CurrentLimit * 1000 >> 17) * MC_CadenceLimit_K;
|
|
|
- CurrentLimitPresent = MC_CurrentLimit_Linear_Process(CurrentLimitSet, CurrentLimitPresent);
|
|
|
+ CurrentLimitPresent = MC_CurrentLimit_Linear_Process(CurrentLimitSet, CurrentLimitPresent, 5 ,1);
|
|
|
PID_IMax.hLower_Limit_Output = -(MC_AssisParam.Gear_SMART.Upper_Iq); //Lower Limit for Output limitation
|
|
|
PID_IMax.hUpper_Limit_Output = 0; //Upper Limit for Output limitation
|
|
|
PID_IMax.wLower_Limit_Integral = -(MC_AssisParam.Gear_SMART.Upper_Iq << 10); // 放大1024
|
|
@@ -736,13 +752,18 @@ void MC_ControlParam_Init(void)
|
|
|
}
|
|
|
|
|
|
//控制参数输入值计算
|
|
|
-void MC_CalParam_Cal(MC_WorkMode_Struct_t p_MC_WorkMode, ADC_SensorData_Struct_t p_ADC_SensorData, MC_GearSt_Struct_t GearSt, TrueOrFalse_Flag_Struct_t Break_Flag, MC_CalParam_Struct_t* p_MC_CalParam)
|
|
|
+void MC_CalParam_Cal(MC_WorkMode_Struct_t p_MC_WorkMode, \
|
|
|
+ ADC_SensorData_Struct_t p_ADC_SensorData, \
|
|
|
+ MC_GearSt_Struct_t GearSt, \
|
|
|
+ TrueOrFalse_Flag_Struct_t Break_Flag, \
|
|
|
+ TrueOrFalse_Flag_Struct_t GearSensor_Flag, \
|
|
|
+ MC_CalParam_Struct_t* p_MC_CalParam)
|
|
|
{
|
|
|
MC_AssistRunMode_Struct_t MC_AssistRunMode_Temp;
|
|
|
static FlagStatus MC_AssistRunMode_ShiftFlag = RESET; //电机助力模式切换标志
|
|
|
|
|
|
//根据指拨信号、助力档位指令、刹车信号判断助力模式
|
|
|
- MC_AssistRunMode_Temp = MC_JudgeAsistRunMode_Process(p_ADC_SensorData.GasSensor, GearSt, Break_Flag);
|
|
|
+ MC_AssistRunMode_Temp = MC_JudgeAsistRunMode_Process(p_ADC_SensorData.GasSensor, GearSt, Break_Flag, GearSensor_Flag);
|
|
|
|
|
|
//发生助力模式切换时,清空变量
|
|
|
if(MC_AssistRunMode_Temp != p_MC_CalParam->AssistRunMode)
|