Hello Brett,
First of all GREAT WORK!!
Your library has saved me a lot of time.
But i´m having a small problem. For some reason using the Processing Front End, everything works great, but when i try to edit manually the values and click to send it to Arduino, it just comes back to the original values.
As i couldn´t figure out what is wrong, since the communication seems to be ok, and i can see Processing IS sending something to arduino, and the arduino portion seems to be alright.. i had the ideia to have the best of both worlds anyway. I addes 3 pots to manually contro e P.I and D values. I would watch the values and the result on the Processing Front End, and manually adjust the values via the potentiometers.
The only problem now is that for some reason, pid.SetTunings doesn´t seem to change the values correctly.
Remember the Example 2 ? Well i´m doing exactly the same thing exept for the setpoint ramp stuff. Mine´s fixed.
Here´s the relevant portion of my code. I´m using it to stabilize de Y axis of a UAV. It´s loaded into a test platform where i have a horizontal arm being held in place by a fixed vertical arm. It has a motor on each side, and they try to keep the arm stable and leveled. Any disturbances should be imediately compensated.
double Input, Output, Setpoint;
PID pid(&Input, &Output, &Setpoint, 3,9,3);
// PID pid(&Input, &Output, &Setpoint,potPin1,potPin2,potPin3);
double Outputinv;
unsigned long serialTime; //this will help us know when to talk with processing
const int buttonPin = 52;
int buttonState = 0;
void setup() {
static int i;
Serial.begin(57600);
pinMode(13, OUTPUT);
servoL.attach(2);
servoR.attach(3);
pinMode(buttonPin, INPUT);
pid.SetInputLimits(-80,89);
pid.SetOutputLimits(900,1200); //tell the PID to range the output from 1000 to 2000
Output = 900; //start the output at min and let the PID adjust it from there
pid.SetMode(AUTO); //turn on the PID
pid.SetSampleTime(10);
Setpoint = 57;
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
initmotors();
delay(2000);
}
getEstimatedInclination();
pot1Value = analogRead(potPin1);
pot1Value = pot1Value /100;
pot2Value = analogRead(potPin2);
pot2Value = pot2Value /100;
pot3Value = analogRead(potPin3);
pot3Value = pot3Value /100;
pid.SetTunings(potPin1,potPin2,potPin3);
Input = (RwEst[1]*100);
pid.Compute();
servoR.writeMicroseconds(Output);
Outputinv = map(Output, 900, 1200, 1200, 900);
servoL.writeMicroseconds(Outputinv);
if(millis()>serialTime)
{
SerialReceive();
SerialSend();
serialTime+=500;
}
}
Any help would be much appreciated.