Skip to content

Commit

Permalink
Correct DC current calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
jsphuebner committed Feb 17, 2021
1 parent 1f7c469 commit ad0ee5d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion 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.99.R
#define VER 5.00.R

/* Entries must be ordered as follows:
1. Saveable parameters (id != 0)
Expand Down
2 changes: 1 addition & 1 deletion libopeninv
5 changes: 3 additions & 2 deletions src/pwmgeneration-foc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static int initwait = 0;
static int fwBaseGain = 0;
static s32fp idref = 0;
static int curki = 0;
static const s32fp dcCurFac = FP_FROMFLT(0.81649658092772603273 * 1.05); //sqrt(2/3)*1.05 (inverter losses)
static tim_oc_id ocChannels[3];
static PiController qController;
static PiController dController;
Expand Down Expand Up @@ -83,8 +84,8 @@ void PwmGeneration::Run()
int32_t uq = qController.Run(iq);
FOC::InvParkClarke(ud, uq, angle);

//This is probably not correct for IPM motors
s32fp idc = (iq * uq) / FOC::GetMaximumModulationIndex();
s32fp idc = (iq * uq + id * ud) / FOC::GetMaximumModulationIndex();
idc = FP_MUL(idc, dcCurFac);

Param::SetFlt(Param::fstat, frq);
Param::SetFlt(Param::angle, DIGIT_TO_DEGREE(angle));
Expand Down
5 changes: 3 additions & 2 deletions src/stm32_sine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,13 @@ extern void parm_Change(Param::PARAM_NUM paramNum)
case Param::throtmin:
case Param::idcmin:
case Param::idcmax:
case Param::brkmax:
//These are candidates to be frequently set by CAN, so we handle them separately
Throttle::throtmax = Param::Get(Param::throtmax);
Throttle::throtmin = Param::Get(Param::throtmin);
Throttle::idcmin = Param::Get(Param::idcmin);
Throttle::idcmax = Param::Get(Param::idcmax);
Throttle::brkmax = Param::Get(Param::brkmax);
break;
default:
can->SetNodeId(Param::GetInt(Param::nodeid));
Expand Down Expand Up @@ -366,19 +368,18 @@ extern "C" int main(void)
s.AddTask(Ms100Task, 100);

DigIo::prec_out.Set();
UpgradeParameters();

Terminal t(USART3, TermCmds);
terminal = &t;

if (hwRev == HW_REV1)
t.DisableTxDMA();

UpgradeParameters();
parm_Change(Param::PARAM_LAST);

while(1)
t.Run();
//term_Run();

return 0;
}
Expand Down

0 comments on commit ad0ee5d

Please sign in to comment.