I am using a differential wheel robot for my project. I need to know the current coordinates of the robot with respect to it's initial position taken as the origin. I m doing the computation on an Arduino UNO and the only sensory input that I get is from the two encoders. I have the function updateOdomenty() called in the loop() and this is it's corresponding code:
void updateOdometry()
{
static int encoderRPosPrev = 0;
static int encoderLPosPrev = 0;
float SR = distancePerCount * (encoderRPos - encoderRPosPrev);
float SL = distancePerCount * (encoderLPos - encoderLPosPrev);
encoderRPosPrev = encoderRPos;
encoderLPosPrev = encoderLPos;
x += SR * cos(theta);
y += SL * sin(theta);
theta += (SR - SL) / wheelDistance;
if(theta > 6.28)
theta -= 6.28;
else if(theta < -6.28)
theta += 6.28;
}
This is the code that me and my team mates made after reading this paper. I am wondering if this is the best possible way to solve this problem with an Arduino. If not, how is odometry done in differential wheeled systems?