All problems

Mobile Cart Takes the Long Turn Across the Zero-Degree Boundary

Level 2 · node · Correctness · Missing shortest-turn normalization for circular angles

Scenario

A fictional indoor autonomous cart receives current and target headings in degrees from 0 inclusive to 360 exclusive. Its controller expects the shortest signed turn between -180 and 180 degrees, where positive means clockwise and negative means counterclockwise. The planner currently subtracts headings directly, causing unnecessarily large rotations across the zero-degree boundary.

Requirements

Return the shortest signed rotation between current and target headings. Choose the smaller-magnitude direction across the zero-degree boundary, and correctly handle ordinary rotations and identical headings. Inputs are in [0,360), and exact 180-degree ties are not tested.

Acceptance criteria

  • A normal small clockwise turn returns a positive angle.
  • A turn from 350 degrees to 10 degrees returns +20 degrees.
  • A turn from 10 degrees to 350 degrees returns -20 degrees.
  • Equal current and target headings return zero.