Kp, Ki, Kd for software PID control
All credit for this is from the (now unfortunately dead) Balancing Robots for Dummies thread on the Arduino forum.

The PID controller is as follows:

int
updatePID(int setPoint, int currentPoint)
{
    float error;
    static float last_error;
    static float integrated_error;

    float pTerm, iTerm, dTerm;

/*  Calculate error and proportional value.*/
    error = setPoint - currentPoint;
    pTerm = Kp * error;

/*  Calculate error and intergral value.*/
    integrated_error += error;
    iTerm = Ki * constrain(integrated_error, LOWER_LIMIT, UPPER_LIMIT);

/*  Calculate deriviative value and reset error.*/
    dTerm = Kd * (error - last_error);
    last_error = error;

/*  Return the PID controlled value.*/
    return constrain(i32K*(pTerm + iTerm + dTerm)), LOWER_LIMIT, UPPER_LIMIT);

}


This version of 'software PID control' implements the limit on the intergral value (similar to your code) using the constrain function from the Arduino library. Added benefit of this code is that it allows you to choose what from controller you want by changing the return value. E.g. a PD controller would remove the iTerm from the return value.

As far as tuning goes, it is similar to what Illegal Immigrant said.

Set Ki, Kp, and Kd to 0.
Tune Kp until oscillation occurs.
Reduce oscillation and overshoot by tuning Kd.
Tune Ki to increase the speed of the system.


This is my first time answering, hopefully I've done this correctly and helped you a little on the way!