JohnLincoln:
I'm not familiar with the item that you call a throttle body.
Does it have a motor and gearbox inside it to drive the two Throttle Position Sensors? Why are two needed?
Can you provide a link to the throttle body? or a photograph of it?What exactly do you mean by :
The throttle body bounces all over the place for a good minute or so before settling in.
The throttle body is a mechanical device that controls the flow of air into an engine in order to control the RPM's. It does have a motor and gearbox with two throttle position sensors inside. Two are needed for automotive safety reasons, so I take the difference of the two for the position. Here is a datasheet that is for a very similar throttle body: http://www.bosch-motorsport.de/media/catalog_resources/Electronic_Throttle_Body_Datasheet_51_en_10726070795pdf.pdf As for it bouncing around, when ever I try and set it to a specific position, whether it be WOT or closed it will jitter back and forth quite a lot trying to find the right point. I think it is going too fast and overcompensating.
PaulS:
Setpoint = map(analogRead(2), 0, 1023, 0, 255);There is no clue, from reading this, exactly what is controlling the set point. Why not?
map() is a pretty expensive way to divide by 4.
double gap = abs(Setpoint-Input); //distance away from setpoint
if(gap<100)
{ //we're close to setpoint, use conservative tuning parameters
myPID.SetTunings(consKp, consKi, consKd);
}
else
{
//we're far from setpoint, use aggressive tuning parameters
myPID.SetTunings(aggKp, aggKi, aggKd);
}
You don't diddle with the tuning parameters based on how far off you are. You experiment to find tuning parameters, and use them. Consistently.int TPS0 = analogRead(0);
int TPS1 = analogRead(1);Again, there is no clue what you are reading from. Why not?int TPS = TPS1 - TPS0;
TPS = map(TPS, -715, 910, 0, 255);
Input = TPS;What purpose is TPS serving? None that I can see.
The set-point is being controlled from a potentiometer, similarly as it will be by the electronic throttle pedal. Also, I'll have to change it to divide by 4, I didn't even realize that.
So what you're saying is that I should just find tuning parameters that work and then keep them without having them changed based upon how far off?
The TPS0 and TPS1 read the two TPS's inside the throttle body then calculates the difference and maps it to the same range as my control potentiometer. It then gets sent to the "input" of the PID while the "setpoint" of the PID is controlled by the potentiometer. That way it knows where I want it to be and where it currently is. The PID then outputs to the H-Bridge speed control pin.
Thanks!