MPU 6050 stuck on same values
Let's deconstruct this down to a simple example which we can test without the MPU6050:



#include &lt;PID_v1.h&gt;

double Setpoint, Input, Output;
//Specify the links and initial tuning parameters
double Kp = 2, Ki = 5, Kd = 1;
PID myPID(&amp;Input, &amp;Output, &amp;Setpoint, Kp, Ki, Kd, DIRECT);

void setup() {
  Setpoint = 100;
  //turn the PID on
  myPID.SetMode(AUTOMATIC);
  Serial.begin (115200);
  Serial.println (F("\n\nStarting\n\n"));
}

void loop() {
  int a = 0;
  int val = map(a, -1300, 1300, 0, 1023);
  Input = val;
  myPID.Compute();
  Serial.print (F("Input = "));
  Serial.println(Input);
  Serial.print (F("Setpoint = "));
  Serial.println(Setpoint);
  Serial.print (F("Output = "));
  Serial.println(Output);
  Serial.println();
  delay (300);
}




Output:

Starting


Input = 511.00
Setpoint = 100.00
Output = 0.00

Input = 511.00
Setpoint = 100.00
Output = 0.00

Input = 511.00
Setpoint = 100.00
Output = 0.00

Input = 511.00
Setpoint = 100.00
Output = 0.00


Indeed it isn't changing. Let's analyze why:


The input is 511
The setpoint is 100
Therefore the error is 100 - 511 = -411
Disregarding (for the moment) the integral and differential terms, you have a proportional term of 2 (Kp) so the algorithm tries to output 2 * Error
Output would be 2 * -411 = -822
However the maximum and minimum limits default to 0 to 255, and thus the output is clamped to 0.
The algorithm outputs 0. 
And the next time it does the same thing.


There is a function SetOutputLimits which can be used to change the default minimum and maximum output values.

The Ki and Kd values might eventually have an impact, but you won't notice anything with the output clamped to zero.

For example, adding this line in setup gives different results:



  myPID.SetOutputLimits (-5000, 5000);


Result:



Starting


Input = 511.00
Setpoint = 100.00
Output = -5000.00

Input = 511.00
Setpoint = 100.00
Output = -1233.00

Input = 511.00
Setpoint = 100.00
Output = -1438.50

Input = 511.00
Setpoint = 100.00
Output = -1644.00

Input = 511.00
Setpoint = 100.00
Output = -1849.50

Input = 511.00
Setpoint = 100.00
Output = -2055.00

Input = 511.00
Setpoint = 100.00
Output = -2260.50

Input = 511.00
Setpoint = 100.00
Output = -2466.00


Whether they are valid limits depend on what you are attempting to do exactly.