Skip to content

Commit

Permalink
Added ffwstart parameter which defines where field weakening controll…
Browse files Browse the repository at this point in the history
…er starts to ramp up

Fixed rev limiter
  • Loading branch information
jsphuebner committed Sep 30, 2021
1 parent 9527823 commit 8134e2b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 17 deletions.
5 changes: 3 additions & 2 deletions include/param_prj.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#define VER 5.10.R
#define VER 5.11.R

/* Entries must be ordered as follows:
1. Saveable parameters (id != 0)
2. Temporary parameters (id = 0)
3. Display values
*/
//Next param id (increase when adding new parameter!): 135
//Next param id (increase when adding new parameter!): 138
//Next value Id: 2049
/* category name unit min max default id */

Expand Down Expand Up @@ -54,6 +54,7 @@
PARAM_ENTRY(CAT_MOTOR, curki, "", 0, 100000, 20000, 108 ) \
PARAM_ENTRY(CAT_MOTOR, curkifrqgain,"dig/Hz", 0, 1000, 50, 120 ) \
PARAM_ENTRY(CAT_MOTOR, fwkp, "", -10000, 0, -100, 118 ) \
PARAM_ENTRY(CAT_MOTOR, ffwstart, "Hz", 0, 1000, 200, 136 ) \
PARAM_ENTRY(CAT_MOTOR, syncofs, "dig", 0, 65535, 0, 70 ) \
PARAM_ENTRY(CAT_MOTOR, syncadv, "dig/Hz", 0, 65535, 10, 133 )

Expand Down
2 changes: 1 addition & 1 deletion libopeninv
Submodule libopeninv updated 1 files
+3 −4 src/foc.cpp
19 changes: 17 additions & 2 deletions src/pwmgeneration-foc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void PwmGeneration::Run()
{
static s32fp frqFiltered = 0, idcFiltered = 0;
int dir = Param::GetInt(Param::dir);
int moddedfwkp;
int kifrqgain = Param::GetInt(Param::curkifrqgain);
s32fp id, iq;

Expand All @@ -61,15 +62,29 @@ void PwmGeneration::Run()
frqFiltered = IIRFILTER(frqFiltered, frq, 8);
int moddedKi = curki + kifrqgain * FP_TOINT(frqFiltered);

if (frq < Param::Get(Param::ffwstart))
{
moddedfwkp = 0;
}
else if (frq > Param::Get(Param::fmax))
{
moddedfwkp = fwBaseGain;
}
else
{
moddedfwkp = fwBaseGain * (FP_TOINT(frq) - Param::GetInt(Param::ffwstart));
moddedfwkp/= Param::GetInt(Param::fmax) - Param::GetInt(Param::ffwstart);
}

qController.SetIntegralGain(moddedKi);
dController.SetIntegralGain(moddedKi);
fwController.SetProportionalGain(fwBaseGain * dir);
fwController.SetProportionalGain(moddedfwkp * dir);

ProcessCurrents(id, iq);

if (opmode == MOD_RUN && initwait == 0)
{
s32fp fwIdRef = idref <= 0 ? fwController.RunProportionalOnly(iq) : 0;
s32fp fwIdRef = fwController.RunProportionalOnly(iq);
dController.SetRef(idref + fwIdRef);
Param::SetFixed(Param::ifw, fwIdRef);
}
Expand Down
22 changes: 11 additions & 11 deletions src/throttle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ float Throttle::CalcThrottle(float potnom, float pot2nom, bool brkpedal)
else
{
potnom -= brknom;
potnom = 100.0 * potnom / (100.0 - brknom);
potnom = 100.0f * potnom / (100.0f - brknom);
}

return potnom;
Expand Down Expand Up @@ -139,7 +139,7 @@ float Throttle::CalcCruiseSpeed(int speed)
int speederr = cruiseSpeed - speedFiltered;

float potnom = speedkp * speederr;
potnom = MIN(100.0, potnom);
potnom = MIN(100.0f, potnom);
potnom = MAX(brkcruise, potnom);

return potnom;
Expand All @@ -150,16 +150,16 @@ bool Throttle::TemperatureDerate(float temp, float tempMax, float& finalSpnt)
float limit = 0;

if (temp <= tempMax)
limit = 100.0;
else if (temp < (tempMax + 2.0))
limit = 50.0;
limit = 100.0f;
else if (temp < (tempMax + 2.0f))
limit = 50.0f;

if (finalSpnt >= 0)
finalSpnt = MIN(finalSpnt, limit);
else
finalSpnt = MAX(finalSpnt, -limit);

return limit < 100.0;
return limit < 100.0f;
}

void Throttle::BmsLimitCommand(float& finalSpnt, bool dinbms)
Expand Down Expand Up @@ -195,16 +195,16 @@ void Throttle::IdcLimitCommand(float& finalSpnt, float idc)
{
if (finalSpnt >= 0)
{
s32fp idcerr = idcmax - idc;
s32fp res = idcerr * idckp;
float idcerr = idcmax - idc;
float res = idcerr * idckp;

res = MAX(0, res);
finalSpnt = MIN(res, finalSpnt);
}
else
{
s32fp idcerr = idcmin - idc;
s32fp res = idcerr * idckp;
float idcerr = idcmin - idc;
float res = idcerr * idckp;

res = MIN(0, res);
finalSpnt = MAX(res, finalSpnt);
Expand All @@ -222,7 +222,7 @@ void Throttle::FrequencyLimitCommand(float& finalSpnt, float frequency)
float frqerr = fmax - frqFiltered;
float res = frqerr * 4;

res = MAX(1, res);
res = MAX(0, res);
finalSpnt = MIN(res, finalSpnt);
}
}
2 changes: 1 addition & 1 deletion src/vehiclecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ void VehicleControl::GetTemps(float& tmphs, float &tmpm)
priusTempCoeff *= 2;
}

tmphs = 166.66 - tmphsi / priusTempCoeff;
tmphs = 166.66f - tmphsi / priusTempCoeff;
}
else if (snshs == TempMeas::TEMP_BMWI3HS)
{
Expand Down

0 comments on commit 8134e2b

Please sign in to comment.