I have a function that takes as parameter some doubles and does a subtraction operation on it. However I'm getting a result of 0 when one of the parameter is 0 for some reason.
int calcPID(double current, double desired, double k){
double diff;
diff = desired - current;
Serial.print("desired = ");
Serial.print(desired);
Serial.print(", current = ");
Serial.print(current);
Serial.print(", diff = ");
Serial.println(diff);
int r = (int)diff;
return r;
}
Output
desired = 250.00, current = 1.69, diff = 248.31
desired = 250.00, current = 0.00, diff = 0.00
When the current is 0.00 the result (diff) is also 0.00, when it should be 250. Can someone tell me what's going on?
calcPIDfunction reported, but now, looking at the updated example I'm more convinced about my answer, so much I updated it with a test. – Roberto Lo Giacco Jan 26 '17 at 16:57