|
@@ -628,8 +628,8 @@ MC_CalParam_Struct_t MC_AssistRunMode_Cadence_Process(MC_GearSt_Struct_t GearSt)
|
|
|
return (p_MC_CalParam);
|
|
|
}
|
|
|
|
|
|
-//力矩模式处理 运动版
|
|
|
-MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_GearSt_Struct_t GearSt)
|
|
|
+//力矩模式处理
|
|
|
+MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_GearSt_Struct_t GearSt, uint16_t SenorDataByCadence)
|
|
|
{
|
|
|
MC_CalParam_Struct_t p_MC_CalParam = {MC_AssistRunMode_INVALID, 0, 0, RESET};
|
|
|
uint8_t TorqueAccStep = 0;//力矩上升斜率
|
|
@@ -783,6 +783,8 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
|
|
|
//力矩给定升降速处理
|
|
|
else
|
|
|
{
|
|
|
+ MC_TorqueProcess_Param.TorqueApp = SenorDataByCadence;
|
|
|
+
|
|
|
//按照助力档位调节力矩输入值
|
|
|
switch(GearSt)
|
|
|
{
|
|
@@ -805,7 +807,10 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
|
|
|
//控制输入给定减速斜率
|
|
|
TorqueDecStep = MC_AssisParam.Gear_ECO.DecCnt;
|
|
|
//随力矩输入调节助力比
|
|
|
- Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(100, MC_AssisParam.Gear_ECO.Gain_K, MC_AssisParam.Gear_ECO.Upper_Iq, MC_TorqueProcess_Param.TorqueApp)) >> 10);
|
|
|
+ //Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(100, MC_AssisParam.Gear_ECO.Gain_K, MC_AssisParam.Gear_ECO.Upper_Iq, MC_TorqueProcess_Param.TorqueApp)) >> 10);
|
|
|
+
|
|
|
+ Torque_Temp = (uint16_t)((uint32_t)MC_TorqueProcess_Param.TorqueApp * MC_AssisParam.Gear_ECO.Gain_K >> 10);
|
|
|
+
|
|
|
//根据助力增益调节助力比
|
|
|
Torque_Temp = Torque_Temp * MC_ConfigParam1.UserAdjParam_ECO.Assist_K_GAIN / 100;
|
|
|
//给定下限
|
|
@@ -840,7 +845,10 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
|
|
|
//控制输入给定减速斜率
|
|
|
TorqueDecStep = MC_AssisParam.Gear_NORM.DecCnt;
|
|
|
//随力矩输入调节助力比
|
|
|
- Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(100, MC_AssisParam.Gear_NORM.Gain_K, MC_AssisParam.Gear_NORM.Upper_Iq, MC_TorqueProcess_Param.TorqueApp)) >> 10);
|
|
|
+ // Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(100, MC_AssisParam.Gear_NORM.Gain_K, MC_AssisParam.Gear_NORM.Upper_Iq, MC_TorqueProcess_Param.TorqueApp)) >> 10);
|
|
|
+
|
|
|
+ Torque_Temp = (uint16_t)((uint32_t)MC_TorqueProcess_Param.TorqueApp * MC_AssisParam.Gear_NORM.Gain_K >> 10);
|
|
|
+
|
|
|
//根据助力增益调节助力比
|
|
|
Torque_Temp = Torque_Temp * MC_ConfigParam1.UserAdjParam_NORM.Assist_K_GAIN / 100;
|
|
|
//给定下限
|
|
@@ -875,7 +883,10 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
|
|
|
//控制输入给定减速斜率
|
|
|
TorqueDecStep = MC_AssisParam.Gear_SPORT.DecCnt;
|
|
|
//随力矩输入调节助力比
|
|
|
- Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(100, MC_AssisParam.Gear_SPORT.Gain_K, MC_AssisParam.Gear_SPORT.Upper_Iq, MC_TorqueProcess_Param.TorqueApp)) >> 10);
|
|
|
+ //Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(100, MC_AssisParam.Gear_SPORT.Gain_K, MC_AssisParam.Gear_SPORT.Upper_Iq, MC_TorqueProcess_Param.TorqueApp)) >> 10);
|
|
|
+
|
|
|
+ Torque_Temp = (uint16_t)((uint32_t)MC_TorqueProcess_Param.TorqueApp * MC_AssisParam.Gear_SPORT.Gain_K >> 10);
|
|
|
+
|
|
|
//根据助力增益调节助力比
|
|
|
Torque_Temp = Torque_Temp * MC_ConfigParam1.UserAdjParam_SPORT.Assist_K_GAIN / 100;
|
|
|
//给定下限
|
|
@@ -910,7 +921,11 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
|
|
|
//控制输入给定减速斜率
|
|
|
TorqueDecStep = MC_AssisParam.Gear_TURBO.DecCnt;
|
|
|
//随力矩输入调节助力比
|
|
|
- Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(100, MC_AssisParam.Gear_TURBO.Gain_K, MC_AssisParam.Gear_TURBO.Upper_Iq, MC_TorqueProcess_Param.TorqueApp)) >> 10);
|
|
|
+ // Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(100, MC_AssisParam.Gear_TURBO.Gain_K, MC_AssisParam.Gear_TURBO.Upper_Iq, MC_TorqueProcess_Param.TorqueApp)) >> 10);
|
|
|
+
|
|
|
+ Torque_Temp = (uint16_t)((uint32_t)MC_TorqueProcess_Param.TorqueApp * MC_AssisParam.Gear_TURBO.Gain_K >> 10);
|
|
|
+
|
|
|
+
|
|
|
//根据助力增益调节助力比
|
|
|
Torque_Temp = Torque_Temp * MC_ConfigParam1.UserAdjParam_TURBO.Assist_K_GAIN / 100;
|
|
|
//给定下限
|
|
@@ -1116,545 +1131,6 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
|
|
|
return (p_MC_CalParam);
|
|
|
}
|
|
|
|
|
|
-//力矩模式处理 城市版
|
|
|
-uint16_t candenceCount; //踏频磁环信号计数变量,全局变量
|
|
|
-
|
|
|
-uint16_t torqueApp;
|
|
|
-uint16_t torque_NM; //力矩值,单位NM
|
|
|
-uint16_t torqueRank=0; //由踏频采样后的力矩值,得出的力矩给定
|
|
|
-static uint16_t torqueRankLast=0; //力矩给定历史值
|
|
|
-static uint16_t torqueRankBak=0; //力矩给定历史值备份
|
|
|
-static uint8_t flagUpDown=0; //输入力矩上升、下降的标志位
|
|
|
-
|
|
|
-static int32_t tmpFltSum=0; //输入力矩滤波的静态变量
|
|
|
-int16_t tmpFlted=0; //输入力矩滤波的临时变量
|
|
|
-
|
|
|
-int16_t torqueApp2; //力矩计算的临时变量
|
|
|
-
|
|
|
-uint8_t flagCandence=0; //踏频信号更新标志
|
|
|
-int16_t torqueAppLag=0; //力局地经过加减速处理后的临时变量
|
|
|
-int16_t torqueAppRatio=0; //力矩值计算助力比后的临时变量
|
|
|
-
|
|
|
-int16_t torqueAppAccStep = 4; //力矩给定升速斜率
|
|
|
-int16_t torqueAppDecStep = 1; //力矩给定减速斜率
|
|
|
-
|
|
|
-uint16_t candenceBakAtTop=0; //踏频最大值备份
|
|
|
-uint16_t torqueByCandenceDec=0; //由踏频变化计算的力矩减弱量
|
|
|
-int16_t torqueDataFromCadence=0; //经过踏频信号采样的力矩值
|
|
|
-int32_t Taping_activeFlt=0; //踏频实时值滤波中间量
|
|
|
-int32_t Taping_activeFlted = 0; //踏频实时值滤波值
|
|
|
-
|
|
|
-#define TORQUE_TMP 28 //力矩AD值与1NM的换算系数
|
|
|
-
|
|
|
-MC_CalParam_Struct_t MC_AssistRunMode_Torque_compensation(uint16_t SenorData, MC_GearSt_Struct_t GearSt)
|
|
|
-{
|
|
|
- MC_CalParam_Struct_t p_MC_CalParam = {MC_AssistRunMode_INVALID, 0, 0, RESET};
|
|
|
- uint16_t TorqueStartData, TorqueStopData;//力矩启动值,力矩停机值
|
|
|
- int32_t Torque_Ref_Temp;
|
|
|
- static uint32_t TorqueStopDelayTimeCnt = 0;//低力矩停机计时
|
|
|
- uint16_t TorqueStopDelayTime;
|
|
|
- static int16_t IqRefByInPower;//限流计算结果
|
|
|
-
|
|
|
- static uint16_t CurrentLimitPresent; //限流实际值,做升降速处理
|
|
|
- uint16_t CurrentLimitSet;
|
|
|
-
|
|
|
- static FlagStatus SoftStartFlag = SET;
|
|
|
- static uint16_t SoftStartDelayTimeCount = 0;
|
|
|
- uint16_t SoftStartDelayTime = 0;
|
|
|
- uint16_t SoftStartAcc = 0;
|
|
|
-
|
|
|
- #if 0
|
|
|
- //输入三角波,用于测试
|
|
|
- static uint32_t WaveTime_Zero = 0;
|
|
|
- static uint32_t Time_Enter = 0;
|
|
|
- static uint16_t SensorDataDebug = 0;
|
|
|
- if((HAL_GetTick() - Time_Enter) > 10) // 超时10ms未进入,波形发生初始时刻清零
|
|
|
- {
|
|
|
- WaveTime_Zero = HAL_GetTick();
|
|
|
- }
|
|
|
- Time_Enter = HAL_GetTick();
|
|
|
- SensorDataDebug = TriangleWaveGenerate(WaveTime_Zero, 125, 250 ,1500);
|
|
|
- SenorData = SensorDataDebug;
|
|
|
- #endif
|
|
|
-
|
|
|
- MC_TorqueProcess_Param.TorqueApp = SenorData;
|
|
|
-
|
|
|
- /*为下一步抓取最大值,力矩需要滤波*/
|
|
|
- tmpFltSum += (((int32_t )SenorData << 10) - tmpFltSum) >> 7;
|
|
|
- tmpFlted = (int16_t)(tmpFltSum >> 10);
|
|
|
-
|
|
|
- torque_NM = tmpFlted / TORQUE_TMP ; //转换为单位NM 的变量
|
|
|
-
|
|
|
- //低力矩停机
|
|
|
- TorqueStopData = (MC_TorqueCorrectParam.StarData < 200) ? 100 : (MC_TorqueCorrectParam.StarData >> 1);
|
|
|
- if(MC_TorqueProcess_Param.TorqueApp >= (TorqueStopData))
|
|
|
- {
|
|
|
- TorqueStopDelayTimeCnt = HAL_GetTick();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- 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;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //启动值判断
|
|
|
- if(MC_RunInfo.BikeSpeed > 60)
|
|
|
- {
|
|
|
- TorqueStartData = (MC_TorqueCorrectParam.StarData < 200 ? 150 \
|
|
|
- : (MC_TorqueCorrectParam.StarData > 700 ? 525 \
|
|
|
- : (MC_TorqueCorrectParam.StarData * 3 / 4)));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- TorqueStartData = (MC_TorqueCorrectParam.StarData < 200 ? 150 \
|
|
|
- : (MC_TorqueCorrectParam.StarData > 700 ? 525 \
|
|
|
- : MC_TorqueCorrectParam.StarData));
|
|
|
- }
|
|
|
- if(MC_TorqueProcess_Param.TorqueApp >= TorqueStartData)
|
|
|
- {
|
|
|
- MC_TorqueProcess_Param.MotorStopLock_Flag = RESET;
|
|
|
- }
|
|
|
-
|
|
|
- //踏频反向或踏频停止停机
|
|
|
- if((MC_CadenceResult.Cadence_Dir == MC_Cadence_Backward) ||
|
|
|
- (MC_CadenceResult.IsStopFlag == TRUE)
|
|
|
- )
|
|
|
- {
|
|
|
- MC_TorqueProcess_Param.MotorStopLock_Flag = SET;
|
|
|
- }
|
|
|
-
|
|
|
- //停机状态,延时处理
|
|
|
- if(MC_TorqueProcess_Param.MotorStopLock_Flag == SET)
|
|
|
- {
|
|
|
- torqueRankBak = 0;
|
|
|
- torqueAppDecStep = 6;//84;
|
|
|
-
|
|
|
- if(MC_TorqueProcess_Param.TorqueRefEnd < 10)
|
|
|
- {
|
|
|
- MC_TorqueProcess_Param.TorqueRefEnd = 0;
|
|
|
- //停机处理
|
|
|
- MC_MotorStop(&MC_StarFlag);
|
|
|
- p_MC_CalParam.Foc_Flag = RESET;
|
|
|
- //缓启动标志置位
|
|
|
- SoftStartFlag = SET;
|
|
|
- SoftStartDelayTimeCount = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- MC_TorqueProcess_Param.TorqueRefEnd -= 7;
|
|
|
- MC_MotorStar(&MC_StarFlag);
|
|
|
- }
|
|
|
- torqueAppLag = MC_TorqueProcess_Param.TorqueRefEnd;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if(flagCandence==1)
|
|
|
- {
|
|
|
- flagCandence = 0;
|
|
|
-
|
|
|
- torqueRank = torqueDataFromCadence; //根据踏频磁环信号采样力矩值
|
|
|
-
|
|
|
- if(torqueRank > torqueRankLast) //比较本次与上次的值
|
|
|
- {
|
|
|
-
|
|
|
- if(flagUpDown==0)
|
|
|
- {
|
|
|
- //最低点
|
|
|
- }
|
|
|
-
|
|
|
- if(torqueRank > torqueRankBak) //与当前使用的值比较
|
|
|
- {
|
|
|
- torqueRankBak = torqueRank;
|
|
|
- candenceCount = 0;
|
|
|
- torqueAppDecStep = 1;
|
|
|
- torqueByCandenceDec = 0;
|
|
|
- }
|
|
|
-
|
|
|
- flagUpDown=1;// 力矩上升标志
|
|
|
- }
|
|
|
- else if(torqueRank < torqueRankLast)
|
|
|
- {
|
|
|
- if(flagUpDown==1)
|
|
|
- {
|
|
|
- //最高点
|
|
|
- torqueRankBak = torqueRankLast;
|
|
|
- candenceCount = 0;
|
|
|
- torqueAppDecStep = 1;//14;
|
|
|
-
|
|
|
- /*备份力矩最高点的踏频*/
|
|
|
- candenceBakAtTop = Taping_activeFlted;
|
|
|
- torqueByCandenceDec = 0;
|
|
|
- }
|
|
|
- flagUpDown=0; //降
|
|
|
- }
|
|
|
-
|
|
|
- torqueRankLast = torqueRank; //记录上一次的值
|
|
|
-
|
|
|
- if(candenceCount > 60) //没有力矩信号, 踏频信号超过360度,加大降速值,清零给定
|
|
|
- {
|
|
|
- torqueRankBak = 0;
|
|
|
- torqueAppDecStep = 6;//84;
|
|
|
- }
|
|
|
- else if(candenceCount > 35) //超过210度,没有力矩信号
|
|
|
- {
|
|
|
- torqueRankBak = 0;
|
|
|
- torqueAppDecStep = 2;
|
|
|
-
|
|
|
- if((Taping_activeFlted < (candenceBakAtTop - 3)) && (tmpFlted<100))
|
|
|
- {
|
|
|
- torqueAppDecStep = 6;
|
|
|
- }
|
|
|
- }
|
|
|
- else // (candenceCount < 35)
|
|
|
- {
|
|
|
- /*踏频降低,且力矩低*/
|
|
|
- if((Taping_activeFlted < (candenceBakAtTop - 3)) && (tmpFlted<100))
|
|
|
- {
|
|
|
- torqueByCandenceDec +=3;
|
|
|
- torqueAppDecStep = 6;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- torqueApp2 = torqueRankBak - torqueByCandenceDec;
|
|
|
- //torqueApp2 = torqueRankBak;
|
|
|
- torqueApp2 = torqueApp2 > 0 ? torqueApp2 : 0;
|
|
|
-
|
|
|
- //转换力矩值为力矩控制量
|
|
|
- torqueApp = torqueApp2 * TORQUE_TMP ;
|
|
|
-
|
|
|
- }/*if(flagCandence==1)*/
|
|
|
-
|
|
|
- if(GearSt == 0x33)
|
|
|
- {
|
|
|
- torqueAppRatio = ((int32_t)torqueApp * torqueApp / (MC_AssisParam.Gear_SMART.i_Sport_TH));
|
|
|
-
|
|
|
- torqueAppRatio = (int16_t)((int32_t)torqueAppRatio * MC_ConfigParam1.UserAdjParam_SMART.Assist_K_GAIN / 100); //上位机助力比增益调节
|
|
|
-
|
|
|
- //加速增益调节
|
|
|
- if(MC_ConfigParam1.UserAdjParam_SMART.StarModel_GAIN <= 80)
|
|
|
- {
|
|
|
- torqueAppAccStep = MC_AssisParam.Gear_SMART.AccCnt - 1;
|
|
|
- }
|
|
|
- else if(MC_ConfigParam1.UserAdjParam_SMART.StarModel_GAIN >= 120)
|
|
|
- {
|
|
|
- torqueAppAccStep = MC_AssisParam.Gear_SMART.AccCnt + 1;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- torqueAppAccStep = MC_AssisParam.Gear_SMART.AccCnt;
|
|
|
- }
|
|
|
-
|
|
|
- //给定上限
|
|
|
- torqueAppRatio = (torqueAppRatio > MC_AssisParam.Gear_SMART.Upper_Iq) ? MC_AssisParam.Gear_SMART.Upper_Iq : torqueAppRatio;
|
|
|
-
|
|
|
- //限流参数设置
|
|
|
- CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_SMART.CurrentMax_K * MC_ConfigParam1.CurrentLimit * 1000 >> 17) * MC_CadenceLimit_K;
|
|
|
- CurrentLimitPresent = MC_DataSet_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
|
|
|
- PID_IMax.wUpper_Limit_Integral = 0; // 放大1024
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- switch( GearSt & 0x0F )
|
|
|
- {
|
|
|
- case 1:
|
|
|
- //torqueAppRatio = torqueApp * 0.5;
|
|
|
- //torqueAppRatio = (int16_t)((uint32_t)(torqueApp * Coefficient_GainCal( 51 ,410, 1300, torqueApp)) >> 10 ); //0.4
|
|
|
- torqueAppRatio = (int16_t)((uint32_t)(torqueApp * Coefficient_GainCal( 51 ,MC_AssisParam.Gear_ECO.Gain_K, 1300, torqueApp)) >> 10 ); //0.4
|
|
|
- torqueAppRatio = (int16_t)((int32_t)torqueAppRatio * MC_ConfigParam1.UserAdjParam_ECO.Assist_K_GAIN / 100); //上位机助力比增益调节
|
|
|
-
|
|
|
- //加速增益调节
|
|
|
- if(MC_ConfigParam1.UserAdjParam_ECO.StarModel_GAIN <= 80)
|
|
|
- {
|
|
|
- torqueAppAccStep = MC_AssisParam.Gear_ECO.AccCnt - 1;
|
|
|
- }
|
|
|
- else if(MC_ConfigParam1.UserAdjParam_ECO.StarModel_GAIN >= 120)
|
|
|
- {
|
|
|
- torqueAppAccStep = MC_AssisParam.Gear_ECO.AccCnt + 1;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- torqueAppAccStep = MC_AssisParam.Gear_ECO.AccCnt;
|
|
|
- }
|
|
|
-
|
|
|
- //给定上限
|
|
|
- torqueAppRatio = (torqueAppRatio > MC_AssisParam.Gear_ECO.Upper_Iq) ? MC_AssisParam.Gear_ECO.Upper_Iq : torqueAppRatio;
|
|
|
- //限流参数设置
|
|
|
- CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_ECO.CurrentMax_K * MC_ConfigParam1.CurrentLimit * 1000 >> 17) * 100;
|
|
|
- CurrentLimitPresent = MC_DataSet_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
|
|
|
- PID_IMax.wUpper_Limit_Integral = 0; // 放大1024
|
|
|
-
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- //torqueAppRatio = torqueApp * 0.8;
|
|
|
- //torqueAppRatio = (int16_t)((uint32_t)(torqueApp * Coefficient_GainCal( 102 ,717, 1300, torqueApp)) >> 10 ); //0.7
|
|
|
- torqueAppRatio = (int16_t)((uint32_t)(torqueApp * Coefficient_GainCal( 102 ,MC_AssisParam.Gear_NORM.Gain_K, 1300, torqueApp)) >> 10 ); //0.7
|
|
|
- torqueAppRatio = (int16_t)((int32_t)torqueAppRatio * MC_ConfigParam1.UserAdjParam_NORM.Assist_K_GAIN / 100); //上位机助力比增益调节
|
|
|
-
|
|
|
- //加速增益调节
|
|
|
- if(MC_ConfigParam1.UserAdjParam_NORM.StarModel_GAIN <= 80)
|
|
|
- {
|
|
|
- torqueAppAccStep = MC_AssisParam.Gear_NORM.AccCnt - 1;
|
|
|
- }
|
|
|
- else if(MC_ConfigParam1.UserAdjParam_NORM.StarModel_GAIN >= 120)
|
|
|
- {
|
|
|
- torqueAppAccStep = MC_AssisParam.Gear_NORM.AccCnt + 1;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- torqueAppAccStep = MC_AssisParam.Gear_NORM.AccCnt;
|
|
|
- }
|
|
|
-
|
|
|
- //给定上限
|
|
|
- torqueAppRatio = (torqueAppRatio > MC_AssisParam.Gear_NORM.Upper_Iq) ? MC_AssisParam.Gear_NORM.Upper_Iq : torqueAppRatio;
|
|
|
-
|
|
|
- //限流参数设置
|
|
|
- CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_NORM.CurrentMax_K * MC_ConfigParam1.CurrentLimit * 1000 >> 17) * 100;
|
|
|
- CurrentLimitPresent = MC_DataSet_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
|
|
|
- PID_IMax.wUpper_Limit_Integral = 0; // 放大1024
|
|
|
-
|
|
|
- break;
|
|
|
-
|
|
|
- case 3:
|
|
|
- //torqueAppRatio = torqueApp * 1.0;
|
|
|
- //torqueAppRatio = (int16_t)((uint32_t)(torqueApp * Coefficient_GainCal( 204 ,1024, 1300, torqueApp)) >> 10 ); //1.0
|
|
|
- torqueAppRatio = (int16_t)((uint32_t)(torqueApp * Coefficient_GainCal( 204 , MC_AssisParam.Gear_SPORT.Gain_K, 1300, torqueApp)) >> 10 ); //1.0
|
|
|
- torqueAppRatio = (int16_t)((int32_t)torqueAppRatio * MC_ConfigParam1.UserAdjParam_SPORT.Assist_K_GAIN / 100); //上位机助力比增益调节
|
|
|
-
|
|
|
- //加速增益调节
|
|
|
- if(MC_ConfigParam1.UserAdjParam_SPORT.StarModel_GAIN <= 80)
|
|
|
- {
|
|
|
- torqueAppAccStep = MC_AssisParam.Gear_SPORT.AccCnt - 1;
|
|
|
- }
|
|
|
- else if(MC_ConfigParam1.UserAdjParam_SPORT.StarModel_GAIN >= 120)
|
|
|
- {
|
|
|
- torqueAppAccStep = MC_AssisParam.Gear_SPORT.AccCnt + 1;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- torqueAppAccStep = MC_AssisParam.Gear_SPORT.AccCnt;
|
|
|
- }
|
|
|
-
|
|
|
- //给定上限
|
|
|
- torqueAppRatio = (torqueAppRatio > MC_AssisParam.Gear_SPORT.Upper_Iq) ? MC_AssisParam.Gear_SPORT.Upper_Iq : torqueAppRatio;;
|
|
|
-
|
|
|
- //限流参数设置
|
|
|
- CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_SPORT.CurrentMax_K * MC_ConfigParam1.CurrentLimit * 1000 >> 17) * MC_CadenceLimit_K;
|
|
|
- CurrentLimitPresent = MC_DataSet_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
|
|
|
- PID_IMax.wUpper_Limit_Integral = 0; // 放大1024
|
|
|
-
|
|
|
- break;
|
|
|
-
|
|
|
- case 4:
|
|
|
- //torqueAppRatio = torqueApp * 1.5;
|
|
|
- //torqueAppRatio = (int16_t)((uint32_t)(torqueApp * Coefficient_GainCal( 307 ,1536, 1300, torqueApp)) >> 10 ); // 1.5
|
|
|
- torqueAppRatio = (int16_t)((uint32_t)(torqueApp * Coefficient_GainCal( 307 ,MC_AssisParam.Gear_TURBO.Gain_K, 1300, torqueApp)) >> 10 ); // 1.5
|
|
|
- torqueAppRatio = (int16_t)((int32_t)torqueAppRatio * MC_ConfigParam1.UserAdjParam_TURBO.Assist_K_GAIN / 100); //上位机助力比增益调节
|
|
|
-
|
|
|
- //加速增益调节
|
|
|
- if(MC_ConfigParam1.UserAdjParam_TURBO.StarModel_GAIN <= 80)
|
|
|
- {
|
|
|
- torqueAppAccStep = MC_AssisParam.Gear_TURBO.AccCnt - 1;
|
|
|
- }
|
|
|
- else if(MC_ConfigParam1.UserAdjParam_TURBO.StarModel_GAIN >= 120)
|
|
|
- {
|
|
|
- torqueAppAccStep = MC_AssisParam.Gear_TURBO.AccCnt + 1;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- torqueAppAccStep = MC_AssisParam.Gear_TURBO.AccCnt;
|
|
|
- }
|
|
|
-
|
|
|
- //给定上限
|
|
|
- torqueAppRatio = (torqueAppRatio > MC_AssisParam.Gear_TURBO.Upper_Iq) ? MC_AssisParam.Gear_TURBO.Upper_Iq : torqueAppRatio;
|
|
|
-
|
|
|
- //限流参数设置
|
|
|
- CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_TURBO.CurrentMax_K * MC_ConfigParam1.CurrentLimit * 1000 >> 17) * MC_CadenceLimit_K;
|
|
|
- CurrentLimitPresent = MC_DataSet_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
|
|
|
- PID_IMax.wUpper_Limit_Integral = 0; // 放大1024
|
|
|
-
|
|
|
- break;
|
|
|
-
|
|
|
- default:break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //给定上限
|
|
|
- torqueAppRatio = (torqueAppRatio > MC_AssisParam.Gear_TURBO.Upper_Iq) ? MC_AssisParam.Gear_TURBO.Upper_Iq : torqueAppRatio;
|
|
|
-
|
|
|
- //随车速调节助力比
|
|
|
- #if 0
|
|
|
- if(MC_ConfigParam1.StarModel == MC_StarMode_DYNAMIC)
|
|
|
- {
|
|
|
- torqueAppRatio = (uint16_t)((uint32_t)(torqueAppRatio * Function_Linear_3Stage(90, -2, MC_ConfigParam1.SpeedLimit * 10, 160, MC_RunInfo.BikeSpeed)) >> 10);
|
|
|
- }
|
|
|
- else if(MC_ConfigParam1.StarModel == MC_StarMode_SOFT)
|
|
|
- {
|
|
|
- torqueAppRatio = (uint16_t)((uint32_t)(torqueAppRatio * Function_Linear_3Stage(120, -3, MC_ConfigParam1.SpeedLimit * 10, 160, MC_RunInfo.BikeSpeed)) >> 10);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- torqueAppRatio = (uint16_t)((uint32_t)(torqueAppRatio * Function_Linear_3Stage(MC_ConfigParam1.SpeedLimit * 10, 0, MC_ConfigParam1.SpeedLimit * 10, 160, MC_RunInfo.BikeSpeed)) >> 10);
|
|
|
- }
|
|
|
- #elif 1
|
|
|
- torqueAppRatio = (uint16_t)((uint32_t)(torqueAppRatio * Function_Linear_3Stage(MC_ConfigParam1.SpeedLimit * 10, 0, MC_ConfigParam1.SpeedLimit * 10, 160, MC_RunInfo.BikeSpeed)) >> 10);
|
|
|
- #endif
|
|
|
-
|
|
|
- //力矩给定处理
|
|
|
- if(SoftStartFlag == SET) //启动处理
|
|
|
- {
|
|
|
- if(MC_ConfigParam1.StarModel == MC_StarMode_DYNAMIC)
|
|
|
- {
|
|
|
- SoftStartDelayTime = 100; //启动处理延时100ms
|
|
|
- SoftStartAcc = 10; //10ms递增0.1倍
|
|
|
- }
|
|
|
- else if(MC_ConfigParam1.StarModel == MC_StarMode_SOFT)
|
|
|
- {
|
|
|
- SoftStartDelayTime = 900; //启动处理延时900ms
|
|
|
- SoftStartAcc = 90; //90ms递增0.1倍
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- SoftStartDelayTime = 300; //启动处理延时300ms
|
|
|
- SoftStartAcc = 30; //30ms递增0.1倍
|
|
|
- }
|
|
|
- SoftStartDelayTimeCount++;
|
|
|
- if(SoftStartDelayTimeCount <= SoftStartDelayTime) // 缓启动过程,按照0.1倍率逐步增加加减速斜率
|
|
|
- {
|
|
|
- if(torqueAppRatio > torqueAppLag)
|
|
|
- {
|
|
|
- if((SoftStartDelayTimeCount % (10 - SoftStartDelayTimeCount / SoftStartAcc)) == 0)
|
|
|
- {
|
|
|
- torqueAppLag += torqueAppAccStep;
|
|
|
- if(torqueAppLag > torqueAppRatio)
|
|
|
- {
|
|
|
- torqueAppLag = torqueAppRatio;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else if(torqueAppRatio < torqueAppLag)
|
|
|
- {
|
|
|
- torqueAppLag -= torqueAppDecStep;
|
|
|
- if(torqueAppLag < torqueAppRatio)
|
|
|
- {
|
|
|
- torqueAppLag = torqueAppRatio;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- SoftStartDelayTimeCount = 0;
|
|
|
- SoftStartFlag = RESET;
|
|
|
- }
|
|
|
- }
|
|
|
- else //正常骑行
|
|
|
- {
|
|
|
- if(torqueAppRatio > torqueAppLag)
|
|
|
- {
|
|
|
- torqueAppLag += torqueAppAccStep;
|
|
|
- if(torqueAppLag > torqueAppRatio)
|
|
|
- {
|
|
|
- torqueAppLag = torqueAppRatio;
|
|
|
- }
|
|
|
- }
|
|
|
- else if(torqueAppRatio < torqueAppLag)
|
|
|
- {
|
|
|
- torqueAppLag -= torqueAppDecStep;
|
|
|
- if(torqueAppLag < torqueAppRatio)
|
|
|
- {
|
|
|
- torqueAppLag = torqueAppRatio;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- MC_TorqueProcess_Param.TorqueRefEnd = torqueAppLag;
|
|
|
- MC_TorqueProcess_Param.TorqueRefEnd = (MC_TorqueProcess_Param.TorqueRefEnd < 6) ? 6 : MC_TorqueProcess_Param.TorqueRefEnd;
|
|
|
-
|
|
|
- //限速点处理
|
|
|
- if( MC_SpeedSensorData.Speed_Data > (MC_ConfigParam1.SpeedLimit * 10 + 20) ) //限速值+2
|
|
|
- {
|
|
|
- MC_TorqueProcess_Param.MotorStopLock_Flag = SET;
|
|
|
- MC_TorqueProcess_Param.TorqueRefEnd = 0;
|
|
|
- //停机处理
|
|
|
- MC_MotorStop(&MC_StarFlag);
|
|
|
- }
|
|
|
- #if 0 //低于限速点启动电机
|
|
|
- else if(MC_RunInfo.BikeSpeed < ((MC_ConfigParam.SpeedLimit) * 10))
|
|
|
- {
|
|
|
- MC_MotorStar(&MC_StarFlag);
|
|
|
- }
|
|
|
- #elif 1 //低于断电点即启动电机
|
|
|
- else
|
|
|
- {
|
|
|
- MC_MotorStar(&MC_StarFlag);
|
|
|
- }
|
|
|
- #endif
|
|
|
- }
|
|
|
-
|
|
|
- #if 1
|
|
|
- static uint16_t K_ByVoltage_Set_Old = 1024;
|
|
|
- uint16_t K_ByVoltage_Set;
|
|
|
- static uint16_t K_ByVoltage_Result;
|
|
|
- uint16_t K_ByTemperature_Set;
|
|
|
- static uint16_t K_ByTemperature_Result;
|
|
|
-
|
|
|
- //根据电压调节输出
|
|
|
- K_ByVoltage_Set = MC_Cal_K_ByVoltage(MC_RunInfo.BusVoltage, MC_MotorParam.Rate_Voltage, K_ByVoltage_Set_Old);//根据母线电压计算衰减比例,递减
|
|
|
- K_ByVoltage_Set_Old = K_ByVoltage_Set;
|
|
|
- K_ByVoltage_Result = MC_DataSet_Linear_Process(K_ByVoltage_Set, K_ByVoltage_Result, 1, 1); //设定值与给定值线性处理
|
|
|
-
|
|
|
- //根据温度调节输出
|
|
|
- K_ByTemperature_Set = MC_Cal_K_ByTemperature(MC_RunInfo.T_Coil, MC_ConfigParam1.TempTH_Alarm); //根据温度计算衰减比例
|
|
|
- K_ByTemperature_Result = MC_DataSet_Linear_Process(K_ByTemperature_Set, K_ByTemperature_Result, 1, 1); //设定值与给定值线性处理
|
|
|
-
|
|
|
- #else
|
|
|
-
|
|
|
- uint16_t K_ByVoltage_Result = 1024;
|
|
|
- uint16_t K_ByTemperature_Result = 1024;
|
|
|
- #endif
|
|
|
-
|
|
|
- //限流计算
|
|
|
- IqRefByInPower = PID_Regulator(CurrentLimitPresent / 100, (MC_RunInfo.BusCurrent >> 7), &PID_IMax);
|
|
|
-
|
|
|
- Torque_Ref_Temp = ((int32_t)MC_TorqueProcess_Param.TorqueRefEnd * K_ByVoltage_Result) >> 10;
|
|
|
- Torque_Ref_Temp = (Torque_Ref_Temp * K_ByTemperature_Result) >> 10;
|
|
|
- Torque_Ref_Temp = (Torque_Ref_Temp + IqRefByInPower) >> 1;
|
|
|
-
|
|
|
- p_MC_CalParam.Ref_Torque = (int16_t)Torque_Ref_Temp;
|
|
|
- p_MC_CalParam.Foc_Flag = SET;
|
|
|
- p_MC_CalParam.AssistRunMode = MC_AssistRunMode_TORQUE;
|
|
|
-
|
|
|
- return (p_MC_CalParam);
|
|
|
-}
|
|
|
|
|
|
/******************************全局函数定义*****************************/
|
|
|
//传感器初始化
|
|
@@ -1815,10 +1291,7 @@ void MC_CalParam_Cal(MC_WorkMode_Struct_t p_MC_WorkMode, \
|
|
|
case MC_AssistRunMode_TORQUE:
|
|
|
{
|
|
|
//计算FOC控制输入
|
|
|
- //*p_MC_CalParam = MC_AssistRunMode_Torque_Process(p_ADC_SensorData.TorqueSensor, GearSt);
|
|
|
-
|
|
|
- *p_MC_CalParam = MC_AssistRunMode_Torque_compensation(p_ADC_SensorData.TorqueSensor, GearSt);
|
|
|
-
|
|
|
+ *p_MC_CalParam = MC_AssistRunMode_Torque_Process(p_ADC_SensorData.TorqueSensor, GearSt, torqueByCadence_180);
|
|
|
//助力模式切换标志复位
|
|
|
MC_AssistRunMode_ShiftFlag = RESET;
|
|
|
break;
|