4 added picture, explained that the sample code had simplified math edited Jul 23 '14 at 4:53 Robz 1,85233 gold badges1717 silver badges2626 bronze badges To answer your first question: if you really want to find the true kinematic equations for differential drive, I wouldn't start approximating by assuming that each wheel has moved in a straight line. Instead, find the turning radius, calculate the center point of the arc, and then calculate the robot's next point. The turning radius would be infinite if the robot is moving straight, but in the straight case the math is simple. Here's So, just imagine that over each time step, or each time you calculate the change in the incremental sensors, the robot travels from point A to point B on an arc like this: Here's some sample code with the math simplified: // leftDelta and rightDelta = distance that the left and right wheel have moved along // the ground if (fabs(leftDelta - rightDelta) < 1.0e-6) { // basically going straight new_x = x + leftDelta * cos(heading); new_y = y + rightDelta * sin(heading); new_heading = heading; } else { float R = unitsAxisWidth * (leftDelta + rightDelta) / (2 * (rightDelta - leftDelta)), wd = (rightDelta - leftDelta) / unitsAxisWidth; new_x = x + R * sin(wd + heading) - R * sin(heading); new_y = y - R * cos(wd + heading) + R * cos(heading); new_heading = boundAngle(heading + wd); }  I used similar math in a simulator to demonstrate different ways of steering: http://www.cs.utexas.edu/~rjnevels/RobotSimulator4/demos/SteeringDemo/ To answer your first question: if you really want to find the true kinematic equations for differential drive, I wouldn't start approximating by assuming that each wheel has moved in a straight line. Instead, find the turning radius, calculate the center point of the arc, and then calculate the robot's next point. The turning radius would be infinite if the robot is moving straight, but in the straight case the math is simple. Here's some sample code: // leftDelta and rightDelta = distance that the left and right wheel have moved along // the ground if (fabs(leftDelta - rightDelta) < 1.0e-6) { // basically going straight new_x = x + leftDelta * cos(heading); new_y = y + rightDelta * sin(heading); new_heading = heading; } else { float R = unitsAxisWidth * (leftDelta + rightDelta) / (2 * (rightDelta - leftDelta)), wd = (rightDelta - leftDelta) / unitsAxisWidth; new_x = x + R * sin(wd + heading) - R * sin(heading); new_y = y - R * cos(wd + heading) + R * cos(heading); new_heading = boundAngle(heading + wd); }  I used similar math in a simulator to demonstrate different ways of steering: http://www.cs.utexas.edu/~rjnevels/RobotSimulator4/demos/SteeringDemo/ To answer your first question: if you really want to find the true kinematic equations for differential drive, I wouldn't start approximating by assuming that each wheel has moved in a straight line. Instead, find the turning radius, calculate the center point of the arc, and then calculate the robot's next point. The turning radius would be infinite if the robot is moving straight, but in the straight case the math is simple. So, just imagine that over each time step, or each time you calculate the change in the incremental sensors, the robot travels from point A to point B on an arc like this: Here's some sample code with the math simplified: // leftDelta and rightDelta = distance that the left and right wheel have moved along // the ground if (fabs(leftDelta - rightDelta) < 1.0e-6) { // basically going straight new_x = x + leftDelta * cos(heading); new_y = y + rightDelta * sin(heading); new_heading = heading; } else { float R = unitsAxisWidth * (leftDelta + rightDelta) / (2 * (rightDelta - leftDelta)), wd = (rightDelta - leftDelta) / unitsAxisWidth; new_x = x + R * sin(wd + heading) - R * sin(heading); new_y = y - R * cos(wd + heading) + R * cos(heading); new_heading = boundAngle(heading + wd); }  I used similar math in a simulator to demonstrate different ways of steering: http://www.cs.utexas.edu/~rjnevels/RobotSimulator4/demos/SteeringDemo/ 3 deleted 23 characters in body; added 141 characters in body edited Aug 1 '13 at 3:21 Robz 1,85233 gold badges1717 silver badges2626 bronze badges Why approximate? IfTo answer your first question: if you really want to find the true kinematic equations for differential drive, don'tI wouldn't start approximating by assuming that each wheel has moved in a straight line. Instead, find the turning radius, calculate the center point of the arc, and then calculate the robot's next point. The turning radius would be infinite if the robot is moving straight, but in the straight case the math is simple. Here's some sample code: // leftDelta and rightDelta = distance that the left and right wheel have moved along // the ground if (fabs(leftDelta - rightDelta) < 1.0e-6) { // basically going straight new_x = x + leftDelta * cos(heading); new_y = y + rightDelta * sin(heading); new_heading = heading; } else { float R = unitsAxisWidth * (leftDelta + rightDelta) / (2 * (rightDelta - leftDelta)), wd = (rightDelta - leftDelta) / unitsAxisWidth; new_x = x + R * sin(wd + heading) - R * sin(heading); new_y = y - R * cos(wd + heading) + R * cos(heading); new_heading = boundAngle(heading + wd); }  I used similar math in a simulator to demonstrate different ways of steering: http://www.cs.utexas.edu/~rjnevels/RobotSimulator4/demos/SteeringDemo/ Why approximate? If you really want to find the true kinematic equations for differential drive, don't start by assuming that each wheel has moved in a straight line. Instead, find the turning radius, calculate the center point of the arc, and then calculate the robot's next point. The turning radius would be infinite if the robot is moving straight, but in the straight case the math is simple. Here's some sample code: // leftDelta and rightDelta = distance that the left and right wheel have moved along // the ground if (fabs(leftDelta - rightDelta) < 1.0e-6) { // basically going straight new_x = x + leftDelta * cos(heading); new_y = y + rightDelta * sin(heading); new_heading = heading; } else { float R = unitsAxisWidth * (leftDelta + rightDelta) / (2 * (rightDelta - leftDelta)), wd = (rightDelta - leftDelta) / unitsAxisWidth; new_x = x + R * sin(wd + heading) - R * sin(heading); new_y = y - R * cos(wd + heading) + R * cos(heading); new_heading = boundAngle(heading + wd); }  I used similar math in a simulator to demonstrate different ways of steering: http://www.cs.utexas.edu/~rjnevels/RobotSimulator4/demos/SteeringDemo/ To answer your first question: if you really want to find the true kinematic equations for differential drive, I wouldn't start approximating by assuming that each wheel has moved in a straight line. Instead, find the turning radius, calculate the center point of the arc, and then calculate the robot's next point. The turning radius would be infinite if the robot is moving straight, but in the straight case the math is simple. Here's some sample code: // leftDelta and rightDelta = distance that the left and right wheel have moved along // the ground if (fabs(leftDelta - rightDelta) < 1.0e-6) { // basically going straight new_x = x + leftDelta * cos(heading); new_y = y + rightDelta * sin(heading); new_heading = heading; } else { float R = unitsAxisWidth * (leftDelta + rightDelta) / (2 * (rightDelta - leftDelta)), wd = (rightDelta - leftDelta) / unitsAxisWidth; new_x = x + R * sin(wd + heading) - R * sin(heading); new_y = y - R * cos(wd + heading) + R * cos(heading); new_heading = boundAngle(heading + wd); }  I used similar math in a simulator to demonstrate different ways of steering: http://www.cs.utexas.edu/~rjnevels/RobotSimulator4/demos/SteeringDemo/ 2 deleted 23 characters in body; added 141 characters in body edited Aug 1 '13 at 3:14 Robz 1,85233 gold badges1717 silver badges2626 bronze badges Why approximate? If you really want to find the true kinematic equations for differential drive, don't start by assuming that each wheel has moved in a straight line. Instead, find the turning radius, calculate the center point of the arc, and then calculate the robot's next point. The turning radius would be infinite if the robot is moving straight, but in the straight case the math is simple. Here's some sample code: // leftDelta and rightDelta = distance that the left and right wheel have moved along // the ground if (fabs(leftDelta - rightDelta) < 1.0e-6) { // basically going straight new_x = x + leftDelta * cos(heading); new_y = y + rightDelta * sin(heading); new_heading = heading; } else { float R = unitsAxisWidth * (leftDelta + rightDelta) / (2 * (rightDelta - leftDelta)), wd = (rightDelta - leftDelta) / unitsAxisWidth; new_x = x + R * sin(wd + heading) - R * sin(heading); new_y = y - R * cos(wd + heading) + R * cos(heading); new_heading = boundAngle(heading + wd); }  I used similar math along with some others in a simulator to demonstrate different ways of steering: http://www.cs.utexas.edu/~rjnevels/RobotSimulator4/demos/SteeringDemo/ Why approximate? If you really want to find the true kinematic equations for differential drive, don't start by assuming that each wheel has moved in a straight line. Instead, find the turning radius, calculate the center point of the arc, and then calculate the robot's next point. The turning radius would be infinite if the robot is moving straight, but in the straight case the math is simple. Here's some sample code: if (fabs(leftDelta - rightDelta) < 1.0e-6) { new_x = x + leftDelta * cos(heading); new_y = y + rightDelta * sin(heading); new_heading = heading; } else { float R = unitsAxisWidth * (leftDelta + rightDelta) / (2 * (rightDelta - leftDelta)), wd = (rightDelta - leftDelta) / unitsAxisWidth; new_x = x + R * sin(wd + heading) - R * sin(heading); new_y = y - R * cos(wd + heading) + R * cos(heading); new_heading = boundAngle(heading + wd); }  I used similar math along with some others in a simulator to demonstrate different ways of steering: http://www.cs.utexas.edu/~rjnevels/RobotSimulator4/demos/SteeringDemo/ Why approximate? If you really want to find the true kinematic equations for differential drive, don't start by assuming that each wheel has moved in a straight line. Instead, find the turning radius, calculate the center point of the arc, and then calculate the robot's next point. The turning radius would be infinite if the robot is moving straight, but in the straight case the math is simple. Here's some sample code: // leftDelta and rightDelta = distance that the left and right wheel have moved along // the ground if (fabs(leftDelta - rightDelta) < 1.0e-6) { // basically going straight new_x = x + leftDelta * cos(heading); new_y = y + rightDelta * sin(heading); new_heading = heading; } else { float R = unitsAxisWidth * (leftDelta + rightDelta) / (2 * (rightDelta - leftDelta)), wd = (rightDelta - leftDelta) / unitsAxisWidth; new_x = x + R * sin(wd + heading) - R * sin(heading); new_y = y - R * cos(wd + heading) + R * cos(heading); new_heading = boundAngle(heading + wd); }  I used similar math in a simulator to demonstrate different ways of steering: http://www.cs.utexas.edu/~rjnevels/RobotSimulator4/demos/SteeringDemo/ 1 answered Jul 31 '13 at 9:52 Robz 1,85233 gold badges1717 silver badges2626 bronze badges