public int getRequiredChange(int currentHeading, int desiredHeading){

		double error;
		double derivative;
		
		double output;
		
		//If desired heading changes, integral is reset.
		if(previousHeading!=desiredHeading){
			integral = 0;
			previousHeading = desiredHeading;
		}

		// Caculate P,I,D
		//error = desiredHeading - boat.getHeading();
		error = Utils.getHeadingDifference(currentHeading, desiredHeading);
		// In case of error too small then stop intergration
		if(Math.abs(error) > epsilon){
			integral = integral + error * dt;
		}
		
		derivative = (error - previousError) / dt;
		output = Kp * error + Ki * integral + Kd * derivative;

		// Saturation Filter
		if(output > MAX){
			output = MAX;
		}else if(output < MIN){
			output = MIN;
		}
		// Update error
		previousError = error;

		System.out.print("P: " + Kp * error);
		System.out.print(",  I: " + Ki * integral);
		System.out.println(",  D:" + Kd * derivative);
		System.out.println("PID output: " + output);
		return (int) Math.round(output);
	}