Skip to content

Commit

Permalink
More reliable pressed throttle detection
Browse files Browse the repository at this point in the history
Smoother over temperature derating
Limit potmax to 3500 to prevent using over range pedal connection
Add uptime counter, can be used as CAN alive counter
In SINE firmware filter idc for smoother battery current derating
  • Loading branch information
jsphuebner committed Jun 5, 2024
1 parent 3037f14 commit 9e7d887
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
9 changes: 5 additions & 4 deletions include/param_prj.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#define VERSION 5.34
#define VERSION 5.35

/* Entries should be ordered as follows:
1. Saveable parameters
2. Temporary parameters
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 \
Expand Down Expand Up @@ -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 ) \
Expand Down Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions include/throttle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libopeninv
Submodule libopeninv updated 1 files
+4 −4 src/terminal.cpp
4 changes: 3 additions & 1 deletion src/pwmgeneration-sine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand All @@ -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))
Expand Down
10 changes: 9 additions & 1 deletion src/stm32_sine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 8 additions & 6 deletions src/throttle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9e7d887

Please sign in to comment.