PD of PID in a balancing robot

Probably this changing set-point puts its effect to the wild oscillation. I don't get you here:

but about the negative angle, it is coming from sensor: if I lean forward, the angle I get is positive, if I lean backward, I have negative angle, this gives negative and positive motor output based on formulation, so I use the code as you pointed:

  if(output >= 0)
  {
    digitalWrite(LDIRA, HIGH);
    digitalWrite(LDIRB, LOW);
    analogWrite(LPWM, output);
  }
  else
  {
    digitalWrite(LDIRA, LOW);
    digitalWrite(LDIRB, HIGH);
    analogWrite(LPWM, -output);
  }

and check if the final output (to be sent as PWM to motrs) is negative or positive. I only send positive PWM to my motor controller, from 0 to 255, so in case output is negative, I just switch A and B but multiply the output with -1 to have it always positive.

All the time, behavior of the system seems logical, but late reaction

I'm preparing for reconstrcution...