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

Testing and development of Megasquirt 3

Moderators: jsmcortina, muythaibxr

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

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

Post by muythaibxr »

EGO is actually type C. Boost is "ideal" PID at this point. It is pretty easy to experiment with the different types.
Megasquirt is not for use on pollution controlled vehicles. Any advice I give is for off road use only.
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:Ok, so how would we document what the three numbers mean and how to tune them?

Andy
I'm assuming this was directed at me? I'm not sure what you mean by documenting what they mean and how to tune them? As in a "how to guide to PID tuning"? Thats not what I was getting at. There is plenty of information online on how to tune PID loops. I'm just referring to being able to log what each parameter is doing during the loop. For any PID loop, you should really be able to see what each term is doing when a disturbance is introduced and how the terms contribute to getting the loop back on target. Without this information you are just blindly stabbing at numbers until you get to a place where it "sort of" works. You might be lucky and get it first try or it could take a long time to get the control where you want it. At least if you can see what the terms are doing then you can make some educated guesses on where each term needs to be for your particular application.

On the topic of documenting though, I think it would be very useful to document what type of algorithm each PID loop is which would also help tuning it. There is no mention of this in the manuals that I can see of what type of algorithms are used which makes tuning the loop more difficult unless you dig into the source code. Happy to be proven wrong on that one though. Searching on the forums will likely dig up an answer but I'm sure it would be no harm to include more information in the manuals to help people out?
jsmcortina
Site Admin
Posts: 39612
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 »

I've had a look at implementing this but run into some problems getting the data out that may be TS/MLV issues.

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".
jamies
Master MS/Extra'er
Posts: 525
Joined: Tue Apr 07, 2009 12:22 am

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

Post by jamies »

I had also put in a request for this
I have used another branded ecu :o which shows the PID gains (as they use a table for the PID gains, its not a fixed number like the MS) and the P,I,D Output numbers, so for example for closed loop idle it would show P = 5% I -2% D=0% etc depending on what its doing. Made it much easier to tune the gains to to get it to reach the target cleanly, and see what parameter is having most effect.
elaw
Super MS/Extra'er
Posts: 2926
Joined: Fri Oct 16, 2009 6:20 am
Location: Wilmington, MA

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

Post by elaw »

Another +1!

For a while I was running a self-modded version of the MS3 code and one of my mods was that it logged P/I/D parameters for boost control. It made tuning *much* easier!

There are a few caveats though:
1) The MS code, particularly the older stuff, uses a weird (IMHO) implementation where the P, I, and D parameters are not calculated the usual way. So outputting them to the datalog isn't just a simple matter of adding/copying the internal variables to the logged dataset.

1a) The code uses a single function to implement several different PID controls. So there's not a separate P, I, and D value stored for each.

2) In order for this to help with tuning, you have to have a fairly good understanding of how PID controllers work. If you don't know how to interpret the numbers, it won't be any help.

When I did my mod I wrote separate PID-control code for boost, which eliminated issues 1 and 1a, but that of course makes the code size larger, just like having separate P/I/D variables for things makes the data size larger.

If anyone's curious, I've attached a log file showing boost PID parameters.
Eric Law
1990 Audi 80 quattro with AAN turbo engine: happily running on MS3+MS3X
2012 Audi A4 quattro, desperately in need of tweaking

Be alert! America needs more lerts.
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 a plot of the data ELaw posted

http://www.nbs-stl.com/mlvhd/ELaw%20PID ... hot%20.png

Back to my question... How do we use this and how do we teach/document this?

Andy
AlanJ
Helpful MS/Extra'er
Posts: 86
Joined: Mon Apr 10, 2017 7:37 am

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

Post by AlanJ »

I don't mean to thread jack, but I have searched around and could not figure out what p,I,d did. That explanation you posted was very informative. Although I have no clue the inner workings of ms. I think it would be easier to tune if there was a p,I,d out that gave numbers on the effects of each of them.

For example p is adding x, I is subtracting x, and d is adding x. Even if it was an add-in or "plug in" to tuner studio that calculated these values on the tuning computer based on the tune data. (The plug in calculated them in parallel to mega squirt - calculated field on tuning computer only, no changes to Ms code) I don't think the exact number would be as beneficial as just seeing witch is increasing and witch is subtracting in sudo real time......
92 Dakota Work in progress (ms3x)
jsmcortina
Site Admin
Posts: 39612
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 »

I've added logging of Idle, AFR1, Boost1 PID terms to SDcard "internal fields" for the next pre-1.5.1 beta.

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".
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 »

Here is what the Alpha code looks like on a running motor. I run PID on AFR only. My Gego correction is set up to run 4% max authority.

http://www.nbs-stl.com/tuning/PID%20Ego ... ection.png

Note that I am getting data at 200 samples per sec. Each spike in the next_spark.tooth is one full engine cycle. I am finding that a typical big AE event on my motor is about 5 engine cycles long. This is all done on a MS3 Ultimate running a Honda ITB motor.

Andy
jsmcortina
Site Admin
Posts: 39612
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 »

jsmcortina wrote:I've added logging of Idle, AFR1, Boost1 PID terms to SDcard "internal fields" for the next pre-1.5.1 beta.
This is now released as pre-1.5.1 beta 3.

You need to enable INTERNAL_LOG_FIELDS in your project properties, then you can add fields like these to your SDcard datalog. These are not available in regular datalogs.
pid_log_idle_p
pid_log_idle_i
pid_log_idle_d
pid_log_idle_count

Note that these are in internal units which won't necessarily correspond to the externally visible units e.g. for idle the 0-100% scale is handled 0-255 internally. Viewing the "idle steps" field gives you 0-255. The "count" field increments each time the calculation is run, so log this as well.

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".
R/TErnie
MS/Extra Newbie
Posts: 8
Joined: Fri Jun 02, 2017 3:25 pm

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

Post by R/TErnie »

Thank you for adding the PID gains for boost and the idle controller. yay.
Peter Florance
Super MS/Extra'er
Posts: 3653
Joined: Fri Apr 02, 2004 8:40 pm
Location: Virginia Beach, VA
Contact:

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

Post by Peter Florance »

Would it be difficult to add to VVT?

Sent from my XT1254 using Tapatalk
Peter Florance
PF Tuning
81 BMW Euro 528i ESP Car
60-2 Wheel LS2 Coils, Low Z Inj
Co-Driver 1999 BMW E46 DSP car.
jsmcortina
Site Admin
Posts: 39612
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 »

Peter Florance wrote:Would it be difficult to add to VVT?
Not particularly, but which channel?!

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".
Peter Florance
Super MS/Extra'er
Posts: 3653
Joined: Fri Apr 02, 2004 8:40 pm
Location: Virginia Beach, VA
Contact:

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

Post by Peter Florance »

jsmcortina wrote:
Peter Florance wrote:Would it be difficult to add to VVT?
Not particularly, but which channel?!

James
I'm not sure I understand the question.

I'm my case, I might want to tune VVT 1 or 2 as that is intake and exhaust.

Thanks

Sent from my XT1254 using Tapatalk
Peter Florance
PF Tuning
81 BMW Euro 528i ESP Car
60-2 Wheel LS2 Coils, Low Z Inj
Co-Driver 1999 BMW E46 DSP car.
jsmcortina
Site Admin
Posts: 39612
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 »

Peter Florance wrote:Would it be difficult to add to VVT?
Added for beta 7.

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".
sdezego
Helpful MS/Extra'er
Posts: 96
Joined: Sat Jan 07, 2006 8:50 pm
Location: Orlando
Contact:

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

Post by sdezego »

Anyone try logging values and tuning based on it? I am going to try, but was curious.

I also found this thread which was very interesting that talks about about the different Types of PID equations and why Type C is superior in most cases. http://bestune.50megs.com/typeABC.htm
'90 Corrado G60 on MSns -e -> MS3 - '62 Harley Panhead

Supercharged 2L-20v Project Build -> https://forums.vwvortex.com/showthread.php?2805002

Making 02m 6speed Conversion Mounts for VW MKII and MKIII -> http://www.generalprinciple.com/02m
Post Reply