How to make a PID-Controller: control the throttle (ESC) for a given RPM (governor)

openTx has introduced a range of new features, ideas and bling. It is fast becoming the firmware of choice for many users. openTx will run on ALL current hardware platforms, including the gruvin9x and sky9x boards. Work has already started to support the new FrSky X9D radio!
Post Reply
wilopaan
Posts: 155
Joined: Sun Sep 09, 2018 6:09 pm
Country: -

How to make a PID-Controller: control the throttle (ESC) for a given RPM (governor)

Post by wilopaan »

Hi all,

I habe telemetry to get the RPM of the motor of a ship-model. My idea ist to implement a pid-controller for the RPM of the motor. The Input gives the setpoint and the telemetrie measured RPM the process value. With a mixer it is easy to implement the proportional part, but how to differentiate and integrate the feedback error?

Any ideas.

Yes, and I know that there is a substantial dead time in the control-loop.

lshems
Posts: 63
Joined: Tue Sep 15, 2015 5:36 pm
Country: -

Re: RE: How to make a PID-Controller: control the throttle (ESC) for a given RPM (governor)

Post by lshems »

wilopaan wrote:Hi all,

I habe telemetry to get the RPM of the motor of a ship-model. My idea ist to implement a pid-controller for the RPM of the motor. The Input gives the setpoint and the telemetrie measured RPM the process value. With a mixer it is easy to implement the proportional part, but how to differentiate and integrate the feedback error?

Any ideas.

Yes, and I know that there is a substantial dead time in the control-loop.
Radio type?
wilopaan
Posts: 155
Joined: Sun Sep 09, 2018 6:09 pm
Country: -

Re: RE: How to make a PID-Controller: control the throttle (ESC) for a given RPM (governor)

Post by wilopaan »

lshems wrote: Sun Apr 19, 2020 4:31 pm Radio type?
Jumper T12 with OpenTx
lshems
Posts: 63
Joined: Tue Sep 15, 2015 5:36 pm
Country: -

Re: RE: Re: RE: How to make a PID-Controller: control the throttle (ESC) for a given RPM (governor)

Post by lshems »

wilopaan wrote:
lshems wrote: Sun Apr 19, 2020 4:31 pm Radio type?
Jumper T12 with OpenTx
Ok, I'll write you a pid controller. Just send me the main inputs and output calculations, or some other documents on what you want.pid governors isyears ago for me.

It will be a lua script.
wilopaan
Posts: 155
Joined: Sun Sep 09, 2018 6:09 pm
Country: -

Re: How to make a PID-Controller: control the throttle (ESC) for a given RPM (governor)

Post by wilopaan »

Ok, thanks! But you don't have to do that: a lua telemetry script for the PID-controller ist not the problem for me ;-)

I just want to ask if the is something built-in to openty that I could use.

lshems
Posts: 63
Joined: Tue Sep 15, 2015 5:36 pm
Country: -

Re: RE: Re: How to make a PID-Controller: control the throttle (ESC) for a given RPM (governor)

Post by lshems »

wilopaan wrote:Ok, thanks! But you don't have to do that: a lua telemetry script for the PID-controller ist not the problem for me ;-)

I just want to ask if the is something built-in to openty that I could use.
Well, no. Dont think so.

Would be fun to see if it could be done by only mixers.

Did a swash ring with only mixers once. Had to use a curve to get a sqrt function in opentx. But doable.

Lol.
wilopaan
Posts: 155
Joined: Sun Sep 09, 2018 6:09 pm
Country: -

Re: How to make a PID-Controller: control the throttle (ESC) for a given RPM (governor)

Post by wilopaan »

With mixers only I think it would be impossible because you have to use a time delay to realize the differential or integral part.

I you have further ideas, don't hesitate to post them ;-)
User avatar
Kilrah
Posts: 11109
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: How to make a PID-Controller: control the throttle (ESC) for a given RPM (governor)

Post by Kilrah »

Between the slow and multiply in mixer it should be possible to do something...
lshems
Posts: 63
Joined: Tue Sep 15, 2015 5:36 pm
Country: -

Re: RE: Re: How to make a PID-Controller: control the throttle (ESC) for a given RPM (governor)

Post by lshems »

Kilrah wrote:Between the slow and multiply in mixer it should be possible to do something...
Been busy with it.

Seems possible. Got already a nice dampened oscillator.

Figuring out if I can check if it's working correctly.

Fun project.
wilopaan
Posts: 155
Joined: Sun Sep 09, 2018 6:09 pm
Country: -

Re: How to make a PID-Controller: control the throttle (ESC) for a given RPM (governor)

Post by wilopaan »

Oh, very cool! Would be glad to hear more ... this week I'am busy at bussiness.
Thanks!
lshems
Posts: 63
Joined: Tue Sep 15, 2015 5:36 pm
Country: -

Re: How to make a PID-Controller: control the throttle (ESC) for a given RPM (governor)

Post by lshems »

wilopaan wrote: Mon Apr 20, 2020 4:39 pm Oh, very cool! Would be glad to hear more ... this week I'am busy at bussiness.
Thanks!
How about this :)
screenshot_x9d+_20-04-21_01-09-23.png
screenshot_x9d+_20-04-21_01-09-23.png (1.86 KiB) Viewed 11712 times
used a throttle as output parameter, with weight, offset (simulated load) and delay on this throttle as resulting RPM to match the set RPM.

Don't get any effect from the D parameter, but I might have made a mistake.

SA down to trigger.
Use the output monitor to check the effect of the SB switch setpoint step changes for desired RPM. The outputs are all named.
I had to trick some stuff to get a diff measurement set up.

LS, S1 and S2 to adjust P, I, D
RS for load

OTX attached. Taranis XD9+ 2.2.4
Attachments
PID.zip
(868 Bytes) Downloaded 212 times
wilopaan
Posts: 155
Joined: Sun Sep 09, 2018 6:09 pm
Country: -

Re: How to make a PID-Controller: control the throttle (ESC) for a given RPM (governor)

Post by wilopaan »

Well, just had a quick look at your solution.

One question, because I could not get it on the first glance: how do you compute the integration, that is the sum of the error over time?
lshems
Posts: 63
Joined: Tue Sep 15, 2015 5:36 pm
Country: -

Re: How to make a PID-Controller: control the throttle (ESC) for a given RPM (governor)

Post by lshems »

wilopaan wrote: Tue Apr 21, 2020 6:23 am Well, just had a quick look at your solution.

One question, because I could not get it on the first glance: how do you compute the integration, that is the sum of the error over time?
the int channel plus the error equals the int channel
wilopaan
Posts: 155
Joined: Sun Sep 09, 2018 6:09 pm
Country: -

Re: How to make a PID-Controller: control the throttle (ESC) for a given RPM (governor)

Post by wilopaan »

Ah yes!
So the value of an input/mixer for t(n) is always based on another value for t(n-1)?
lshems
Posts: 63
Joined: Tue Sep 15, 2015 5:36 pm
Country: -

Re: How to make a PID-Controller: control the throttle (ESC) for a given RPM (governor)

Post by lshems »

wilopaan wrote: Tue Apr 21, 2020 7:02 pm Ah yes!
So the value of an input/mixer for t(n) is always based on another value for t(n-1)?
Well, that is tricky to say.

But to not even bother about that, I just put every mixer Inthe order if calculation.

So first the current error.

That's simple.

But then, I need the current error minus the last error. In order to force this without your assumption, because I tried some and it didn't work, I created a ls that flips between calculation cycles. It will switch where the current error is stored, error1 or error2. This means that the diff between error1 and error2 is always the diff between the old and the new error, just with the sign flipped. Happens that this ls is also flipping sign so use that to get the diff properly.

The diff and the prop are multiplied by their P and D factor directly.

The int cannot use that, since it needs the 'raw' int in the next cycle. It is done in the output on line 1 instead, and then has the prop and diff added there.

You can test diff and int behaviour by making the setpoint fixed and have the rpm either be 0 weight and offset 1% (int testing) or make the rpm be itself with addition of 1%.

Hope this helps.

P, I, D values are not properly time scaled off course!
But factors are factors. Tune them.
wilopaan
Posts: 155
Joined: Sun Sep 09, 2018 6:09 pm
Country: -

Re: How to make a PID-Controller: control the throttle (ESC) for a given RPM (governor)

Post by wilopaan »

Next question: using the companion, how to simulate 2 or more RPM sensors.

When I start the simulation, there is only one RPM Sensor, but I need of course a second. How can I add a second one?

Thanks.
User avatar
Kilrah
Posts: 11109
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: How to make a PID-Controller: control the throttle (ESC) for a given RPM (governor)

Post by Kilrah »

Not possible at this point.
lshems
Posts: 63
Joined: Tue Sep 15, 2015 5:36 pm
Country: -

Re: RE: Re: How to make a PID-Controller: control the throttle (ESC) for a given RPM (governor)

Post by lshems »

wilopaan wrote:Next question: using the companion, how to simulate 2 or more RPM sensors.

When I start the simulation, there is only one RPM Sensor, but I need of course a second. How can I add a second one?

Thanks.
Don't get your point?

lshems
Posts: 63
Joined: Tue Sep 15, 2015 5:36 pm
Country: -

Re: How to make a PID-Controller: control the throttle (ESC) for a given RPM (governor)

Post by lshems »

Any updates?

Post Reply

Return to “openTx”