[info] electronic throttle body control ETB

It's all about the code!
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: electronic throttle body control ETB

Post by AndreyB »

Just drove with rusEfi ETB control for the first time! PID settings are very not great but car is still pretty derivable. Here pid is 0.8/0/0, offset 0. period 50ms

Logs attached

Attachments
2018-12-02_17.10.50.msl
(671.13 KiB) Downloaded 722 times
graph_etb_drive.png
graph_etb_drive.png (16.66 KiB) Viewed 29182 times
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
alexander-n8hgeg5e
Posts: 50
Joined: Mon Oct 01, 2018 4:42 pm

Re: electronic throttle body control ETB

Post by alexander-n8hgeg5e »

regulated position is a bit oszillating/overshoting but then the target value is reached faster.
Cool , you can even see it in the diagramm its a bit more steeper at beginning.
Hm... Probably it is intended to go full throttle, but not tuned yet.
mck1117
running engine in first post
running engine in first post
Posts: 1493
Joined: Mon Jan 30, 2017 2:05 am
Location: Seattle-ish

Re: electronic throttle body control ETB

Post by mck1117 »

Ok, did some testing last night with a real throttle body on rusefi. I wired in my Ford throttle body to rusefi (only a single channel, no redundancy yet). Wrote an ETB controller similar to what I prototyped on Arduino, and played with it a bit hooked up to the scope. I haven't hooked up motor drive yet, so I'm just watching the duty cycle and direction control change while manually moving the throttle blade. It's set to be a P-only controller, no feedforward/dcbias/linearization term, and a target position of 25%.

There's a bit of a concerning behavior relating to the PWM output. It looks like that duty cycles near 0 can result in duty cycles closer to 10-20% instead. So there's a bug somewhere in PWM land, but other than that the outputs look reasonable.

Here's a video (sorry, it's vertical! :D):

The top trace is PWM duty cycle (at 800hz), and the bottom trace is drive direction. High = motor pushes throttle open, low = motor pushes throttle closed.
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: electronic throttle body control ETB

Post by AndreyB »

Is your code in git? Is it based on recent rusefi? There was a bug about 10% in ETB pwm, due to bug in percent int to float conversionn in electronic_throttle.cpp
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
mck1117
running engine in first post
running engine in first post
Posts: 1493
Joined: Mon Jan 30, 2017 2:05 am
Location: Seattle-ish

Re: electronic throttle body control ETB

Post by mck1117 »

russian wrote:
Wed Dec 05, 2018 11:47 pm
Is your code in git?
It will be tonight!
russian wrote:
Wed Dec 05, 2018 11:47 pm
Is it based on recent rusefi?
Branched from master last night.
russian wrote:
Wed Dec 05, 2018 11:47 pm
There was a bug about 10% in ETB pwm, due to bug in percent int to float conversionn in electronic_throttle.cpp
I'm using SimplePwm like the existing implementation, and I'm not sending duty cycle < 1%. Is the limitation a pulse width limitation, or duty cycle limitation? I suspect this may be related:

https://github.com/rusefi/rusefi/blob/b4a09b2e71a65d2ebda04701d5f43b9f1151538a/firmware/controllers/system/pwm_generator_logic.cpp#L63
mck1117
running engine in first post
running engine in first post
Posts: 1493
Joined: Mon Jan 30, 2017 2:05 am
Location: Seattle-ish

Re: electronic throttle body control ETB

Post by mck1117 »

Ok, here are the goodies:

https://github.com/mck1117/rusefi/tree/mck1117/etb/firmware/testing

I'm now using a custom PWM implementation that's more robust, and impervious to short and long pulses. I haven't tested it very hard, but I think it works. It uses a thread instead of scheduled events, which I think PROBABLY actually saves cycles, and certainly makes it impossible to get weird narrow/long pulse behavior because the loop is guaranteed to run in order.

edit: Well this is awkard, ChibiOS's chThdSleep only provides a resolution of 1 millisecond, so any PWM frequency over 10hz is uselessly low resolution. Other than that it now appears to work, but only at hopelessly low PWM frequencies :D.

edit 2: If I increase CH_CHFG_ST_FREQUENCY, I get smaller ticks. I have to also increase CH_CFG_TIME_QUANTUM by the same factor to not make time quanta smaller. Looks like a 10x increase works, but 100x increase causes other stuff in the firmware to get upset.
Last edited by mck1117 on Thu Dec 06, 2018 10:23 am, edited 1 time in total.
User avatar
kb1gtt
contributor
contributor
Posts: 3758
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA

Re: electronic throttle body control ETB

Post by kb1gtt »

The ChibiOS minimum tick can be decreased. When the ChibiOS tick expires, it will consume blah cycles. If you decrease your tick cycle time, you have increased how many maintenance cycles are consumed over an average period of time. This limits how many cycles are available for other tasks. So it's a balancing act, between the OS's reaction time and how many cycles are available for other tasks. As well there are risks in using a separate bit banging thread for PWM tasks. This can mangle the ChibiOS tick times, making other items act buggy or erratic. I have not looked at your code, but it sounds like you're potentially preventing ChibiOS from getting it's tick at the normal tick time. If your thread happens to block the ChibiOS tick from getting to do it's thing for a bit of time, this add's jitter to the frequency of the ChibiOS tasks. This jitter can cause problems. It might work in a small test, but if you could get things into the scheduler that would greatly reduce the risks of bugs and unexpected problems.

I'm a bit confused. Are you measuring PWM or generating PWM? Most ETB's that I've seen use POT's and analog signals for the feedback. Is your ETB producing a PWM for the feedback? Hmmm, I forget if there are timer resources available. I think the massive scheduler timer is consuming almost all the timer resources. You might be able to setup the STM's hardware to measure the PWM, then have ChibiOS read that PWM register. That would not have risks to the scheduler.
Welcome to the friendlier side of internet crazy :)
mck1117
running engine in first post
running engine in first post
Posts: 1493
Joined: Mon Jan 30, 2017 2:05 am
Location: Seattle-ish

Re: electronic throttle body control ETB

Post by mck1117 »

See second edit to response above, you posted while I was editing.

This was a hack to get around the broken existing pwm implementation. I'm generating bit-banged PWM in software. I'm well aware that it's a hack, and don't expect it to work far outside of bench testing.
Last edited by mck1117 on Thu Dec 06, 2018 10:31 am, edited 2 times in total.
mck1117
running engine in first post
running engine in first post
Posts: 1493
Joined: Mon Jan 30, 2017 2:05 am
Location: Seattle-ish

Re: electronic throttle body control ETB

Post by mck1117 »

kb1gtt wrote:
Thu Dec 06, 2018 9:46 am
When the ChibiOS tick expires, it will consume blah cycles. If you decrease your tick cycle time, you have increased how many maintenance cycles are consumed over an average period of time.
This isn't quite true, a tick is the minimum period of time understood by the kernel. Every N ticks is one time quantum, which is the minimum unit of scheduling. At the expiration of every quantum some cycles are spent to determine if a new task should be scheduled. I increased the ticks-per-quantum value by the same factor, so the duration in ticks increased, but duration in wall-clock time stayed constant.
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: electronic throttle body control ETB

Post by AndreyB »

mck1117 wrote:
Wed Dec 05, 2018 7:27 pm
There's a bit of a concerning behavior relating to the PWM output. It looks like that duty cycles near 0 can result in duty cycles closer to 10-20% instead. So there's a bug somewhere in PWM land, but other than that the outputs look reasonable.
This is nasty, I am on it! Will try to reproduce this tomorrow and see if I can figure it out. https://github.com/rusefi/rusefi/issues/628
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
mck1117
running engine in first post
running engine in first post
Posts: 1493
Joined: Mon Jan 30, 2017 2:05 am
Location: Seattle-ish

Re: electronic throttle body control ETB

Post by mck1117 »

russian wrote:
Sat Dec 08, 2018 3:37 am
This is nasty, I am on it! Will try to reproduce this tomorrow and see if I can figure it out. https://github.com/rusefi/rusefi/issues/628
Thanks! That said, I switched back to using SimplePwm, and I can't get it to repro :/
mck1117
running engine in first post
running engine in first post
Posts: 1493
Joined: Mon Jan 30, 2017 2:05 am
Location: Seattle-ish

Re: electronic throttle body control ETB

Post by mck1117 »

We have success! I switched back to SimplePwm, (sketchily) wired in my hbridge, and now I have smooth motion, including throttle body spring correction! This is a 99% port of my Arduino code, down to the curve for the spring compensation and PID tune constants. It's running 500hz PWM frequency, and 500hz PID loop update. SimplePwm appears to behaving itself now, so I'm not sure what those glitches were that I saw earlier.

The only real change I had to make was that I had to change the TPS to use high speed ADC instead of low speed.



The click when the throttle is nearly closed is the point at which the spring reverses, which it's moving across smoothly!

(edit) Here's the hardware I'm using in this video:
  • Crappy L298 motor driver
  • Crappy harvested 12v hard drive power supply (2 or 3 amps or something?)
  • Throttle body is from a 3.5L Ford Duratec (Mustang, Explorer, Flex, etc) I believe
Last edited by mck1117 on Wed Jan 02, 2019 6:31 pm, edited 1 time in total.
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: electronic throttle body control ETB

Post by AndreyB »

mck1117 wrote:
Sat Dec 08, 2018 7:35 am
We have success!
I like having success :)

I am deep in https://github.com/rusefi/rusefi/issues/129 so I've missed the video for the whole day sorry :(

Do you want to make a PR with just TwoPinDcMotor? I can make the configuration sections for linearization_inputs and linearization_outputs. Do you think we need 8 points or would just 4 points be enough?
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
mck1117
running engine in first post
running engine in first post
Posts: 1493
Joined: Mon Jan 30, 2017 2:05 am
Location: Seattle-ish

Re: electronic throttle body control ETB

Post by mck1117 »

russian wrote:
Sun Dec 09, 2018 3:43 am
I am deep in https://github.com/rusefi/rusefi/issues/129 so I've missed the video for the whole day sorry :(
Fixes look good so far! I think sanitizing the inputs to the SimplePwm fixed my issue, so your changes should fix it.

One thing: I think instead of checking == 0 and ==1, we should check < 0.01f and >0.99f. 0.000001f is a valid float, but not equal to 0! And will almost certainly cause issues. Also, it currently lets you send a duty of 2, or 50, or 10000 without checking it...
russian wrote:
Sun Dec 09, 2018 3:43 am
Do you want to make a PR with just TwoPinDcMotor? I can make the configuration sections for linearization_inputs and linearization_outputs. Do you think we need 8 points or would just 4 points be enough?
Let's go for 8, at least. Memory is pretty cheap, and while I think my throttle body would work with 4, not all may.
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: electronic throttle body control ETB

Post by AndreyB »

Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: electronic throttle body control ETB

Post by AndreyB »

Youtube has disabled easy 90 degree video rotation and apparently they know that you want to tilt your head for this specific one - please enjoy
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
mck1117
running engine in first post
running engine in first post
Posts: 1493
Joined: Mon Jan 30, 2017 2:05 am
Location: Seattle-ish

Re: electronic throttle body control ETB

Post by mck1117 »

Awesome!

ps: I feel you on the "youtube can't rotate" thing, I re-shot my video of the TB working because it wouldn't let me rotate :(
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: electronic throttle body control ETB

Post by AndreyB »

Current status posted to first thread message https://rusefi.com/forum/viewtopic.php?f=5&t=592#p9012
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: electronic throttle body control ETB

Post by AndreyB »

I wonder if it's possible to just use a small OEM self-contained module like 37850-PPD-911 from 2005 Honda Accord
Attachments
37850-PPD-911.jpg
37850-PPD-911.jpg (107.09 KiB) Viewed 28830 times
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
mk e
Posts: 486
Joined: Tue Dec 06, 2016 7:32 pm

Re: electronic throttle body control ETB

Post by mk e »

On my system I use a pololu controler:

https://www.pololu.com/product/2994

(I killed the 17A version, but I'm moving 12 TBs so....)

Then a gpio with a pullup for direction and a pwm (1khz seems to work well with the controller and the bmw servo I'm using, lower hz makes a lot of noise, higher doesn't seem to function well). This is on a 7ms update loop, but there it a hardware pwm that does 1hz to 50khz so pwm ouput is independant of control info updates.

The issue I'm dealing with is is oscillation when system voltage changes. If I tune the pid to be as responsive as possible then system voltage changes can cause oscillation to set it. I'm thinking I'm going to add a pid tuning vs voltage table....after I fix a dropped valve seat.

I also have the throttle tied into the idle control (controls throttle to maintain set rpm) and traction control ( reduces throttle to maintain a max wheel slip)....but I don't have the engine running well enough to spent much time with those.

Oh, the othe issue I had was with negative TPS. I set 0 when the TB is full closed, not sitting on an idle screw. Then I have a TB start position and default idle position when idle control is offline, always positive....because it got really confused if I let the TB hit a hard stop above where the throttle pedal was trying to set it.

I also have a table the is desired TB position vs Pedal position. This make the engine power vs pedal position more linear....big TBs let in a LOT of air with small angle changes at low throttle positions, this table smooths that out.

I have a stall saver feature too...if rpm drops x rpm below idle setting the throttle snaps open to a set position until rpm recovers then drops back to idle set point. I guess any feature that opens the throttle more than the pedal commands is a bit dangerous......but it's nice.
mk e
Posts: 486
Joined: Tue Dec 06, 2016 7:32 pm

Re: electronic throttle body control ETB

Post by mk e »

I dug up a log of the throttle response on my setup....Red and yellow are the tthrottle and desired location. There's a little lag, basically the loop read time delay. The blue line is throttle state switching from normal to idle and you see the throttle move to an idle position, this was testing so I use a BIG number to see to working, real idle is about 6% not 20%. Also notice I use the translation table as a manual idle set, Throttle goes to near 0% but the yellow goes to my idle setpoint, pretty easy to use.

I also attach a pretty helpful PID tuning guide I found and a screen shot of the important part...just set I, D to zero and increase P until a disturbance (quick throttle blip and manually flip the actuator) cause an oscillation that doesn't stop. Log it to get the period, plug in the numbers and its tuned pretty near perfect every time.
Attachments
Throttle translation.JPG
Throttle translation.JPG (36.86 KiB) Viewed 28718 times
PID settings.JPG
PID settings.JPG (24.17 KiB) Viewed 28718 times
PIDTuningClassical - ControlsWiki.pdf
(450.88 KiB) Downloaded 318 times
Throttle.JPG
Throttle.JPG (159.19 KiB) Viewed 28718 times
PID tune.JPG
PID tune.JPG (111.26 KiB) Viewed 28718 times
User avatar
andreika
donator
donator
Posts: 461
Joined: Mon Feb 13, 2017 2:35 pm
Location: Kiev

Re: electronic throttle body control ETB

Post by andreika »

mck1117 wrote:
Sat Dec 08, 2018 7:35 am
We have success! I switched back to SimplePwm, (sketchily) wired in my hbridge, and now I have smooth motion, including throttle body spring correction! This is a 99% port of my Arduino code, down to the curve for the spring compensation and PID tune constants. It's running 500hz PWM frequency, and 500hz PID loop update. SimplePwm appears to behaving itself now, so I'm not sure what those glitches were that I saw earlier.
This is a truly wonderful result! Well done! :D
Could you please clarify what driver board did you use in your video? Or at least take a big photo of this module? And what power supply (max.current) was used?
mck1117
running engine in first post
running engine in first post
Posts: 1493
Joined: Mon Jan 30, 2017 2:05 am
Location: Seattle-ish

Re: electronic throttle body control ETB

Post by mck1117 »

andreika wrote:
Wed Jan 02, 2019 3:59 pm
Could you please clarify what driver board did you use in your video? Or at least take a big photo of this module? And what power supply (max.current) was used?
Edited in to post with video above to maintain context. As crappy as the setup was, it worked great until the L298 overtemp'd after a few minutes.

I have one of these https://www.pololu.com/product/1212 to upgrade to, as it should be quite a bit more efficient. I've been busy and out of town so I haven't had a chance to wire it in yet :)
mk e
Posts: 486
Joined: Tue Dec 06, 2016 7:32 pm

Re: electronic throttle body control ETB

Post by mk e »

For converting an existing TB to ETB this actuator from a bmw E46 series works well and gives you a second TPS signal as well.....but its a bit large and draws well over 3A in motion even with no TB connected to it, over 10A moving 12 ITBs.

I really like the simple feedforward (spring compensation)table you've added ...its probably going to want voltage compensation of some kind? Also I didn't see anything to clamp the I term, that's usually needed to keep things stable.
Attachments
E46.JPG
E46.JPG (409.96 KiB) Viewed 28688 times
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: electronic throttle body control ETB

Post by AndreyB »

Is this BMW 7831529 from M3? Not any e46 I believe?
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
mk e
Posts: 486
Joined: Tue Dec 06, 2016 7:32 pm

Re: electronic throttle body control ETB

Post by mk e »

russian wrote:
Wed Jan 02, 2019 8:05 pm
Is this BMW 7831529 from M3? Not any e46 I believe?
YES! the E46 M3, sorry to forget that critical piece of info.

Powerful bugger though. It has no trouble with this setup, you can just see it tucked in the V on the right. I did switch to pretty light springs in the TBs though

Edit: also I use the TPS on the actuator as the ERROR signal not the primary control signal....there is play in the linkage so its not as accurate as the TB mounted TPS. I tried it both ways and it definitely works best with the TB mounted TPS as the control signal.
Attachments
20170117_2130301.jpg
20170117_2130301.jpg (2.52 MiB) Viewed 28687 times
Last edited by mk e on Wed Jan 02, 2019 8:34 pm, edited 1 time in total.
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: electronic throttle body control ETB

Post by AndreyB »

You cannot attach THIS picture and not have at least some build thread URL or thread on this forum :)
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: electronic throttle body control ETB

Post by puff »

Ferrari? :o :shock:
russian, you seem to officially have some parts from Ferrari (plug extender?) :D
mk e
Posts: 486
Joined: Tue Dec 06, 2016 7:32 pm

Re: electronic throttle body control ETB

Post by mk e »

russian wrote:
Wed Jan 02, 2019 8:33 pm
You cannot attach THIS picture and not have at least some build thread URL or thread on this forum :)
Sorry again, here some info

http://gemellocattivo.com/forum/viewtopic.php?f=2&t=8

Now back to ETB :)
mk e
Posts: 486
Joined: Tue Dec 06, 2016 7:32 pm

Re: electronic throttle body control ETB

Post by mk e »

mk e wrote:
Wed Jan 02, 2019 7:54 pm
I really like the simple feedforward (spring compensation)table you've added ...its probably going to want voltage compensation of some kind?
I added a version of this to my setup with a 5x11 table to do 8, 10, 12, 13,8, 15V and throttle from 0-100% in 10% steps as a starting point and tested it tonight at 13.8V with the PID at 0s.....it turns out I don't have enough spring force to really have much correlation between output pwm and position. The red is TPS, green is the PWM...it took a lot to get it open then almost nothing to hold it. Just something to watch out for I guess....check up and down to be sure the pwm setting gives you repeatable TPS results, they sure didn't for me. I'll leave it in my model but these will be just all 0s for me I guess.
Attachments
Capture throttle test.JPG
Capture throttle test.JPG (85.44 KiB) Viewed 28619 times
Post Reply