A park's cleaning robot sweeps around a fountain on a circle of radius R metres, its midpoint moving at speed metres per second. The sign of R says which way: R > 0 puts the circle's centre on the robot's left (it drives counter-clockwise), R < 0 on its right (clockwise). |R| is the distance from the robot's midpoint to the centre.
The robot is a differential drive with its two wheels L metres apart. Its forward speed and turning rate come from the wheels' speeds along the ground:
(\omega in rad/s, positive counter-clockwise). A body moving at v while turning at \omega stays on a circle of signed radius v / \omega.
Write circle_lap(R, speed, L) that returns the tuple (v_left, v_right, lap_time): the two wheel speeds in m/s (negative means the wheel rolls backwards) and the time in seconds for the midpoint to go once around the circle.
Examples
Input: R = 1.0, speed = 0.5, L = 0.3
Output: (0.425, 0.575, 12.56637061)
Explanation: omega = 0.5 / 1.0 = 0.5 rad/s; the outer (right) wheel is 0.15 m further out.
One lap is 2 * pi * 1.0 m long, which takes 4 * pi seconds at 0.5 m/s.
Input: R = -0.1, speed = 0.2, L = 0.3
Output: (0.5, -0.1, 3.14159265)
Explanation: a tight clockwise circle, smaller than half the wheel separation,
so the inner (right) wheel rolls backwards.
Constraints
R != 0(a spin on the spot has no forward speed)- floats are compared with a tolerance of
1e-6
Goals
- Choose the turning rate that puts a robot on a circle of a given radius
- Find the wheel speeds for that circle and the time for one lap
- Notice when the inner wheel has to roll backwards