stancecoke said:
casainho said:
Why do you think the users of that forum do not write in EN, why they don't prefer to write here on the official forum thread??
Because it's much easier to write in your native language?! :wink:
Then I would be alone on this project, talking in portuguese on the portuguese forum "Nova Energia". I think we all understand that having devs from Portugal, China, German, etc, means we really need to write in EN.
Maybe you can persuade them to join us here?
stancecoke said:
OK, can I help at any point? A first try to limit battery current is implemented in the torquesensor branch (update_setpoint) already.
Maybe implement the PI controller (look as I did on the EUC firmware). We will need that kind of controller for ID current also (I think) and for sure we will need for speed control.
I think it should run on main and with higher priority (higher than throttle/PAS) and I don't know the frequency, but maybe 1/100 second?? We will have new read IQ values every 2 or 1ms max and they are low pass filtered so 10 or 20ms seems a good value for the PI controller frequency.
No floats, 8 bits would be great.
// Calculate phase/angle correction value to try keep id current = 0
//------------------------------------------------------------------------
static float correction_value = 0;
// I
correction_value = qfp_fsub(correction_value, qfp_fmul(K_POSITION_CORRECTION_VALUE, id));
// D
static float id_old = 0;
float delta = qfp_fsub(id, id_old);
id_old = id;
correction_value = qfp_fsub(correction_value, qfp_fmul(D_POSITION_CORRECTION_VALUE, delta));
if ((duty_cycle < 5 && duty_cycle > -5) || motor_speed_erps < 80) // avoid PI controller windup
{ // motor_speed_erps < 80 seems a good value to avoid motor stalling at start up, very low speed
correction_value = 0.0;
}
if (correction_value > 30.0) { correction_value = 30.0; }
if (correction_value < -30.0) { correction_value = -30.0; }
position_correction_value = (int) correction_value;
// ------------------------------------------------------------------------
https://github.com/EGG-electric-unicycle/firmware-gen2_boards/blob/modifiedFOC-motorMicroWorks30kmh/motor_foc.c