Skip to content

Commit

Permalink
Merge branch 'master' into safer_can2
Browse files Browse the repository at this point in the history
  • Loading branch information
jsphuebner committed Aug 22, 2023
2 parents 358f66f + b2eca4e commit dacd3ea
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/pwmgeneration.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class PwmGeneration
static int GetCpuLoad();
static void SetChargeCurrent(float cur);
static void SetPolePairRatio(int ratio) { polePairRatio = ratio; }
static void SetFwCurMax(float c);

private:
enum EdgeType { NoEdge, PosEdge, NegEdge };
Expand Down
8 changes: 7 additions & 1 deletion src/pwmgeneration-foc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static s32fp idMtpa = 0, iqMtpa = 0;
static tim_oc_id ocChannels[3];
static PiController qController;
static PiController dController;
static s32fp fwCurMax = 0;

void PwmGeneration::Run()
{
Expand Down Expand Up @@ -74,7 +75,7 @@ void PwmGeneration::Run()
if (0 == frq) amplitudeErrFiltered = fwOutMax << shiftForFilter;

int vlim = amplitudeErrFiltered >> shiftForFilter;
s32fp ifw = ((fwOutMax - vlim) * Param::Get(Param::fwcurmax)) / fwOutMax;
s32fp ifw = ((fwOutMax - vlim) * fwCurMax) / fwOutMax;
Param::SetFixed(Param::ifw, ifw);

s32fp limitedIq = (vlim * iqMtpa) / fwOutMax;
Expand Down Expand Up @@ -143,6 +144,11 @@ void PwmGeneration::Run()
}
}

void PwmGeneration::SetFwCurMax(float cur)
{
fwCurMax = FP_FROMFLT(cur);
}

void PwmGeneration::SetTorquePercent(float torquePercent)
{
float is = Param::GetFloat(Param::throtcur) * torquePercent;
Expand Down
1 change: 0 additions & 1 deletion src/stm32_sine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ void Param::Change(Param::PARAM_NUM paramNum)
Throttle::idcmin = Param::GetFloat(Param::idcmin);
Throttle::idcmax = Param::GetFloat(Param::idcmax);
Throttle::idckp = Param::GetFloat(Param::idckp);
Throttle::fmax = Param::GetFloat(Param::fmax);
Throttle::accelflt = Param::GetInt(Param::accelflt);
Throttle::accelmax = Param::GetInt(Param::accelmax);

Expand Down
10 changes: 9 additions & 1 deletion src/vehiclecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ void VehicleControl::SelectDirection()
float VehicleControl::ProcessThrottle()
{
float throtSpnt = 0, finalSpnt;
const float fstat = Param::GetFloat(Param::fstat);

if ((int)Encoder::GetSpeed() < Param::GetInt(Param::throtramprpm))
Throttle::throttleRamp = Param::GetFloat(Param::throtramp);
Expand All @@ -273,9 +274,10 @@ float VehicleControl::ProcessThrottle()
if (hwRev != HW_TESLA)
Throttle::BmsLimitCommand(finalSpnt, Param::GetBool(Param::din_bms));

Throttle::fmax = Param::GetFloat(Param::fmax);
Throttle::UdcLimitCommand(finalSpnt, Param::GetFloat(Param::udc));
Throttle::IdcLimitCommand(finalSpnt, Param::GetFloat(Param::idc));
Throttle::FrequencyLimitCommand(finalSpnt, Param::GetFloat(Param::fstat));
Throttle::FrequencyLimitCommand(finalSpnt, fstat);
Throttle::AccelerationLimitCommand(finalSpnt, Encoder::GetSpeed());

if (Throttle::TemperatureDerate(Param::GetFloat(Param::tmphs), Param::GetFloat(Param::tmphsmax), finalSpnt))
Expand Down Expand Up @@ -312,6 +314,12 @@ float VehicleControl::ProcessThrottle()
finalSpnt *= Encoder::GetRotorDirection();
else //inconsistency here: in slip control negative always means regen
finalSpnt *= Param::GetInt(Param::dir);

//At 110% fmax start derating field weakening current just in case it has a torque producing current
Throttle::fmax = Param::GetFloat(Param::fmax) * 1.1f;
float fwPercent = 100;
Throttle::FrequencyLimitCommand(fwPercent, fstat);
PwmGeneration::SetFwCurMax(fwPercent * Param::GetFloat(Param::fwcurmax));
#endif // CONTROL
}

Expand Down

0 comments on commit dacd3ea

Please sign in to comment.