A greenhouse robot's planner decides how the robot should move: forward at v metres per second while turning at omega radians per second (positive counter-clockwise, to the left). The motor drivers do not understand that. Each wants its own wheel's spin rate in radians per second.
The robot is a differential drive: two wheels of radius r metres, a distance L metres apart, with the robot's reference point midway between them. Its motion follows from the two wheels' speeds along the floor, v_l and v_r:
A wheel of radius r spinning at \varphi rad/s rolls along the floor at r\varphi m/s (a positive spin rolls the robot forward).
Write wheel_rates(v, omega, L, r) that returns the tuple (phi_left, phi_right): the spin rates, in rad/s, that make the robot move as planned.
Examples
Input: v = 0.5, omega = 1.0, L = 0.4, r = 0.05
Output: (6.0, 14.0)
Explanation: the right wheel rolls at 0.7 m/s and the left at 0.3 m/s;
divided by the radius 0.05 m that is 14 and 6 rad/s.
Input: v = 0.0, omega = -2.0, L = 0.3, r = 0.06
Output: (5.0, -5.0)
Explanation: a clockwise spin on the spot: the left wheel forward, the right backward.
Constraints
- floats are compared with a tolerance of
1e-6
Goals
- Split a forward speed and a turning rate into the two wheel speeds
- Convert a speed along the floor into a wheel's spin in radians per second