diff --git a/include/param_prj.h b/include/param_prj.h index 959d3ad..6a5e184 100644 --- a/include/param_prj.h +++ b/include/param_prj.h @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#define VERSION 5.34 +#define VERSION 5.35 /* Entries should be ordered as follows: 1. Saveable parameters @@ -25,7 +25,7 @@ 3. Display values */ //Next param id (increase when adding new parameter!): 159 -//Next value Id: 2053 +//Next value Id: 2055 /* category name unit min max default id */ #define MOTOR_PARAMETERS_COMMON \ @@ -108,8 +108,8 @@ PARAM_ENTRY(CAT_CHARGER, chargepwmax, "%", 0, 99, 90, 79 ) #define THROTTLE_PARAMETERS_COMMON \ - PARAM_ENTRY(CAT_THROTTLE,potmin, "dig", 0, 4095, 0, 17 ) \ - PARAM_ENTRY(CAT_THROTTLE,potmax, "dig", 0, 4095, 4095, 18 ) \ + PARAM_ENTRY(CAT_THROTTLE,potmin, "dig", 0, 3500, 0, 17 ) \ + PARAM_ENTRY(CAT_THROTTLE,potmax, "dig", 0, 3500, 3500, 18 ) \ PARAM_ENTRY(CAT_THROTTLE,pot2min, "dig", 0, 4095, 4095, 63 ) \ PARAM_ENTRY(CAT_THROTTLE,pot2max, "dig", 0, 4095, 4095, 64 ) \ PARAM_ENTRY(CAT_THROTTLE,potmode, POTMODES, 0, 6, 0, 82 ) \ @@ -197,6 +197,7 @@ VALUE_ENTRY(din_ocur, OKERR, 2030 ) \ VALUE_ENTRY(din_desat, OKERR, 2031 ) \ VALUE_ENTRY(din_bms, ONOFF, 2032 ) \ + VALUE_ENTRY(uptime, "10ms", 2054 ) \ VALUE_ENTRY(cpuload, "%", 2035 ) \ #define VALUES_SINE \ diff --git a/include/throttle.h b/include/throttle.h index ae5f1f9..4a7d23c 100644 --- a/include/throttle.h +++ b/include/throttle.h @@ -40,6 +40,7 @@ class Throttle static void FrequencyLimitCommand(float& finalSpnt, float frequency); static float RampThrottle(float finalSpnt); static void UpdateDynamicRegenTravel(float regenTravelMax, float frequency); + static bool IsThrottlePressed(int pot1); static int potmin[2]; static int potmax[2]; static float brknom; diff --git a/libopeninv b/libopeninv index 637f16c..6f33c67 160000 --- a/libopeninv +++ b/libopeninv @@ -1 +1 @@ -Subproject commit 637f16cc464277aab2a86f911a8d26a5cfb8f47f +Subproject commit 6f33c676cdc67c9a2bdd52530ff97eca1a98d287 diff --git a/src/pwmgeneration-sine.cpp b/src/pwmgeneration-sine.cpp index f54cf5c..f3c9af7 100644 --- a/src/pwmgeneration-sine.cpp +++ b/src/pwmgeneration-sine.cpp @@ -243,6 +243,7 @@ PwmGeneration::EdgeType PwmGeneration::CalcRms(s32fp il, EdgeType& lastEdge, s32 s32fp PwmGeneration::ProcessCurrents() { static s32fp currentMax[2]; + static s32fp idcFiltered = 0; static int samples[2] = { 0 }; static EdgeType lastEdge[2] = { PosEdge, PosEdge }; @@ -263,7 +264,8 @@ s32fp PwmGeneration::ProcessCurrents() s32fp idc = (SineCore::GetAmp() * rms) / SineCore::MAXAMP; idc = FP_MUL(idc, FP_FROMFLT(1.2247)); //multiply by sqrt(3)/sqrt(2) idc *= fslip < 0 ? -1 : 1; - Param::SetFixed(Param::idc, idc); + idcFiltered = IIRFILTER(idcFiltered, idc, Param::GetInt(Param::idcflt)); + Param::SetFixed(Param::idc, idcFiltered); } } if (CalcRms(il2, lastEdge[1], currentMax[1], rms, samples[1], il2PrevRms)) diff --git a/src/stm32_sine.cpp b/src/stm32_sine.cpp index 6e0e373..6792f80 100644 --- a/src/stm32_sine.cpp +++ b/src/stm32_sine.cpp @@ -149,7 +149,7 @@ static void Ms10Task(void) stt |= DigIo::emcystop_in.Get() || hwRev == HW_REV3 ? STAT_NONE : STAT_EMCYSTOP; stt |= DigIo::mprot_in.Get() ? STAT_NONE : STAT_MPROT; - stt |= Param::GetInt(Param::potnom) <= 0 ? STAT_NONE : STAT_POTPRESSED; + stt |= Throttle::IsThrottlePressed(Param::GetInt(Param::pot)) ? STAT_POTPRESSED : STAT_NONE; stt |= udc >= Param::GetFloat(Param::udcsw) ? STAT_NONE : STAT_UDCBELOWUDCSW; stt |= udc < Param::GetFloat(Param::udclim) ? STAT_NONE : STAT_UDCLIM; stt |= seenBrakePedal ? STAT_NONE : STAT_BRAKECHECK; @@ -245,6 +245,8 @@ static void Ms10Task(void) initWait--; } + Param::SetInt(Param::uptime, rtc_get_counter_val()); + if (Param::GetInt(Param::canperiod) == CAN_PERIOD_10MS) canMap->SendAll(); } @@ -346,6 +348,12 @@ static void UpgradeParameters() if (Param::Get(Param::offthrotregen) > 0) Param::Set(Param::offthrotregen, -Param::Get(Param::offthrotregen)); + s32fp maxPotMax = Param::GetAttrib(Param::potmax)->max; + s32fp potMax = Param::Get(Param::potmax); + + if (potMax > maxPotMax) + Param::SetFixed(Param::potmax, maxPotMax); + //Remove CAN mapping for safety critical values canMap->Remove(Param::pot); canMap->Remove(Param::pot2); diff --git a/src/throttle.cpp b/src/throttle.cpp index a015a01..bab4c4f 100644 --- a/src/throttle.cpp +++ b/src/throttle.cpp @@ -76,6 +76,12 @@ bool Throttle::CheckAndLimitRange(int* potval, uint8_t potIdx) return true; } +bool Throttle::IsThrottlePressed(int pot1) +{ + float percent = DigitsToPercent(pot1, 0); + return percent > brknom; +} + float Throttle::DigitsToPercent(int potval, int potidx) { if (potidx > 1) return 0; @@ -194,12 +200,8 @@ bool Throttle::HoldPosition(int distance, float& finalSpnt) bool Throttle::TemperatureDerate(float temp, float tempMax, float& finalSpnt) { - float limit = 0; - - if (temp <= tempMax) - limit = 100.0f; - else if (temp < (tempMax + 2.0f)) - limit = 50.0f; + float limit = (tempMax - temp) * 10; //derate 10% per °C as we approach tempMax + limit = MAX(0, limit); if (finalSpnt >= 0) finalSpnt = MIN(finalSpnt, limit);