Problem 227533 · easy · Robotics · Level 02 Motion

Two Wheels, One Motion

differential drive · kinematics · turning radius · instantaneous centre of curvature

A library robot carries returned books on two driven wheels, one on each side, a distance L metres apart (castors keep it level). Such a differential drive cannot move sideways: everything it does comes from the two wheel speeds v_left and v_right (metres per second along the floor, negative when a wheel rolls backwards).

The point midway between the wheels moves forward at the average of the two speeds, and the robot turns counter-clockwise (to its left) at a rate set by their difference:

v = \frac{v_r + v_l}{2}, \qquad \omega = \frac{v_r - v_l}{L}

with v in m/s and \omega in radians per second, positive counter-clockwise.

While the wheel speeds stay fixed, the robot drives along a circle around a point on the line through its two wheels, the instantaneous centre of curvature. Its signed turning radius R is the distance from the robot's midpoint to that centre: positive when the centre lies to the robot's left (a left turn), negative when it lies to the right. Two special cases:

  • both wheels at the same speed (stopped included): the robot drives straight and there is no centre; return None for the radius;
  • equal and opposite speeds: the robot spins on the spot around its midpoint; the radius is 0.0.

Write wheel_twist(v_left, v_right, L) that returns the tuple (v, omega, R).

Examples

Input:  v_left = 0.2, v_right = 0.4, L = 0.5
Output: (0.3, 0.4, 0.75)
Explanation: v = (0.4 + 0.2) / 2 = 0.3 m/s and omega = (0.4 - 0.2) / 0.5 = 0.4 rad/s,
a left turn around a centre 0.75 m to the robot's left.

Input:  v_left = 0.3, v_right = 0.3, L = 0.5
Output: (0.3, 0.0, None)

Input:  v_left = -0.1, v_right = 0.1, L = 0.4
Output: (0.0, 0.5, 0.0)
Explanation: the wheels cancel out, so the robot spins counter-clockwise on the spot.

Constraints

  • floats are compared with a tolerance of 1e-6

Goals

  • Turn the speeds of two wheels into the robot's forward speed and turning rate
  • Find the signed radius of the turn, and recognise the straight line and the spin on the spot
Starting Python…