I'm having a problem with my MPU6050. I'm using PID to speed up a motor with the MPU values. What could the problem be?
Here is a link to a previous question that I asked concerning a problem with pid: PID not working correctly
These are the values that I'm getting, which repeat forever. The values are:
- motor speed;
- the value that changes the motor speed;
- the MPU value;
- the change that PID made.
0.00
0
10900
4800
0.00
0
10900
4800
Here is the code itself.
int16_t ax, ay, az;
double Setpoint, Input, Output;
//Specify the links and initial tuning parameters
double Kp=2, Ki=5, Kd=1;
PID myPID(&Input, &Output, &Setpoint, Kp,Ki,Kd, DIRECT);
void setup() {
Input = analogRead(ax);
Setpoint = 100;
//turn the PID on
myPID.SetMode(AUTOMATIC);
}
void loop() {
accelgyro.getAcceleration(&ax, &ay, &az);
int a=ax+10900;
//Here I set the used variable to around 0. ax is actually around -10900
//This is always true, this won't be in the final code. This is just making it work.
if(1) {
int val;
val = map(a, -1300, 1300, 0, 1023);
Input = val;
myPID.Compute();
Serial.println(Output);
digitalWrite(motorPin2, HIGH);
Serial.print("\t");
Serial.println(ax);
Serial.print("\t");
Serial.println(a);
Serial.print("\t");
Serial.println(val);
}
}
setup
? – Nick Gammon♦ Mar 3 '16 at 22:12