PID Engine RPM Controller

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Hi Guys,

I'm building an engine speed controller using a 16 bit microcontroller
for a gasoline engine.  I have a 1.8 degree resolution stepper motor
coupled to the throttle plate which moves the throttle angle to the
target position.

The objective is to regulate the speed of the engine to one fixed
setpoint in terms of RPM.  I'm measuring the engine speed with a
magnetic pickup and calculating RPM in the microcontroller.  My
stepper motor driver simply works by setting a direction and number of
steps which is generatred from the micro.

I'm trying to set up a good PID control loop.  I have implemented some
code, but am a bit confused over some of the algorithm options.  I'm
considering using a velocity form (incremental).  Basically, the
engine speed is the feedback which is subtracted from a reference RPM
and fed to the PID controller.  The output of the controller would be
throttle angle (I think?).  The throttle angle then results in a
certain engine RPM for a given load (highly non-linear of course).

The problem I'm having is a conceptual one as to how to treat the
stepper motor and the associated input to the "plant".  I understand
that a stepper motor is a "self integrating" device, but I don't have
a good intuitive feel for what that means in real-life.

Is the proper way to implement?:

- Use an incremental algorithm to calculate my *change* in throttle
angle for each sample period.
- Take this delta, and translate it to stepper motor steps (and
direction) based on the change in throttle angle.
- Update this calculation each sample period

The unknowns to me are:

- Can I use a positional algorithm instead of incremental by taking
the PID output and subtracting the last position to generate a delta
and send that to the stepper?  I have tried implemented the algorithm
as positional and simply send the PID output (after translating to #
of steps) and send that directly to the stepper - this seems to
function but do I wind up with an extra, unwanted integration?  In
this scenario I interpreted the output of the PID as a delta position
as opposed to absolute position, and to my surprise is seems to
function reasonably well.
- I am presently running the stepper motor at a fixed speed and always
microstepping to 1/8 step.  I could conceivably play with both the
step speed and the step resolution in real time to create
acceleration.  Would this be of any benefit.
- I've read about Three-Position Pulse Output type algorithms, which
seems to be similiar to what I'm doing - how does this apply?
- My PID sampling period is 30ms.  With the current stepper speed, I
would take upwards of 200ms for it to travel its entire stroke.  This
means my actuator would not be finished positioning when the next PID
loop rolls around.  Is this a problem?

Thanks for any feedback,

Paul

Re: PID Engine RPM Controller
Quoted text here. Click to load it
This means that the motor output is some form of an integral of it's
input.  For the stepper motor itself this is a bad analogy -- you've got
  two phases, four or six wires, you're microstepping, etc.  An ideal DC
motor is a better model -- you give it a voltage, it goes that speed,
therefore its position is the integral of the drive.

If you have some other process that's driving the stepper, and you just
tell it the number of steps, then your stepper-driver combo is "self
integrating".

Quoted text here. Click to load it
This should work depending on a number of things (if you want to be
recognized as an engineer practice saying "it depends" in answer to
every question).

Quoted text here. Click to load it

I assume that what you send to the stepper is a desired number of steps?
  The difference between outputting an angle vs. an angle delta is that
you have that extra integration.  So you need to ask if it's unwanted.
If the motor needs that derivative term to be stable it probably is, but
if you want a type-II loop it probably isn't.

It would also be nice if you know what your throttle position is, for
diagnostics if nothing else.

Quoted text here. Click to load it

Probably not.


I'm not familiar with the term -- it sounds specific to one type of
actuator.

Quoted text here. Click to load it

Yes, you'll have integrator windup in your PID.  My article
http://www.wescottdesign.com/articles/pidwophd.html touches on
integrator windup and gives the most popular method of avoiding it, but
doesn't go in depth.  I suspect you'll find it useful anyway.

Quoted text here. Click to load it

Additional Comments:

* Stepper motors -- blech.

   * A throttle position feedback would be a good idea.

* You _really_ want some safety built-in, at least a solenoid that kicks
the throttle to idle if your power cuts out, better yet a back-up rev
limiter (you can get these on your ignition if it's not already there).

--

Tim Wescott
Wescott Design Services
We've slightly trimmed the long signature. Click to see the full one.
Re: PID Engine RPM Controller


Quoted text here. Click to load it

Yes, correct.



Yes, I believe it does require the derivative term to maintain stability.  

When you say "extra integration", do you mean the integration in the PID
loop plus the integration in the motor?

 
Quoted text here. Click to load it

I'm looking at a throttle position sensor to confirm this.  Although I can
know throttle position indirection by keeping track of all the deltas.  
Assuming the motor doesn't mis steps, then it would always be correct (and
he hasn't missed any steps that I know of).


Quoted text here. Click to load it

Its where the output is either UP/DOWN/STOP for example, where UP might
drive a fixed speed motor opening a valve.  

Quoted text here. Click to load it

Do you mean that when the position output exceeds the number of steps that
can be completed within one sample period is considered windup?  In this
case, the actuator is not really saturated on an absolute basis, only per
sample period.

 
Quoted text here. Click to load it

Yes, I have overspeed/underspeed shut down which cuts the fuel.

Thanks,

paul


Re: PID Engine RPM Controller

Quoted text here. Click to load it

Ditto, that.  I started a project to control huge steam and gas valves using
pneumatics.   The pneumatic cylinder was controlled by a pneumatic stepper
valve.   There were problems with the stepper valve shifting to a safe
position when power was lost.   Also, there were problems getting the
initial position set properly.   I wouldn't trust steppers valves for
anything important.

I bowed out.   We did have position feedback for the pneumatic cylinder that
was controlling the flow control spool, but when stuff happened, the only
sure way I had to make sure the main flow control properly shut or open was
to just give the stepper motor on the pneumatic valve a bunch of steps in
one direction or the other depending on whether the valve was to fail shut
or closed.   Well what happens if our controller loses power?  We can't make
the valve fail in either direction because without power we cannot step the
stepper motor.   The pneumatic stepper valve would also fail to a neutral
postion which would let the main flow control valve move at all.

Peter Nachtwey



Re: PID Engine RPM Controller
Hi Paul,

Why would a stepper be self integrating in this application? A stepper
is an almost instant and pretty digital control when it comes to
engines. A step and thus throttle change of 1.8 degrees happens in
microseconds whereas the reaction of the engine takes a whole lot longer
because of the flywheel and other delay causing elements. So the natural
lowpass filter in the actuator section is going to be the engine. Well,
maybe unless it was a souped up version from a Ferrari Testarossa :-).

One method to arrive at customary loop responses is to look at a good
governor solution. Most stationary engines have governors, for example
generators where the output voltage isn't supposed to stray more than 5%
or so from spec. This doesn't mean they are all good though. I have just
used a wood splitter that had a terrible governor which even caused the
engine to bang once in a while.

Regards, Joerg

http://www.analogconsultants.com

Re: PID Engine RPM Controller
On 13 Jun 2004 13:12:51 -0700, the renowned bushie snipped-for-privacy@hotmail.com

Quoted text here. Click to load it

Okay.


Yes, which could cause problems- if it can't be tuned properly at both
extremes of load you'll likely have to add throttle position feedback
or load feedforward to deal with the nonlinearity.  

Quoted text here. Click to load it



Your controller inputs are SP and PV, your output is change in
"throttle angle" (or whatever actually results from the stepper motor
steps) per Ts.

Quoted text here. Click to load it

You don't really have a PID controller if the output is slew-rate
limited, but it doesn't sound like this will happen much in normal
operation.

Quoted text here. Click to load it

I don't think it does. I've used things like this in controls such as
heat/cool controls on extruders where some zones are run close to
adiabatic (the heat from plasticizing is close to the heat loss, so
you may need heating or cooling), but your setup sounds very
symmetrical and I don't see much reason for that kind of thing unless
you're trying to deal with problems (eg. "hunting") caused by
mechanical backlash in the throttle linkage (and the best way to deal
with that is to eliminate it).

Quoted text here. Click to load it

Probably not except at startup or sudden load increases you might get
overshoot/undershoot on the RPM (but 0.2s is not really very long
compared to the time constant of the plant, which is more important
than the sample time). You'll probably have trouble calculating the
2nd derivative of the RPM, BTW, without some filtering. You might try
and see if just a PI controller will work well enough. Windup should
not be a problem because you are using a velocity controller.

Quoted text here. Click to load it

Best regards,
Spehro Pefhany
--
"it's the network..."                          "The Journey is the reward"
snipped-for-privacy@interlog.com             Info for manufacturers: http://www.trexon.com
We've slightly trimmed the long signature. Click to see the full one.
Re: PID Engine RPM Controller

Quoted text here. Click to load it

Yeah, I must implement some form of gain scheduling, or perhaps even a
characterizer to linearize the system.


Quoted text here. Click to load it

Ts = Sample Period?

When you say "or whatever actually results from the stepper motor
steps", do you mean the case where the motor has reached its maximum
number of steps per sample period?  

That's what I'm wondering, should my output be absolute throttle angle,
or should it be *change* in throttle angle?


Quoted text here. Click to load it

Not sure I follow what you're saying.  Are you saying that even though
the motor is bandwidth limited, it likely doesn't matter compared to the
response time of the engine?


Quoted text here. Click to load it

I could probably speed up the stepper motor so that it always completes
the change in throttle within one PID period.

Quoted text here. Click to load it

I'm pretty sure I need derivative, it requires it for stability from my
experiments.  

You mentioned 2nd derivative, I assume you mean that first derivative is
that of the normal PID term, and the 2nd is because it is a velocity
algorithm?

Can I implement a software low pass filter to supress high frequency
noise?


Thanks,

Paul

Re: PID Engine RPM Controller
On Sun, 13 Jun 2004 23:50:23 GMT, the renowned Preppy

Quoted text here. Click to load it

Yes.


I mean that stepper motor steps could be nonlinear wrt throttle angle.
For example, if you have a spring return and a linkage so that it
shuts off if the stepper motor loses power..

Quoted text here. Click to load it

The output of a velocity controller is the rate of change of the
controller output, so, given fixed sample time, you can think of it as
(proportional to) steps (maybe fractional, maybe + or -) per second
and also per sample time.  

Quoted text here. Click to load it

That's my guess.  

Quoted text here. Click to load it

Think of the bandwidth of the controlled system (throttle to loaded
engine shaft) first, and use a sample time that is appropriate to that
(not too fast, not too slow).  

Quoted text here. Click to load it


Correct- to get the I in PID you need the second derivative of the
error term with the velocity algorithm.

Quoted text here. Click to load it

Certainly, given the usual caveats of digital filtering.

Quoted text here. Click to load it

Best regards,
Spehro Pefhany
--
"it's the network..."                          "The Journey is the reward"
snipped-for-privacy@interlog.com             Info for manufacturers: http://www.trexon.com
We've slightly trimmed the long signature. Click to see the full one.
Re: PID Engine RPM Controller

Quoted text here. Click to load it

You do.  Your system has two lags at least.  The valve and the motor.   This
requires a PID for best response.

Shame on those that suggest that just a PI would do.

Quoted text here. Click to load it

A second deriviative should be considered if there are many lags.

Quoted text here. Click to load it

Yes.   The corner frequency should be much higher than the plant frequency
so the filter has little affect on the response.  I like to use the
geometric mean between the same frequency and the plant frequency.  I have
used up to a four pole Butterworth filter.

One more suggest.   As Tim suggested, the integrator WILL wind up.   To
avoid this, do NOT ramp the set point up faster than what the stepper can
respond.  In fact, you may want to ramp the RPM as slow as possible.  This
way the the rate limited stepper will not be a factor.

Peter Nachtwey



Re: PID Engine RPM Controller
Quoted text here. Click to load it

I've implemented valve motor control in a PID temperature controller, which
would seem similar. I'm not sure I understand why you need to worry about
throttle angle - it's just the output actuator within a closed loop. If
you're measuring engine RPM, surely the throttle angle must do whatever it
takes to maintain the measured variable (RPM)? What am I missing?

Re delays in your actuator - most real-world processes are laggy, so I
shouldn't worry too much unless your I term is inappropriately short.

Steve
http://www.sfdesign.co.uk
http://www.fivetrees.com



Re: PID Engine RPM Controller
Hi Paul,

Yep a stepper motor set up like this is effectively an integrator, ie when
you move it to a new position it stays there, it's doesn't return to a zero
position when you stop stepping. Most position control systems are
integrators by their very nature, ie you tell them to move to a new position
they do, and in general it doesn't take much to hold them there.

In this case you would limit the amount of integral gain in your PID
controller, as the system has 2 integrators there's a risk it could go
unstable :o(

What is the response time of your throttle?? are you trying to maintain a
certain engine speeds over a wide range of engine loads?? how quickly can
the load change?? you may be able to get away with just a PI controller...

Dave


Quoted text here. Click to load it



Re: PID Engine RPM Controller

Quoted text here. Click to load it

Got it!  Thanks.

Quoted text here. Click to load it

Is this true for both the positional and velocity algorithms?


Quoted text here. Click to load it

Do you mean the response time of the engine speed to changes in
throttle? I don't really know, but is relatively slow in microcontroller
terms - probably well over a second at least.

Quoted text here. Click to load it

Yes, as best I can.

Quoted text here. Click to load it

Instantly, upon application of higher electrical current (we are driving
a generator).  

Quoted text here. Click to load it

Tried that, but it seems to want D for stability.

Thanks!

Paul

Re: PID Engine RPM Controller
Hi,

I had a bit of a re-think last night, the "D" term might be required for
stability.

If the engine speed starts to drop off quickly ( say due to an increase in
load ) the D term will detect this and cause the output to increase.

Again you have to a bit carefully with the amount of "D" you add in.

Dave


Quoted text here. Click to load it



Re: PID Engine RPM Controller
In my prototype, I am outputing the positional PID algorithm and
translating to a certain number of steps and applying that directly to
the stepper motor.  i.e. I am treating that output of the PID as if it
were a delta, rather than absolute position.

It seems pretty clear to me, based on the comments of all the guys
that what I've wound up with is an integrator (the motor) after the
PID controller.  I can implement the velocity algorithm, but I'm
trying to figure out what impact my first attempt has on the response.
 Does that imply that my "extra" integration is effectively cancelling
out the derivative?

Thanks,

Paul

Quoted text here. Click to load it

Re: PID Engine RPM Controller

Quoted text here. Click to load it

Yes.  Following a derivative with an integrator cancels the derivative.

--

Tim Wescott
Wescott Design Services
We've slightly trimmed the long signature. Click to see the full one.
Re: PID Engine RPM Controller
So by having an intergrating stepper motor placed after a positional
PID algorithm, what exactly does that yield?  A PI controller with
amplified I?

Paul

Quoted text here. Click to load it

Re: PID Engine RPM Controller
Overall I suppose you could call it a "PII" controller, but so many
plants have integrating action that you may as well just call it a PID
with an integrating plant and be done with it.

There's nothing wrong, by the way, with using an unusual controller to
go with an unusual plant or requirement set.  I have recently
implemented both a proportional-integral-integral controller for a plant
with velocity-only feedback, and a proportional-derivative-derivative
controller for an inherently integrating driver along with a plant with
a long thermal time lag.

Paul W. wrote:

Quoted text here. Click to load it

--

Tim Wescott
Wescott Design Services
We've slightly trimmed the long signature. Click to see the full one.
Re: PID Engine RPM Controller
Wouldn't that have serious problems with noise?  Or did you have an
unusually clean signal?  I guess a temperature loop might indeed qualify as
really smooth and that is why you are using DD in the first place.

Walter.

Quoted text here. Click to load it



Re: PID Engine RPM Controller
First, the driver was inherently integrating (it was actually
integrating in software because we had a strict limitation on the speed
that we could ramp up the cooler, so it went PDD -> limit -> integrate).
  Second, the loop closure was at a Hertz or two, so the differentiators
were leveled off at around 5-10Hz, which really kept the noise down.
And finally, it sits in a proprietary product next to a bunch of other
control loops and video acquisition, all of which need to be good to
14-16 bits, so the we _really_ knew our noise reduction techniques and
we had the leverage to apply them.

Walter Driedger wrote:
Quoted text here. Click to load it


--

Tim Wescott
Wescott Design Services
We've slightly trimmed the long signature. Click to see the full one.
Re: PID Engine RPM Controller



Quoted text here. Click to load it

Excuse me if I am wrong, but

Doesn't the input and output have to be linear (or linearizable) and be
able to convert to 0 to 100% to work?
And that the System Dynamics have to be stable to be tunable?

Neil



Site Timeline