I have a robot using differential drive and with a quadrature encoder on each motor. I'm trying to plot its position on a screen based on the odometry data. I have this example of calculation, but am having difficulty with the calculation for bearing.
I've simplified the example for the above link in the code below.
theta = 0;
WHEEL_BASE = 20;
void loop {
L_Dis = GetOdometer(L); // Get odometer reading (distance since last sample)
R_Dis = GetOdometer(R); // Get odometer reading (distance since last sample)
distance = (L_Dis + R_Dis ) / 2; // Calculate total distance travelled
theta += (L_Dis - R_Dis ) / WHEEL_BASE; // Accumulate total rotation
theta -= (float)((int)(theta/TWOPI))*TWOPI; //Clip the rotation to plus or minus 360 degrees
/* now calculate and accumulate our position in inches */
Y_pos += distance * cos(theta);
X_pos += distance * sin(theta);
}
To me it looks like theta would just become zero every time. the line commented "Clip the rotation to plus or minus 360 degrees" seems to basically subtract theta from theta.
Does anyone have any suggestions or similar examples for converting odometry data to a Cartesian coordinate?
To me it looks like theta would just become zero every time. the line commented "Clip the rotation to plus or minus 360 degrees" seems to basically subtract theta from theta.
No. It is subtracting 360 degrees or 0 degrees from a value. Suppose that theta was 150 degrees.
Then, theta/360 would be 0. 0 times 360 is 0. 150 - 0 = 150.
Suppose, instead that theta was 370 degrees. 370/360 = 1. 1 * 360 = 360. 370 - 360 = 10.
Hi RichMo,
Am working on a mobile robot and using rotary encoder and arduino mega. I have problem in determing the position of the robot. Your code catches my interest but i got confused when you talked of pulses per meter in your definitions. And moreso, i dont understand these 3 lines
double distance = ((m_odometerVals[0]/ticksPerM) + (m_odometerVals[1]/ticksPerM)) / 2; // Calculate distance moved in meters
theta += ((((m_odometerVals[0]/ticksPerM) - (m_odometerVals[1]/ticksPerM)) / wheelBase)); // Accumulate change in bearing;
theta -= ((double)((int)(theta/TWOPI))*TWOPI); // clip to +/- 360
I must admit that i am quite new in this field. Your help will be of immense help to me
Thanks in advance
Nelson