 
 // Initialize with encoder period and swing-up limit.
 // Theta is positive clockwise in degrees, with theta = 0 when hanging at rest.
-Pendulum pendulum(7200 /* counts/rev */, 120.0 /* deg */);
+Pendulum pendulum(7200 /* counts/rev */, 125.0 /* deg */);
 
 // PID controllers for pendulum and cart.
 // Parameters: p,i,d, initial setpoint, timestep [ms]
-PIDControl penPid(0.75, 0.0002, 75.0, 180.0, 10);
+PIDControl penPid(0.75, 0.002, 150.0, 180.0, 10);
 PIDControl cartPid(2.0, 0.0005, 0, 0.0, 5);
 
 elapsedMillis printTimer = 0;

  }

  // The "catch" band
  else if ((thetaError > +15 && thetaError < +20 && pendulum.omega > 0) ||
           (thetaError < -15 && thetaError > -20 && pendulum.omega < 0))
  {
    cartPid.setpoint += 0.0002 * pendulum.omega;


  }

  // The "swing" band
  else
  {
    // If pendulum is not inverted, generate setpoint for swinging action
    cartPid.setpoint = pendulum.swingX(0.4);
