|
@@ -11,7 +11,7 @@ Bike_RatioCal_Struct_t Bike_RatioCalParam = {0,0,0,0,0};
|
|
|
//参数初始化
|
|
|
void BikeRatioCal_Init(UWORD Teeth_F, UWORD Teeth_B)
|
|
|
{
|
|
|
- Bike_RatioCalParam.RatioDefault = (Teeth_F << 10) / Teeth_B;
|
|
|
+ Bike_RatioCalParam.RatioDefault = 1 << 10;
|
|
|
Bike_RatioCalParam.RatioResult = Bike_RatioCalParam.RatioDefault;
|
|
|
}
|
|
|
|
|
@@ -19,44 +19,46 @@ void BikeRatioCal_Init(UWORD Teeth_F, UWORD Teeth_B)
|
|
|
void BikeRatioCal_Process(UWORD MotorSpeed, UWORD Cadence, UWORD BikeSpeedRpm, UWORD PedalTorqueNm, UWORD Current, Bike_RatioCal_Struct_t* p_Bike_RatioCal)
|
|
|
{
|
|
|
ULONG Speed_F, Speed_B; //前后牙盘转速 rpm Q8
|
|
|
- UBYTE Coasted_Flag = 1; //滑行或静止标志,1-滑行或静止
|
|
|
+ UBYTE Coasted_Flag = 0xFF; //滑行或静止标志,1-滑行,2-静止
|
|
|
|
|
|
//有效判断
|
|
|
if(BikeSpeedRpm > 20) //20rpm*60*2.19m/1000≈2.6km/h
|
|
|
{
|
|
|
- if((PedalTorqueNm > 50) && (Cadence > 10)) //5Nm 10rpm
|
|
|
+ if((PedalTorqueNm > 100) && (Cadence > 10)) //10Nm 10rpm
|
|
|
Coasted_Flag = 0;
|
|
|
else
|
|
|
{
|
|
|
if((MotorSpeed > 100) && (Current > 10)) //100rpm 0.1A
|
|
|
- {
|
|
|
Coasted_Flag = 0;
|
|
|
- }
|
|
|
+ else
|
|
|
+ Coasted_Flag = 1;
|
|
|
}
|
|
|
}
|
|
|
+ else
|
|
|
+ Coasted_Flag = 2;
|
|
|
|
|
|
//计算传动比
|
|
|
- if(Coasted_Flag == 0)
|
|
|
+ if(Coasted_Flag == 2) //静止更新为默认值
|
|
|
{
|
|
|
- //转速计算
|
|
|
- Speed_F = ((((ULONG)MotorSpeed * 56) > ((ULONG)Cadence * 614)) ? ((ULONG)MotorSpeed * 56) : ((ULONG)Cadence * 614)) >> 8; //max(电机转速/4.55*256,踏频*2.4*256)
|
|
|
- Speed_B = BikeSpeedRpm;
|
|
|
- //计算传动比 Q10
|
|
|
- p_Bike_RatioCal->RatioPer = (Speed_B << 10) / Speed_F;
|
|
|
- //限制计算结果
|
|
|
- p_Bike_RatioCal->RatioPer = (p_Bike_RatioCal->RatioPer < 200) ? 200 : ((p_Bike_RatioCal->RatioPer > 5000) ? 5000 : p_Bike_RatioCal->RatioPer);
|
|
|
+ p_Bike_RatioCal->RatioResult = p_Bike_RatioCal->RatioDefault;
|
|
|
+ p_Bike_RatioCal->RatioFltSum = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(Coasted_Flag == 0) //骑行或转把时计算
|
|
|
+ {
|
|
|
+ //转速计算
|
|
|
+ Speed_F = ((((ULONG)MotorSpeed * 56) > ((ULONG)Cadence * 614)) ? ((ULONG)MotorSpeed * 56) : ((ULONG)Cadence * 614)) >> 8; //max(电机转速/4.55*256,踏频*2.4*256)
|
|
|
+ Speed_B = BikeSpeedRpm;
|
|
|
+ //计算传动比 Q10
|
|
|
+ p_Bike_RatioCal->RatioPer = (Speed_B << 10) / Speed_F;
|
|
|
+ //限制计算结果
|
|
|
+ p_Bike_RatioCal->RatioPer = (p_Bike_RatioCal->RatioPer < 400) ? 400 : ((p_Bike_RatioCal->RatioPer > 1500) ? 1500 : p_Bike_RatioCal->RatioPer);
|
|
|
+ }
|
|
|
//计算结果滤波
|
|
|
- p_Bike_RatioCal->RatioFltSum += ((p_Bike_RatioCal->RatioPer << 10) - p_Bike_RatioCal->RatioFltSum) >> 4;
|
|
|
+ p_Bike_RatioCal->RatioFltSum += ((p_Bike_RatioCal->RatioPer << 10) - p_Bike_RatioCal->RatioFltSum) >> 8;
|
|
|
p_Bike_RatioCal->RatioFlt = p_Bike_RatioCal->RatioFltSum >> 10;
|
|
|
//目标值计算
|
|
|
p_Bike_RatioCal->RatioResult = p_Bike_RatioCal->RatioFlt;
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- p_Bike_RatioCal->RatioPer = p_Bike_RatioCal->RatioDefault;
|
|
|
- p_Bike_RatioCal->RatioResult = p_Bike_RatioCal->RatioDefault;
|
|
|
- p_Bike_RatioCal->RatioFlt = p_Bike_RatioCal->RatioDefault;
|
|
|
- p_Bike_RatioCal->RatioFltSum = 0;
|
|
|
- }
|
|
|
-
|
|
|
}
|