The problem is of PID controller for a ball beam system, intially some angle is given to the beam. A controller is to be designed to balance the ball in the beam.
if (*rtu_BallPositionValid)
{
real_T error=(0-*rtu_BallPosition);
double derivative=(error-lasterror)/0.001;
integral+=error*0.001;
*rty_RequestedBeamAngle=*rtu_ActualBeamAngle+ (Kp*error+Kd*derivative+Ki*integral);
lasterror=error;
} else {
*rty_RequestedBeamAngle = localDW->Delay_DSTATE;
}