I have found this to be an acceptable take-back-half algorithm:
Code:
cval -= (cval - goodval) / 2;
Where cval is the current value of [whatever] and goodval is the ideal point (what you want it to be at)
Code:
cval += constrain(-(cval - goodval) / 2,-max,max);
This also works, but is constrains the value to within a maximum speed, the variable max. Function constrain below:
Code:
float constrain(val,min,max) {
return val>max?max:val<min?min:val;
}
This seems a lot simpler than the previously posted code, and I was wondering if they are equivalent?