Data logging P, I, and D contributions to closed loop

Testing and development of Megasquirt 3

Moderators: jsmcortina, muythaibxr

Matt Cramer
Super MS/Extra'er
Posts: 17499
Joined: Thu Apr 16, 2009 8:08 pm

Data logging P, I, and D contributions to closed loop

Post by Matt Cramer »

I've had a couple customers who were annoyed at how their PID tuning (one for boost, one for O2 correction) was behaving. Is it possible to change the code to add a feature to data log the internal calculations - contributions from the P, I, and D terms, for example? This might aid in troubleshooting these sorts of issues.
Matt Cramer -1966 Dodge Dart slant six running on MS3X
franksidebike
Experienced MS/Extra'er
Posts: 226
Joined: Fri Apr 08, 2005 2:08 pm
Location: Wathlingen, Germany

Re: Data logging P, I, and D contributions to closed loop

Post by franksidebike »

+1
Suprazz
Master MS/Extra'er
Posts: 499
Joined: Mon Jan 22, 2007 7:58 pm
Contact:

Re: Data logging P, I, and D contributions to closed loop

Post by Suprazz »

yes please!
Best looking and most advanced CAN-bus gauge
Toyota Supra 7MGE, 7M-GTE and 1JZ-GTE Plug and play ECUs: http://www.perfecttuning.net
Serial to Bluetooth or Serial to WiFi
DIYAutotune Canadian, EFI Source and ECUMaster reseller!
whittlebeast
Super MS/Extra'er
Posts: 2221
Joined: Tue May 04, 2004 8:20 pm
Location: St Louis
Contact:

Re: Data logging P, I, and D contributions to closed loop

Post by whittlebeast »

Assuming you could get the programmers to include this in the logs, explain how you would use this to solve a hunting idle or AFR issue.

Andy
Matt Cramer
Super MS/Extra'er
Posts: 17499
Joined: Thu Apr 16, 2009 8:08 pm

Re: Data logging P, I, and D contributions to closed loop

Post by Matt Cramer »

whittlebeast wrote:Assuming you could get the programmers to include this in the logs, explain how you would use this to solve a hunting idle or AFR issue.

Andy
This is something to help with a sort of "higher level" complaint - customers who insist that the code must be broken because it's either not applying correction as quickly as they'd like, or are baffled by some sort of weird behavior. This log was taken from a test on a Stim where I was trying to establish that PID correction speed had not changed significantly between the 1.4.1 and 1.5.0 code, but it has a set of "spikes" to the EGO correction that I don't understand. Logging the P, I, and D terms might give some explanation.

And since I don't really have the programming skills (or time) to take apart the code and prove to a customer (who may very well have even worse programming skills than me) that the code is working, something like this could save me a lot of time on some of the more difficult customer support conversations. They don't happen extremely often, but when they do these tend to take up a disproportionate share of time.
Matt Cramer -1966 Dodge Dart slant six running on MS3X
Reverant
Super MS/Extra'er
Posts: 1233
Joined: Sat Apr 15, 2006 12:39 am
Location: Athens, Greece

Re: Data logging P, I, and D contributions to closed loop

Post by Reverant »

Matt Cramer wrote:I've had a couple customers who were annoyed at how their PID tuning (one for boost, one for O2 correction) was behaving. Is it possible to change the code to add a feature to data log the internal calculations - contributions from the P, I, and D terms, for example? This might aid in troubleshooting these sorts of issues.
I've already written this code as I was trying to figure out why P is doing almost nothing to correct the fueling. Let me look it up and I can post a patch here.
The man behind MS Labs
2005 Audi A3 2.0L TFSI DSG AWD - Extreme MS3
2002 Mazda Miata 1.8 6sp - Enhanced MS3 1.4.0, sequential injection, sequential ignition, big turbo, lots of boost
AbatelliCristian
Super MS/Extra'er
Posts: 855
Joined: Sun Oct 10, 2010 6:33 am

Re: Data logging P, I, and D contributions to closed loop

Post by AbatelliCristian »

+1
motthomas
Helpful MS/Extra'er
Posts: 88
Joined: Wed Aug 24, 2011 2:06 am

Re: Data logging P, I, and D contributions to closed loop

Post by motthomas »

whittlebeast wrote:Assuming you could get the programmers to include this in the logs, explain how you would use this to solve a hunting idle or AFR issue.

Andy
Knowing what each of the terms are doing would massively help to dial in the control for anyone familiar with standard control systems. Not logging them means you are trying to tune the control loop blind.
whittlebeast
Super MS/Extra'er
Posts: 2221
Joined: Tue May 04, 2004 8:20 pm
Location: St Louis
Contact:

Re: Data logging P, I, and D contributions to closed loop

Post by whittlebeast »

Ok, so how would we document what the three numbers mean and how to tune them?

Andy
whittlebeast
Super MS/Extra'er
Posts: 2221
Joined: Tue May 04, 2004 8:20 pm
Location: St Louis
Contact:

Re: Data logging P, I, and D contributions to closed loop

Post by whittlebeast »

This is one of the best (simple minded) explanation of a PID logic that I have ever seen. Still trying to get my head around bringing this back to a log and "Here is the problem, grab that knob"

https://commons.wikimedia.org/wiki/File ... imated.gif

Andy
muythaibxr
Site Admin
Posts: 8228
Joined: Thu Oct 14, 2004 12:48 pm

Re: Data logging P, I, and D contributions to closed loop

Post by muythaibxr »

Reverant wrote:
Matt Cramer wrote:I've had a couple customers who were annoyed at how their PID tuning (one for boost, one for O2 correction) was behaving. Is it possible to change the code to add a feature to data log the internal calculations - contributions from the P, I, and D terms, for example? This might aid in troubleshooting these sorts of issues.
I've already written this code as I was trying to figure out why P is doing almost nothing to correct the fueling. Let me look it up and I can post a patch here.
Did you find anything other than AFR has to be changing for it to have an effect?
Megasquirt is not for use on pollution controlled vehicles. Any advice I give is for off road use only.
mrx79
Experienced MS/Extra'er
Posts: 299
Joined: Wed Oct 29, 2008 8:26 am
Location: Frankfurt / Germany

Re: Data logging P, I, and D contributions to closed loop

Post by mrx79 »

+1 for this feature for both EGO and Idle control
Honda CRX B16A1 Turbo | MS3 running | pre1.5.1 beta7 Firmware | 24/1 Dual Wheel | COP ignition | 725cc ID injectors
whittlebeast
Super MS/Extra'er
Posts: 2221
Joined: Tue May 04, 2004 8:20 pm
Location: St Louis
Contact:

Re: Data logging P, I, and D contributions to closed loop

Post by whittlebeast »

If you enter PID in the TS search box, you get 8 different things that can be controlled with PID, or 24 new possible fields to log.
Matt Cramer
Super MS/Extra'er
Posts: 17499
Joined: Thu Apr 16, 2009 8:08 pm

Re: Data logging P, I, and D contributions to closed loop

Post by Matt Cramer »

It would make sense to allow this to be turned off or on, like Port Status.
Matt Cramer -1966 Dodge Dart slant six running on MS3X
whittlebeast
Super MS/Extra'er
Posts: 2221
Joined: Tue May 04, 2004 8:20 pm
Location: St Louis
Contact:

Re: Data logging P, I, and D contributions to closed loop

Post by whittlebeast »

James may chine in here, but I wonder what the format of the P, I, and D are under the covers.

Andy
jsmcortina
Site Admin
Posts: 39587
Joined: Mon May 03, 2004 1:34 am
Location: Birmingham, UK
Contact:

Re: Data logging P, I, and D contributions to closed loop

Post by jsmcortina »

whittlebeast wrote:James may chine in here, but I wonder what the format of the P, I, and D are under the covers.

Andy
They are signed 32bit numbers. So adding all of these could require 96 bytes of "outpc" space.

James
I can repair or upgrade Megasquirts in UK. http://www.jamesmurrayengineering.co.uk

My Success story: http://www.msextra.com/forums/viewtopic ... 04&t=34277
MSEXTRA documentation at: http://www.msextra.com/doc/index.html
New users, please read the "Forum Help Page".
Reverant
Super MS/Extra'er
Posts: 1233
Joined: Sat Apr 15, 2006 12:39 am
Location: Athens, Greece

Re: Data logging P, I, and D contributions to closed loop

Post by Reverant »

96bits.
The man behind MS Labs
2005 Audi A3 2.0L TFSI DSG AWD - Extreme MS3
2002 Mazda Miata 1.8 6sp - Enhanced MS3 1.4.0, sequential injection, sequential ignition, big turbo, lots of boost
jsmcortina
Site Admin
Posts: 39587
Joined: Mon May 03, 2004 1:34 am
Location: Birmingham, UK
Contact:

Re: Data logging P, I, and D contributions to closed loop

Post by jsmcortina »

Reverant wrote:96bits.
24 fields according to Andy. x 4 bytes each -> 96 bytes.

James
I can repair or upgrade Megasquirts in UK. http://www.jamesmurrayengineering.co.uk

My Success story: http://www.msextra.com/forums/viewtopic ... 04&t=34277
MSEXTRA documentation at: http://www.msextra.com/doc/index.html
New users, please read the "Forum Help Page".
Reverant
Super MS/Extra'er
Posts: 1233
Joined: Sat Apr 15, 2006 12:39 am
Location: Athens, Greece

Re: Data logging P, I, and D contributions to closed loop

Post by Reverant »

I think Matt mostly said about EGO and boost control, not really everything.

Like I said before, I myself had the same idea when I saw logs of stock ECUs and other ECUs doing closed loop fuel control REALLY quick, and no matter what I would do, I couldn't get the MS3 to react as quickly, and after a little code hacking, led me to the observation that if I had PID values of 100,0,0, a target of 14.7 and an actual AFR of 10 (pegged rich), the closed loop would just sit there and won't make any corrections at all.

Now, Ken has said that he has implemented the type B algorithm and that's fine, but is type B really suited in this case? I've had so much better results with closed loop fuel control since I converted Kp = (long) (error * (long)set_Kp);

And then there's the limiting size of outpc, which is probably the current biggest development issue right now. We can't add any new features that need gauges or datalogging without increasing the size of outpc.
The man behind MS Labs
2005 Audi A3 2.0L TFSI DSG AWD - Extreme MS3
2002 Mazda Miata 1.8 6sp - Enhanced MS3 1.4.0, sequential injection, sequential ignition, big turbo, lots of boost
Reverant
Super MS/Extra'er
Posts: 1233
Joined: Sat Apr 15, 2006 12:39 am
Location: Athens, Greece

Re: Data logging P, I, and D contributions to closed loop

Post by Reverant »

muythaibxr wrote:
Reverant wrote:
Matt Cramer wrote:I've had a couple customers who were annoyed at how their PID tuning (one for boost, one for O2 correction) was behaving. Is it possible to change the code to add a feature to data log the internal calculations - contributions from the P, I, and D terms, for example? This might aid in troubleshooting these sorts of issues.
I've already written this code as I was trying to figure out why P is doing almost nothing to correct the fueling. Let me look it up and I can post a patch here.
Did you find anything other than AFR has to be changing for it to have an effect?
And to answer this: no. P was only making corrections if the AFR was wildly swinging up and down (big changes in error). On a relativelt calm engine, with just a massive error in AFR, P is doing nothing and only I is working over time to bring it in line.
The man behind MS Labs
2005 Audi A3 2.0L TFSI DSG AWD - Extreme MS3
2002 Mazda Miata 1.8 6sp - Enhanced MS3 1.4.0, sequential injection, sequential ignition, big turbo, lots of boost
Post Reply