Problem 144638 · easy · Robotics · Level 01 Poses and Frames

How Far Did the Wheel Roll?

radians · degrees · arc length · wheel encoder · loops

A small delivery robot counts how far each of its wheels has turned. Every control tick, the wheel's encoder reports the turn since the last tick in degrees: positive when the wheel turned forwards, negative when it turned backwards.

A wheel of radius r that turns by an angle \theta in radians and does not slip rolls the distance

s = r\,\theta

(this is the length of the arc the rim lays on the floor). One full turn is 360 degrees or 2\pi radians, so \theta_{\text{rad}} = \theta_{\text{deg}} \cdot \pi / 180; math.radians does that conversion.

Write wheel_distances(radius, turns) that returns a tuple (distances, net):

  • distances: the list of distances rolled in each tick, in the order of turns, in the units of radius,
  • net: the sum of those distances (how far the robot is from where it started along its straight path; 0.0 for no ticks).

Examples

Input:  radius = 5, turns = [90, 180, -45]
Output: ([7.853981633974483, 15.707963267948966, -3.9269908169872414], 19.634954084936208)
Explanation: 90 degrees is pi/2 radians, so the wheel rolls 5 * pi/2 = 7.854 cm.
The last tick turned backwards and rolled 3.927 cm back.

Input:  radius = 3, turns = [360]
Output: ([18.84955592153876], 18.84955592153876)
Explanation: one full turn rolls the whole rim, 2 * pi * 3.

Constraints

  • answers are compared with a tolerance of 1e-6; do not round

Goals

  • Convert an angle from degrees to radians
  • Use the arc length $s = r\,\theta$ to turn a wheel rotation into a distance
  • Keep the sign: a backwards turn rolls a negative distance
Starting Python…