PID control discussion

Official FreeEMS vanilla firmware development, the heart and soul of the system!
Post Reply
User avatar
Fred
Moderator
Posts: 15431
Joined: Tue Jan 15, 2008 2:31 pm
Location: Home sweet home!
Contact:

Re: PID control discussion

Post by Fred »

8InchesFlacid wrote:It would be awesome if there was something to tell you when the modes were being [fizzle] with, but there isn't.
Put something in! Seriously, there are existing spare vars that you can just populate now that you are coding in there (remember, I mentioned these before), and you may be able to commandeer some other unused vars temporarily ;-)

Also check for status bits for various things and change them to mean what you want. Things like this should be able to be hacked in pretty easily, even if it's not clean.

You can always boil your solution down to the essentials later if need be :-)

Fred.
DIYEFI.org - where Open Source means Open Source, and Free means Freedom
FreeEMS.org - the open source engine management system
FreeEMS dev diary and its comments thread and my turbo truck!
n00bs, do NOT PM or email tech questions! Use the forum!
The ever growing list of FreeEMS success stories!
User avatar
AbeFM
Post Whore!
Posts: 629
Joined: Sat Feb 16, 2008 12:11 am
Location: Sunny San Diego
Contact:

Re: PID control discussion

Post by AbeFM »

That might get me in a bit over my head? I'd have to figure out how to set these flags, which ones they are, etc etc. I love the idea, but if I can't get the idle working, I don't think I want to mess with more of it. Soon, maybe.
User avatar
Fred
Moderator
Posts: 15431
Joined: Tue Jan 15, 2008 2:31 pm
Location: Home sweet home!
Contact:

Re: PID control discussion

Post by Fred »

Well, the spare vars are EASY to use and there for EXACTLY that purpose :-)
DIYEFI.org - where Open Source means Open Source, and Free means Freedom
FreeEMS.org - the open source engine management system
FreeEMS dev diary and its comments thread and my turbo truck!
n00bs, do NOT PM or email tech questions! Use the forum!
The ever growing list of FreeEMS success stories!
User avatar
AbeFM
Post Whore!
Posts: 629
Joined: Sat Feb 16, 2008 12:11 am
Location: Sunny San Diego
Contact:

Re: PID control discussion

Post by AbeFM »

Uhg, I guess I'll have to check them out.


Latest issues:

Code: Select all



				//shift over values in error array each loop, a "time step". Z += 1
				ztrans_idle_error_array[2] = ztrans_idle_error_array[1];
				ztrans_idle_error_array[1] = ztrans_idle_error_array[0];

				ztrans_idle_error_array[0] = (targ_rpm - outpc.rpm);// / 20;	// Error is target - actual, removed typecasting, scale so K-gains have less effect


//output of the form: OUTPUT += Alpha * Error[0] - Beta * Error[1] + Gamma * Error[2]
//Note subtraction of the beta term prevents kP term from summing to infinity
//Note the IACmotor_Pos is large relative to the Alpha, Beta, Gamma terms since they are multiplied by the divided down error term
                            tmp1 = ((40 * (long)IACmotor_pos) // This is "+=" from Z-transform math
                            				+ (z_alpha * ztrans_idle_error_array[0])	//this is the "now" part
                            				- (z_beta * ztrans_idle_error_array[1])		//this is the "last time" part
                            				+ (z_gamma * ztrans_idle_error_array[2]))	//this is contribution from 2 loops ago
							/ 40;	//This is to scale the gain's contribution

                            IACmotor_pos = tmp1;	//Set output (valve pos) to calculated value
P = 10
I = D = 0

So, when I'm positive (above the target), the idle valve moves to full open, then ticks closed slowly with increasing RPM.

When I'm below the target, everything seems cool, valve sits at 0 for a (variable) number of RPM, then will tick slowly more open as RPM drop. It seems there's some initialization taking place, so that depending on which RPM you were at when it noticed you cross the target, that's where it tries to center on. Though it doesn't flip to positive until you really are positive (i.e. over the set point).

It's weird, so I'm going to read through the code, but I thought I'd share. I don't remember this happening with my old version of the code. Perhaps there's some weird stuff with the typecasting, so maybe I'll try my old, working V 7 again.
User avatar
AbeFM
Post Whore!
Posts: 629
Joined: Sat Feb 16, 2008 12:11 am
Location: Sunny San Diego
Contact:

Re: PID control discussion

Post by AbeFM »

Ok, anytime my TPS crosses (down-going) the Idle Activation TPS Threshold, my IAC jumps to 166 steps. I can move that happening, but it's hard to deal with,plus it stays at 166 and stays there as the new "master" offset. Zero would seem a better choice, but I'm not sure where that is yet. It IS 64%, maybe it's using the after cranking value?

Ok, changed that to 40%... And that's where it goes (101 steps) after the TPS thingie.

One thing I've ignored in all this is the different idle "modes", there's like 1-7, but... They don't make any sense, and only a few of them are documented.

Certainly, sometimes, the code seems to work, I just have trouble when it gets stuck in weird places, jumps for no reason, etc. I was hoping to be able to isolate the PID code I wrote, but really it's so buried in all these left over work-arounds I don't know what to do. Still, I guess I don't have much choice, find them or stop working on it.

Using a lot of integral gain seems to fix this issue, so maybe that's my short term answer.
User avatar
AbeFM
Post Whore!
Posts: 629
Joined: Sat Feb 16, 2008 12:11 am
Location: Sunny San Diego
Contact:

Re: PID control discussion

Post by AbeFM »

Further updates.... After being annoyed at how weird it acted on the sim, I tried it in the car.

OMG! I'm so impressed. It took a while to come up with good numbers (turns out they are still quite low... P,I,D = 6, 1, 15 but... Excepting when I pull into a stop hard on the brakes with fans on full, lights on, etc etc, when it drops to maybe 300-400 rpm, but it recovers every time without fail, and always approaches the target like a nice, overdamped oscillator.

So, I think I'll mess with it some more, but it's good.

Also, every time I turned on any of the cut outs - all the deactivation stuff - it falls apart. Sure, it would be nice to have something with even better predictive powers, but I have to say it's pretty good over all. Needs more testing, and maybe a way to change the overall gain (tieing it to the time of the loop would be AWESOME, i.e. kp = kp, ki = ki * period, kd = * period. Or something like that. What do you all think?
User avatar
Fred
Moderator
Posts: 15431
Joined: Tue Jan 15, 2008 2:31 pm
Location: Home sweet home!
Contact:

Re: PID control discussion

Post by Fred »

8InchesFlacid wrote:OMG! I'm so impressed. It took a while to come up with good numbers (turns out they are still quite low... P,I,D = 6, 1, 15 but... Excepting when I pull into a stop hard on the brakes with fans on full, lights on, etc etc, when it drops to maybe 300-400 rpm, but it recovers every time without fail, and always approaches the target like a nice, overdamped oscillator.

So, I think I'll mess with it some more, but it's good.
Congrats, keep plugging away :-)

Fred.
DIYEFI.org - where Open Source means Open Source, and Free means Freedom
FreeEMS.org - the open source engine management system
FreeEMS dev diary and its comments thread and my turbo truck!
n00bs, do NOT PM or email tech questions! Use the forum!
The ever growing list of FreeEMS success stories!
shameem
LQFP112 - Up with the play
Posts: 135
Joined: Thu May 01, 2008 6:30 pm
Location: Ann Arbor, MI
Contact:

Re: PID control discussion

Post by shameem »

I am sure you already know about this page - but just in case ...
http://www.megamanual.com/ms2/IAC.htm
User avatar
AbeFM
Post Whore!
Posts: 629
Joined: Sat Feb 16, 2008 12:11 am
Location: Sunny San Diego
Contact:

Re: PID control discussion

Post by AbeFM »

Latest notes:
Car works great when warmed up, when cold the idle hunts a lot. Basicaly, anything that lets the valve close much further than it needs to to obtain a small idle causes issues, overshooting which leads to oscilation.

I can counter it with huge derivative gains, the problem there is that when I'm at light throttle, the term picks up small fluctuations in RPM, and the D-term leaves the can bouncing and bucking, fighting any change in RPM but being too slow to do it. There's a TPS cutout I can use, but then I get the problem where the valve opens far enough to idle at over 4,000 rpm, and all sorts of issues come up.

I went to more P and less D, and it's better, but.... while I'm fighting this PID-while-not-idling, I'm kinda stuck. Posted on MS forums to see if they have some advice.
thebigmacd
LQFP112 - Up with the play
Posts: 205
Joined: Thu Apr 10, 2008 5:51 pm

Re: PID control discussion

Post by thebigmacd »

Why not try a little feed-forward compensation in the loop? Add a constant offset to the valve position that is proportional to the desired rpm setpoint, or based off a warmup table. IE do your PID calcs, then tack on the values from the open loop idle control table/scale function.

This way you have a base output that is modified by the PID loop to maintain idle when unexpected loads arise.

We talked about feed-forward before...it "shouldn't be too hard" to implement and it will help eliminate overshoot while keeping Kd small. During warmup it will force your basic ISV position to be farther open when you arrive in the vicinity of your desired output, keeping the engine from stumbling.

It will also help people get started...they can set all the constants to zero and get unloaded varying idle working in open loop, then start by playing around with kp etc to get it closer as loads switch on.

What is happening is the transfer function of the system (engine) changes as it warms up. The open loop table can compensate quite well for the 1st-order portion of this change, then the PID can adjust to get it right on.
Keith MacDonald
Control Engineering (Systems) Technologist
Post Reply