PID signal to SERVO signal conversion.

Hi all.

I'm using <PID_v1.h> on a servo controlled throttle body. The Arduino gets a Hall sensor signal from a flywheel of a generator, this is the INPUT of the PID.. The user defines the RPM with a pot, this is the SET POINT. And the OUTPUT of the PID is a signal that is meant for a heater element or an Air Conditioning, but I want to convert that signal into a Servo signal that regulates a Throttle body..

Any clues? I basically have everything build up and working except this last major step.. I've been scratching my head over this problem for a few weeks now and could really use a hint or two.

And I'm processing all my output and input signals directly with Hardware Timers so all my signals are very accurate... Just need to convert that PID heater signal to a Servo signal.

Thanks.

The user defines the RPM with a pot, this is the SET POINT. And the OUTPUT of the PID is a signal that is meant for a heater element or an Air Conditioning,

Does this make sense? What is the relationship between RPM and heating or air conditioning?

but I want to convert that signal into a Servo signal that regulates a Throttle body..

You need a function, f(x), that converts x to a servo angle. Only you have any idea what that function should do, or whether the relationship is even linear.

And I'm processing all my output and input signals directly with Hardware Timers so all my signals are very accurate... Just need to convert that PID heater signal to a Servo signal.

I can't see how you can implement PID if servo position is not one of the inputs. The whole idea behind PID is to take some input and some desired target, and determine what needs to change to move the input closer to the target.

The PID is simply the software equivalent of an opamp, it takes two inputs and
the difference between them is an error value that is amplified and filtered in time
to make a stable feedback loop.

The two inputs have to be commensurate (measured in the same units, say rpm), whereas
the output is unrelated. However the overall gain of the system (PID loop plus the thing
being controlled) is vital to get right.

Think of the PID loop as amplifying an error signal by a certain factor, then the system
being controlled amplifies its control input by some factor to produce an output signal.

So any scaling of the PID output to the full range of Servo values will do, but you will
need to re-tune the PID so that the gain round the loop is back to a sensible value.

You also have to get the sign of respose right.

I'd suggest scaling so the full output range of the PID maps to the full Servo input range
as a first try. Start with just a P factor and get that a reasonable value first off.

Thank you PaulS and MarkT for your valuable input.

I've talked with a few other engineers about this PID to Servo issue and after hearing all this input including from you two here's what I'll do:

I'm digging around the PID library and I'll just take the most essential math algorithm part of it and focus on the P term only.

Then figure out the translation between Error Difference and RPM and Servo position.

I think if I can get that much going the rest is all down hill.

Thank you.

PaulS:

The user defines the RPM with a pot, this is the SET POINT. And the OUTPUT of the PID is a signal that is meant for a heater element or an Air Conditioning,

Does this make sense? What is the relationship between RPM and heating or air conditioning?

but I want to convert that signal into a Servo signal that regulates a Throttle body..

You need a function, f(x), that converts x to a servo angle. Only you have any idea what that function should do, or whether the relationship is even linear.

And I'm processing all my output and input signals directly with Hardware Timers so all my signals are very accurate... Just need to convert that PID heater signal to a Servo signal.

I can't see how you can implement PID if servo position is not one of the inputs. The whole idea behind PID is to take some input and some desired target, and determine what needs to change to move the input closer to the target.

You are maybe failing to understand that the servo is just a means of controlling/changing the process variable and it's the "process variable" that is the main input to the PID controller along with the desired setpoint input.

Say the servo was controlling a car's accelerator pedal as in a classic 'speed controller'. The PID output is manipulating the servo's position but the PID doesn't care what position the servo moves to (inside a min and max travel range limits), just that is can indirectly raise or lower the vehicle's speed, so that the PID can continuously adjust the servo position command to force the speed sensor's value to equal setpoint value.

Bottom line is that the servo's position is not used as a PID input value, unless the objective of the PID controller is as a simple servo controller, which is something the servo already has built into it's internal electronics.

You are maybe failing to understand that the servo is just a means of controlling/changing the process variable and it's the "process variable" that is the main input to the PID controller along with the desired setpoint input.

This assumes that there is a relationship between the process variable and the servo position. If the relationship is linear, one value can be easily substituted for the other.

PaulS:

You are maybe failing to understand that the servo is just a means of controlling/changing the process variable and it's the "process variable" that is the main input to the PID controller along with the desired setpoint input.

This assumes that there is a relationship between the process variable and the servo position. If the relationship is linear, one value can be easily substituted for the other.

But there must be such a relationship otherwise what is the purpose of having the servo try and change the process variable being controlled? Linear or Non-linear output response is not a problem as the PID just drives the system towards process variable = setpoint and keeps it at that control point while adjusting for load changes on the process variable.

Well, after analyzing the PID library some more I've extracted the following "concept".

error = setpoint - input;
I_term += error;
D_term = (input - last_input); 

output = kp * error + I_term - kd * D_term;

With this simple code I should get an output that can go either positive or negative.. Then all I have to do is map that properly to the Servo position.

So far I've implemented the P_term (error) part of it with a potentiometer as the Kp adjustment and it's seems to be working.... I'm in the process of adding the I_term now and eventually the D_term.

My problem has been the output format in the library.

k7michal:
Well, after analyzing the PID library some more I've extracted the following "concept".

error = setpoint - input;

I_term += error;
D_term = (input - last_input);

output = kp * error + I_term - kd * D_term;




With this simple code I should get an output that can go either positive or negative.. Then all I have to do is map that properly to the Servo position. 

You really don't need to map anything. The library also has a function to set output low and high limit values so if you just set them to 0 and 180 those will be the only value range that you call the servo write function with. The PID will handle the rest.

So far I've implemented the P_term (error) part of it with a potentiometer as the Kp adjustment and it's seems to be working.... I'm in the process of adding the I_term now and eventually the D_term. 

My problem has been the output format in the library.

You really don't need to map anything. The library also has a function to set output low and high limit values so if you just set them to 0 and 180 those will be the only value range that you call the servo write function with. The PID will handle the rest.

I see, thank you.