LineFollower Zumo 32U4 PID issue

Hello !

I’m using the LineFollower example from the Zumo32U4 Library and I’m experiencing some unexpected results.
When I run the code as it is the robot follows the line without any problem. However when I change this line :
int16_t speedDifference = error / 4 + 6 * (error - lastError);

To this line :
int16_t speedDifference = (1/4) * error + 6 * (error - lastError);

My zumo is experiencing some trouble following the line.

And when I try :
int16_t speedDifference = 4 * error + 6 * (error - lastError);

The result seems the same as with error/4

Now I’ve searched for an explanation to that issue but I don’t understand how it’s possible as it is exactly the same calcul.

Can anyone tell me why this happens ?

Many thanks !


It is understandable why you are seeing a difference between your first two cases. In C++, the result of dividing an integer by an integer is an integer, so your first operation, 1/4, evaluates to zero. That means the expression becomes equivalent to 0 * error + 6 * (error -lastError) instead of error / 4 + 6 * (error - lastError).

I am more surprised that you are seeing similar results from your first and third cases since you are changing your proportional constant value from 0.25 to 4, so your robot should be oscillating about the line with much greater amplitude in the third case.

- Patrick