Skip to content

Commit

Permalink
Removed kludges that dealt with the fact that the current controllers…
Browse files Browse the repository at this point in the history
… were misconfigured
  • Loading branch information
jsphuebner committed Jan 31, 2020
1 parent b4949d4 commit 8c0f476
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 52 deletions.
14 changes: 5 additions & 9 deletions include/param_prj.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#define VER 4.70.R
#define VER 4.71.R

/* Entries must be ordered as follows:
1. Saveable parameters (id != 0)
Expand Down Expand Up @@ -149,12 +149,10 @@
//Next param id (increase when adding new parameter!): 119
/* category name unit min max default id */
#define PARAM_LIST \
PARAM_ENTRY(CAT_MOTOR, curkp, "", 0, 10000, 64, 107 ) \
PARAM_ENTRY(CAT_MOTOR, curki, "", 0, 10000, 256, 108 ) \
PARAM_ENTRY(CAT_MOTOR, fwkp, "", 0, 10000, 1, 114 ) \
PARAM_ENTRY(CAT_MOTOR, fwkp2, "", -10000, 0, -1, 118 ) \
PARAM_ENTRY(CAT_MOTOR, dofsramp, "", 0, 10000, 1000, 117 ) \
PARAM_ENTRY(CAT_MOTOR, frqfac, "dig/Hz", -10000, 10000, 10, 116 ) \
PARAM_ENTRY(CAT_MOTOR, curkp, "", 0, 20000, 64, 107 ) \
PARAM_ENTRY(CAT_MOTOR, curki, "", 0, 100000, 20000, 108 ) \
PARAM_ENTRY(CAT_MOTOR, fwkp, "", 0, 10000, 100, 114 ) \
PARAM_ENTRY(CAT_MOTOR, fwkp2, "", -10000, 0, -80, 118 ) \
PARAM_ENTRY(CAT_MOTOR, dmargin, "Hz", -10000, 0, -1000, 113 ) \
PARAM_ENTRY(CAT_MOTOR, polepairs, "", 1, 16, 2, 32 ) \
PARAM_ENTRY(CAT_MOTOR, respolepairs,"", 1, 16, 1, 93 ) \
Expand Down Expand Up @@ -262,8 +260,6 @@
VALUE_ENTRY(cpuload, "%", 2035 ) \
VALUE_ENTRY(ud, "dig", 22035 ) \
VALUE_ENTRY(uq, "dig", 22035 ) \
VALUE_ENTRY(dofs, "dig", 22035 ) \
VALUE_ENTRY(qofs, "dig", 22035 ) \
VALUE_ENTRY(dspnt, "dig", 22035 ) \
VALUE_ENTRY(qspnt, "dig", 22035 )

Expand Down
49 changes: 7 additions & 42 deletions src/pwmgeneration-foc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,20 @@
#define DIGIT_TO_DEGREE(a) FP_FROMINT(angle) / (65536 / 360)

static int initwait = 0;
static bool regen = false;
static s32fp idref = 0;
static PiController qController;
static PiController dController;
static PiController dControllerRegen;
static PiController fwController;
static PiController fwController2;

void PwmGeneration::Run()
{
if (opmode == MOD_MANUAL || opmode == MOD_RUN || opmode == MOD_SINE)
if (opmode == MOD_MANUAL || opmode == MOD_RUN)
{
int dir = Param::GetInt(Param::dir);
uint16_t dc[3];
s32fp id, iq;
static int32_t fwIdRef = 0, udRamped = 0;
static int32_t fwIdRef = 0;

Encoder::UpdateRotorAngle(dir);

Expand All @@ -61,52 +59,32 @@ void PwmGeneration::Run()

ProcessCurrents(id, iq);

int32_t dofs = FP_TOINT(-Param::GetInt(Param::frqfac) * frq);
int32_t qofs = FP_TOINT(Param::GetInt(Param::frqfac) * frq);

dController.SetOffset(dofs);
qController.SetOffset(qofs);

if (opmode == MOD_RUN)
{
s32fp fwIdRef2 = fwController2.Run(iq);
dController.SetRef(idref + fwIdRef + fwIdRef2);
dControllerRegen.SetRef(idref + fwIdRef + fwIdRef2);
int32_t ud = regen ? dControllerRegen.Run(id) : dController.Run(id);

if (ud < udRamped)
{
udRamped = RAMPDOWN(udRamped, ud, Param::GetInt(Param::dofsramp));
}
else
{
udRamped = RAMPUP(udRamped, ud, Param::GetInt(Param::dofsramp));
}
}
else if (opmode == MOD_MANUAL)
{
idref = Param::Get(Param::manualid);
dController.SetRef(idref);
qController.SetRef(Param::Get(Param::manualiq));
udRamped = dController.Run(id);

}

int32_t qlimit = FOC::GetQLimit(udRamped);
int32_t ud = dController.Run(id);
int32_t qlimit = FOC::GetQLimit(ud);
qController.SetMinMaxY(-qlimit, qlimit);
int32_t uq = qController.Run(iq);
FOC::InvParkClarke(udRamped, uq, angle);
FOC::InvParkClarke(ud, uq, angle);
//Calculate extra field weakening current for the next cycle
fwIdRef = fwController.Run(FOC::GetTotalVoltage(udRamped, uq) >> 5);
fwIdRef = fwController.Run(FOC::GetTotalVoltage(ud, uq) >> 5);

s32fp idc = (iq * uq) / FOC::GetMaximumModulationIndex();

Param::SetFlt(Param::fstat, frq);
Param::SetFlt(Param::angle, DIGIT_TO_DEGREE(angle));
Param::SetInt(Param::ud, udRamped);
Param::SetInt(Param::ud, ud);
Param::SetInt(Param::uq, uq);
Param::SetInt(Param::qofs, qofs);
Param::SetInt(Param::dofs, dofs);
Param::SetFlt(Param::idc, idc);
Param::SetFlt(Param::dspnt, dController.GetRef());
Param::SetFlt(Param::qspnt, qController.GetRef());
Expand All @@ -116,7 +94,6 @@ void PwmGeneration::Run()
{
timer_disable_break_main_output(PWM_TIMER);
dController.ResetIntegrator();
dControllerRegen.ResetIntegrator();
qController.ResetIntegrator();
fwController.ResetIntegrator();
fwController2.ResetIntegrator();
Expand Down Expand Up @@ -171,31 +148,22 @@ void PwmGeneration::SetTorquePercent(s32fp torquePercent)
if (torquePercent < 0)
{
direction = Encoder::GetRotorDirection();
regen = true;
}
else
{
regen = false;
}

//s32fp id = FP_MUL(Param::Get(Param::throtid), ABS(torquePercent));
int32_t is = FP_TOINT(FP_MUL(Param::Get(Param::throtcur), direction * torquePercent));
int32_t id, iq;

FOC::Mtpa(is, id, iq);

qController.SetRef(FP_FROMINT(iq));
fwController2.SetRef(FP_FROMINT(iq));
//dController.SetRef(id);
idref = FP_FROMINT(id);
//dController.SetRef(idref);
}

void PwmGeneration::SetControllerGains(int kp, int ki, int fwkp, int fwkp2)
{
qController.SetGains(kp, ki);
dController.SetGains(kp, ki);
dControllerRegen.SetGains(kp, ki);
fwController.SetGains(fwkp, 0);
fwController2.SetGains(fwkp2, 0);
}
Expand All @@ -213,9 +181,6 @@ void PwmGeneration::PwmInit()
dController.ResetIntegrator();
dController.SetCallingFrequency(pwmfrq);
dController.SetMinMaxY(-maxVd, maxVd);
dControllerRegen.ResetIntegrator();
dControllerRegen.SetCallingFrequency(pwmfrq);
dControllerRegen.SetMinMaxY(-maxVd, maxVd);
fwController.ResetIntegrator();
fwController.SetCallingFrequency(pwmfrq);
fwController.SetMinMaxY(-FP_FROMINT(500), 0);
Expand Down
4 changes: 3 additions & 1 deletion src/throttle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ s32fp Throttle::CalcCruiseSpeed(int speed)
speedFiltered = IIRFILTER(speedFiltered, speed, speedflt);
int speederr = cruiseSpeed - speedFiltered;

s32fp potnom = MAX(FP_FROMINT(brkmax), MIN(FP_FROMINT(100), speedkp * speederr));
s32fp potnom = speedkp * speederr;
potnom = MIN(FP_FROMINT(100), potnom);
potnom = MAX(brkmax, potnom);

return potnom;
}
Expand Down

0 comments on commit 8c0f476

Please sign in to comment.