[help needed] electronic throttle body control ETB

It's all about the code!
Rhinoman
contributor
contributor
Posts: 256
Joined: Thu Sep 24, 2015 2:14 pm
Location: Wiltshire, UK
Contact:

Re: electronic throttle body control ETB

Post by Rhinoman »

Have you got any feedback from the electronic throttle? if you have then you could plot the two and try some rapid openings and then see how well the electronic throttle follows (step response). Also try some rapid voltage variations to make sure it isn't going to go unstable when you get transients.

OrchardPerformance
contributor
contributor
Posts: 162
Joined: Tue Jul 24, 2018 8:55 pm
Soldering skill: yes
Coding skill?: yes

Re: electronic throttle body control ETB

Post by OrchardPerformance »

I think the reason the PID only needs the integral value may be due to 3 things, 1 - the system has a return spring that is always trying to push it closed so will try to keep the throttle closed against the motor drive and will add a certain amount of resistance to the system overshooting when opened, 2 - the throttle will have a certain amount of friction from the pivots and seals but it will be a relatively consistent amount of friction meaning you wont get studen jerks as it begins to move and finally 3 - the rate a human can open the throttle is relatively low, it takes us like 0.2-0.5 seconds at best to fully open a throttle which in electronics time is an age.

Perhaps if you were to play it a step signal then you might see some more erratic results? Or maybe use a deliberately sticky throttle?

Either way I think it might just be because the system has its own inherent damping and a driver will adjust to any slight undershoot of the pedal without knowing they are doing it. After all most cars now do not have a 1:1 relationship between the throttle and the pedal and haven't since the 90s and most drivers do not notice (ever seen a snail shaped quadrant on a cable throttle?) we humans are good at adapting to even vaguely proportional systems as long as the response is consistent.

User avatar
kb1gtt
contributor
contributor
Posts: 3563
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA
Contact:

Re: electronic throttle body control ETB

Post by kb1gtt »

I suspect the valve has an offset when done with P only term. It looks close, but it's not the same. I'm not sure that matters, as you'll just smash the pedal little bit harder. If you want to remove this you could add a small offset in your command signal, or you could include the I term.
Welcome to the friendlier side of internet crazy :)

OrchardPerformance
contributor
contributor
Posts: 162
Joined: Tue Jul 24, 2018 8:55 pm
Soldering skill: yes
Coding skill?: yes

Re: electronic throttle body control ETB

Post by OrchardPerformance »

Glad you commented on that as I thought I was imagining it. I watched the video 3 times and couldn't decide if it was an offset or a trick of the camera angle.

If it is a tiny bit off it won't matter as long as it is consistent so the driver can adapt to it. Also wont mater if the throttle never quite reaches 90 degrees either, those last few degrees do practically nothing for air flow anyway.

P.S. If you fancy being clever then have your idle control routine jack the throttle a tiny bit and use it as a way to manage idle speed without a specific ICV. A lot of newer vehicles without ICV valves do it this way.

Rhinoman
contributor
contributor
Posts: 256
Joined: Thu Sep 24, 2015 2:14 pm
Location: Wiltshire, UK
Contact:

Re: electronic throttle body control ETB

Post by Rhinoman »

I suspect your loop timing is wrong. You can't really run a PID algorithm on a micro, its an analogue (s-domain) algorithm, on a micro you run a modified (z-domain) algorithm, in essence you have four inputs P,I,D and T where T is the loop time.
There are a number of different methods to convert from s-domain to z-domain and most of the open-source algorithms use a very simple method which works OK with speed control of a DC motor (the usual example) because they have a relatively high inertia and can run relatively slow loop times. That also leads to another issue in some code where a loop time of 1 second is assumed, that makes the algorithm simpler because they can then remove some of the multiplication or division times.
I would try modifying the loop time and then see if the PID values become a bit more conventional. The integral term will always close the error, the P term should close it much faster, if you are not using any P then I would guess that your loop time is too fast or the algorithm is not optimal. Its an interesting exercise, I've ordered a cheap throttle to try it myself.

OrchardPerformance
contributor
contributor
Posts: 162
Joined: Tue Jul 24, 2018 8:55 pm
Soldering skill: yes
Coding skill?: yes

Re: electronic throttle body control ETB

Post by OrchardPerformance »

@Rhinoman - I have a Bosch throttle here if you want to try that as well, as you are in Wiltshire you are a maximum of ~15 miles from me.
Last edited by OrchardPerformance on Sat Oct 06, 2018 12:58 pm, edited 1 time in total.

Rhinoman
contributor
contributor
Posts: 256
Joined: Thu Sep 24, 2015 2:14 pm
Location: Wiltshire, UK
Contact:

Re: electronic throttle body control ETB

Post by Rhinoman »

The ETB that I have is from a Mazda though it is a Ford unit, quite clearly marked FoMoCo. Have you get the pinout information for these?

OrchardPerformance
contributor
contributor
Posts: 162
Joined: Tue Jul 24, 2018 8:55 pm
Soldering skill: yes
Coding skill?: yes

Re: electronic throttle body control ETB

Post by OrchardPerformance »

I am sure I do for the ford one and I should be able to for the Bosch one as it has come from a 330i E46.

Rhinoman
contributor
contributor
Posts: 256
Joined: Thu Sep 24, 2015 2:14 pm
Location: Wiltshire, UK
Contact:

Re: electronic throttle body control ETB

Post by Rhinoman »

If you can post that it would help, I'm not finding any info.

OrchardPerformance
contributor
contributor
Posts: 162
Joined: Tue Jul 24, 2018 8:55 pm
Soldering skill: yes
Coding skill?: yes

Re: electronic throttle body control ETB

Post by OrchardPerformance »

Bosch throttles changed a lot between M52tu and M54 generation it seems...
M52tu is in the attached photo
The M54 seems to be a PWM throttle which is an arse as it is a 70mm unit.
Attachments
M52_e-throttle.thumb.PNG.f43f0e3f1f91cda9dce7f1456acb1717.PNG
M52_e-throttle.thumb.PNG.f43f0e3f1f91cda9dce7f1456acb1717.PNG (382.33 KiB) Viewed 3443 times

mck1117
running engine in first post
running engine in first post
Posts: 323
Joined: Mon Jan 30, 2017 2:05 am
Location: Seattle-ish
Soldering skill: yes
Coding skill?: yes

Re: electronic throttle body control ETB

Post by mck1117 »

Ok, I bought a Ford throttle body (read: Bosch) from Ebay, which I believe is for the 3.5 v6 in the Explorer/Mustang/Taurus/etc. The units for other engines appear very similar but are different sizes. Mine has two feedback signals, one that provides full scale output, and one that saturates past 50% throttle position (higher resolution, but only 0-50%).

The spring does not push the throttle closed. The spring pushes the throttle back to around 8% open, so below 8% it pushes it open, and above 8% it pushes it closed. This behavior means that the I term is not enough. Since the spring also has a large amount of preload, there's a very strong step response in the required motor torque at 8%, from sharply negative to sharply positive required to maintain position.

Here's what the required duty cycle (Y axis, -255 thru 255) looks like required to hold a particular position (X axis, 0-100%). I generated these data through empirical testing.

Image

It can almost be modeled with a pretty simple piecewise function:

f(x>8)= 125
f(x<8)= -100

To control this system, we need not only a feedback controller, but also a feedforward controller that anticipates the required motor current to maintain a particular position (essentially a "smart" PID I term). In my implementation, I used an ugly hack piecewise function, linear above 10% and cubic below 10%. Removing the feedback portion of the controller gives a very strange result. You can freely push the throttle plate around like there's no spring at all. After all, that's what we want: a transform that makes the spring behave like it isn't there, so that a simple PID controller will work to handle moving the throttle to the desired position.

Here's what the controller I developed looks like:

Code: Select all

float pos = getPos();

  float error = sp - pos;
  static float lastError = 0;

  float dError = error - lastError;

  float p = kp * error;
  
  integral += error * dt;
  float i = integral * ki;
  
  float dEdT = dError / dt;
  float d = dEdT * kd;

  float output = p + i + d + dcBias(pos);
  setPwm(output);
As you can see, it's a straightforward PID controller, but with an additional "DC bias" feed-forward term. In a real implementation, the feed-forward term should be a lookup table. It doesn't even need too many bins. 5-8 is probably plenty. My throttle would probably work fine with as few as 4.

Here's an example of the controller working. It's traversing a sinusoidal input from 5-95%, and smoothly crossing the 8% neutral point.



There's a little bit of nervousness in that video (easier to hear the noise in the duty cycle than see it), which was solved by increasing the control loop frequency. It required at least several hundred hertz for good, smooth performance.

mck1117
running engine in first post
running engine in first post
Posts: 323
Joined: Mon Jan 30, 2017 2:05 am
Location: Seattle-ish
Soldering skill: yes
Coding skill?: yes

Re: electronic throttle body control ETB

Post by mck1117 »

And here's a video of the high speed response, cycling between around 20 and 70%. Second half of the video is at 1/10-ish speed.


User avatar
kb1gtt
contributor
contributor
Posts: 3563
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA
Contact:

Re: electronic throttle body control ETB

Post by kb1gtt »

Very nice. I agree that it should be much better than normal PID. Basically you manually control the valve and create a look up table for various position through out the range. Such that with no PID, you would get these positions. The PID then only deals with the errors. AKA your manually set positions, will not account for things like pressures on the butterfly caused by air flow, etc. So the PID will compensate for these kinds of errors. I would suggest adding limits to your I term, to prevent integral windup. To determine the I limits, I would suggest running it and logging the normal limits of the I term. Once you have a recorded Max and Min, then I would set the I limits to something like 120% of the max measured. You can probably get a fairly decent idea if what your min and max are by snapping your TB open for the max, and snapping it closed for the min. Or vice versa. Once you have these limits set, you could create alarm conditions if your I term ever exceeds these limits. AKA if your butter fly is falling off or something like that, you can alarm if something has gone wrong.

Also do you have a separate idle air control valve? Your commanded position may end up being your TPS command + idle compensation. Your idle compensation is likely going to be a PID which controls this PID. If you have a separate idle compensation valve, then you may end up with that control loop fighting with this control loop.

Also I recall the console has a semi high speed trend graph option. Basically it blasts data points as fast as possible over the serial stream. You can likely get that to display your commanded position vs your measured position. This can be handy when tuning PID's.
Welcome to the friendlier side of internet crazy :)

mck1117
running engine in first post
running engine in first post
Posts: 323
Joined: Mon Jan 30, 2017 2:05 am
Location: Seattle-ish
Soldering skill: yes
Coding skill?: yes

Re: electronic throttle body control ETB

Post by mck1117 »

kb1gtt wrote:
Thu Oct 11, 2018 9:44 am
Basically you manually control the valve and create a look up table for various position through out the range. Such that with no PID, you would get these positions.
Yup, that's what I did!
kb1gtt wrote:
Thu Oct 11, 2018 9:44 am
Also do you have a separate idle air control valve?
Nope. I don't think I've ever seen an engine that had an electronic throttle and a separate IAC. Isn't that one of the reasons to switch, eliminating the IAC?
kb1gtt wrote:
Thu Oct 11, 2018 9:44 am
Also I recall the console has a semi high speed trend graph option. Basically it blasts data points as fast as possible over the serial stream. You can likely get that to display your commanded position vs your measured position. This can be handy when tuning PID's.
I prototyped this on an Arduino, and used the serial plotter to plot commanded vs. actual position for PID tuning. I tuned it using Ziegler–Nichols which did a reasonable enough job.

User avatar
AndreyB
Site Admin
Posts: 10019
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Soldering skill: yes
Coding skill?: yes
Contact:

Re: electronic throttle body control ETB

Post by AndreyB »

I am jealous :)

Is there a chance for a pull request?
https://rusefi.com/s/howtocontribute
very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions
my skype is arro239

User avatar
AndreyB
Site Admin
Posts: 10019
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Soldering skill: yes
Coding skill?: yes
Contact:

Re: electronic throttle body control ETB

Post by AndreyB »

So that dcBias(pos) is like our pid->offset, just a variable one depending on desired TPS position?
https://rusefi.com/s/howtocontribute
very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions
my skype is arro239

User avatar
kb1gtt
contributor
contributor
Posts: 3563
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA
Contact:

Re: electronic throttle body control ETB

Post by kb1gtt »

Correct. They are the similar, but the ETB version is a variable offset based on TPS position, while the PID offset is fixed.
Welcome to the friendlier side of internet crazy :)

Rhinoman
contributor
contributor
Posts: 256
Joined: Thu Sep 24, 2015 2:14 pm
Location: Wiltshire, UK
Contact:

Re: electronic throttle body control ETB

Post by Rhinoman »

I drilled the pop-rivets off the Mazda ETB and opened it up. Any electronics must be moulded into the top, I would guess that its all mounted on a lead frame inside the plastic. There is a magnetic encoder on the shaft for the butterfly and two contacts for the motor. It does confirm that its a Denso ETB.

Image

Image

Image

Rhinoman
contributor
contributor
Posts: 256
Joined: Thu Sep 24, 2015 2:14 pm
Location: Wiltshire, UK
Contact:

Re: electronic throttle body control ETB

Post by Rhinoman »

It looks very much like this:
https://patents.google.com/patent/US6173939

Checking with the multi-meter, the two pins nearest to the motor contacts are connected to those motor contacts so I have four pins for the encoder. The springs have a fair resistance to them so I would guess that the motor is driven from 12V PWM.

User avatar
kb1gtt
contributor
contributor
Posts: 3563
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA
Contact:

Re: electronic throttle body control ETB

Post by kb1gtt »

How many ohms? I would expect high ohms means you can drive 100% duty, while low ohms would mean you need PWM to prevent from overheating. Probably with some sweet spot for peak heat at just the right PWM.
Welcome to the friendlier side of internet crazy :)

Rhinoman
contributor
contributor
Posts: 256
Joined: Thu Sep 24, 2015 2:14 pm
Location: Wiltshire, UK
Contact:

Re: electronic throttle body control ETB

Post by Rhinoman »

2.4 ohms so low-z, even if it were high-z it would have to be PWM'd to control the speed, you won't make a position controller without a speed controller. I will measure the inductance and then I can determine the PWM frequency for the current controller.

User avatar
kb1gtt
contributor
contributor
Posts: 3563
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA
Contact:

Re: electronic throttle body control ETB

Post by kb1gtt »

If it gets sticky, and if you have a PID or similar control algorithm, there is a potential that your PID could get to 100% PWM output which would cause it to overheat and potentially fail. I guess you can have similar during tuning, if something goes wrong, it can over heat. If you measure the temperature of the ETB while taking other measurements it would allow for some kind of predictive overheat conditions. I expect the heat generated by the ETB will be proportional to the amps it's consuming. The amps will be proportional to the PWM duty. So I would think that limiting the ETB's PWM duty would be a decent method for alarming or identifying an overheating potential.

I would suggest that the PWM output have an alarm added to it. Such that when at the bench or during initial ETB tuning, you first manually control the PWM until the ETB is WOT. Then you set your limit to something like 150% of that PWM. I'm not sure if an alarm condition would do anything more than alarm, or if it should allow for limiting the PWM. I'm tempted to suggest that if it alarms for more than something like 30 seconds, then it should limit the PWM to prevent electrical fire. However I'm not sure if that's safer than letting it catch fire and attempting to control until it can't do it any more. Perhaps the limiting based on alarm can be a bit that is toggled for tuning purposes. AKA a PID with integral windup, which runs away can cause WOT, and damage things while your tuning.

Any how, I would like suggest that the output has some kind of PWM limit, before algorithms are attempted to control the ETB.

What kind of control algorithm should be used for ETB control? PID has potential to run away. Are there other algorithms which would be less susceptible to run away conditions? Perhaps limiting the I term could prevent the run away from being to bad. Or perhaps only allowing the I term when you are in a band around the target, say no I term unless feedback is at 10% from the target.
Welcome to the friendlier side of internet crazy :)

Rhinoman
contributor
contributor
Posts: 256
Joined: Thu Sep 24, 2015 2:14 pm
Location: Wiltshire, UK
Contact:

Re: electronic throttle body control ETB

Post by Rhinoman »

You need to define what you mean by 'running away', I would always expect anti-wind a motor PID-controller. The biggest problem with automotive motor controllers is the vulnerability to instability caused by transients on the supply voltage, IME that's usually dealt with by a voltage compensation multiplier on the P term of the current loop. Also the characteristics of the motor change dramatically over the temperature range, temperature sensing would make it simple but a separate temperature sensor isn't going to be in a price sensitive automotive device so the PID terms have to be chosen so they work adequately at the extremes.
Any significant error in the PWM will cause a positional error which should cause the ECU to shut down the ETB, particularly at 100% PWM. 100% PWM would only be used to accelerate the motor during a large step change, not to hold it in position but there is a possibility that the motor could go to 100% PWM while at full throttle - that would be detected by monitoring the current, My intention is to remove the motor to tune the current and speed loops, that can't be done easily with the restricted movement of the ETB.
I don't have any concerns about overheating the motor, if it were to go unstable during testing then I'll just turn the power off, I can do that in within a couple of seconds.

User avatar
kb1gtt
contributor
contributor
Posts: 3563
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA
Contact:

Re: electronic throttle body control ETB

Post by kb1gtt »

Running away could be integral wind up, or it could simply be oscillation caused by unforeseen holes and poles. I guess there is some software risk, such that software does something not expected, like a higher priority bit of code prevents the PID for operating at a consistent time base, or something funky like that.

About the overheating, I was more thinking of when your not looking at it. AKA something has changed perhaps a pot gets a bit dirty, or a bad wire adds some unexpected resistance, something like that which causes the feedback signal to go wrong. You may just be sitting there engine off tuning tables or something similar, and the ETB is unexpectedly running to hot. I was thinking that adding some limits would likely help avoid issues when that happens.
Welcome to the friendlier side of internet crazy :)

User avatar
AndreyB
Site Admin
Posts: 10019
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Soldering skill: yes
Coding skill?: yes
Contact:

Re: electronic throttle body control ETB

Post by AndreyB »

Minor software progress:
I now have console code which starts at 0% duty cycle and starts to go up 0.5% each second. It records at which point ETB has started to open.

It increases duty cycle by 0.5% every 3 seconds until it reaches 100% and starts to do the opposite thing - going down by 0.5% every 3 seconds until it closes completely.

A few repetitions and here are my stats:

2018-11-17 20_27: : startedToOpenValue = 19.5, reached100Value = 26.0
2018-11-17 20_27: : startedToCloseValue = 13.5, backToZeroValue = 8.0

2018-11-17 20_32: : startedToOpenValue = 19.5, reached100Value = 26.0
2018-11-17 20_32: : startedToCloseValue = 12.5, backToZeroValue = 8.0

2018-11-17 20_39: : startedToOpenValue = 19.0, reached100Value = 26.0
2018-11-17 20_39: : startedToCloseValue = 12.5, backToZeroValue = 7.5

Interesting to note how the 19-26 opening range does not overlap with the 8-12 closing range. Attached is a log file - "debug f1" is duty cycle while TPS is TPS.
Attachments
2018-11-17_20_22_54.zip
(217.85 KiB) Downloaded 33 times
etb_auto_up_down.png
etb_auto_up_down.png (78.79 KiB) Viewed 3059 times
https://rusefi.com/s/howtocontribute
very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions
my skype is arro239

User avatar
kb1gtt
contributor
contributor
Posts: 3563
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA
Contact:

Re: electronic throttle body control ETB

Post by kb1gtt »

russian wrote:
Sun Nov 18, 2018 2:06 am
Interesting to note how the 19-26 opening range does not overlap with the 8-12 closing range.
https://en.wikipedia.org/wiki/Hysteresis
Welcome to the friendlier side of internet crazy :)

Rhinoman
contributor
contributor
Posts: 256
Joined: Thu Sep 24, 2015 2:14 pm
Location: Wiltshire, UK
Contact:

Re: electronic throttle body control ETB

Post by Rhinoman »

I've lost track if what you're trying to achieve. If your throttle body accepts a PWM input to give a position then it already has a controller so you don't need a control algorithm. Are you sure that you have the PWM frequency correct?

User avatar
andreika
donator
donator
Posts: 431
Joined: Mon Feb 13, 2017 2:35 pm
Location: Kiev

Re: electronic throttle body control ETB

Post by andreika »

russian wrote:
Sun Nov 18, 2018 2:06 am
2018-11-17 20_27: : startedToOpenValue = 19.5, reached100Value = 26.0
2018-11-17 20_27: : startedToCloseValue = 13.5, backToZeroValue = 8.0
pid.offset = (startedToOpenValue + startedToCloseValue) * 0.5 = ~16.5

User avatar
kb1gtt
contributor
contributor
Posts: 3563
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA
Contact:

Re: electronic throttle body control ETB

Post by kb1gtt »

Ah, I understand PID * Hysteresis = blah.

Hmmm, you could try this. Your max Hysteresis appears to be 26 - 8 = 18. Lets say our PID output is 50%. You could make the ETB's signal 68% for say 0.1 seconds, then make it 32% for 0.1 seconds, then repeat this process, such that the average is 50%, with a dithering amplitude of 18. Hmmm, dithering might only need an amplitude of 9. You can try different dithering frequencies and different dithering amplitudes. The dithering commonly removes the hysteresis. One caution with a dithering frequency is that it can mechanically cause fatigue.

You could also try this. Again, lets say your PID output is 50%. Once very say 0.1 seconds for perhaps 0.01 seconds, make the output 50% - 18% = 32%. Such one every so often you push to one side of the hysteresis, and you're always approaching your target from either closed or open side of the hysteresis.

Also once you get this done, you'll likely want to create a linearization curve. PID like linear, and your ETB output is not likely linear.
Welcome to the friendlier side of internet crazy :)

Joeldc510
Posts: 29
Joined: Mon Jan 22, 2018 4:04 am
Soldering skill: yes
Coding skill?: yes

Re: electronic throttle body control ETB

Post by Joeldc510 »

russian wrote:
Sun Nov 18, 2018 2:06 am
Minor software progress:
I now have console code which starts at 0% duty cycle and starts to go up 0.5% each second. It records at which point ETB has started to open.

It increases duty cycle by 0.5% every 3 seconds until it reaches 100% and starts to do the opposite thing - going down by 0.5% every 3 seconds until it closes completely.

A few repetitions and here are my stats:

2018-11-17 20_27: : startedToOpenValue = 19.5, reached100Value = 26.0
2018-11-17 20_27: : startedToCloseValue = 13.5, backToZeroValue = 8.0

2018-11-17 20_32: : startedToOpenValue = 19.5, reached100Value = 26.0
2018-11-17 20_32: : startedToCloseValue = 12.5, backToZeroValue = 8.0

2018-11-17 20_39: : startedToOpenValue = 19.0, reached100Value = 26.0
2018-11-17 20_39: : startedToCloseValue = 12.5, backToZeroValue = 7.5

Interesting to note how the 19-26 opening range does not overlap with the 8-12 closing range. Attached is a log file - "debug f1" is duty cycle while TPS is TPS.
Since you're using Megalogviewer, can you use the scatter plot option to see if you can get more information out of your log. Put you X axis as you Input(Duty Cycle) and Y axis as your Output (TPS). Also maybe run the test a couple times to get more data points and see where your throttle behaves linearly.

Post Reply