May have jumped the gun slightly with the last post, it's working but when compared side by side the differences are subtle.
Worth mentioning that I've dropped the current down to 100A for these as with yesterdays code odd things seemed to happen at higher currents (unfortunately didn't grab a plot).
First yesterdays code (latest OpenInverter build but with the old limiter disabled):
Bit of instability at the end but ok until you realise that the Id and Id currents are wandering all over the place and when the controller tries to add Ifw Id actually reduces!
Next with the new code that prevents Ifw above the critical current (higher Id due to Mtpa is still allowed) and a limiter that drives the operating point towards the critical current point if the amplitude gets too big:
Better but not perfect. Id is now pretty well controlled by Iq isn't. What is really interesting is that the limiter has actually tried to reduce the throttle to 0 (Ifw shows the throttle reduction in these plots, 256=full throttle, 0=no throttle at all). The reason for this is that Vq isn't allowed to go negative in the standard code.
Last plot with Vq allowed to go negative:
Now there is some oscillation appearing in the limiter at higher speeds but apart from that it looks pretty good, both Iq and Id are well controlled and at sensible values. Acceleration isn't bad and the PWM amplitudes are kept under control. The throttle limiter is also doing sensible things.
Now the problem - I don't know why Vq is limited to stay positive. I'm sure there is a good reason but want to fully understand it before even thinking of allowing it to go negative in real code!