Why are Phoenix6 units in turns?

When I try to get data from a sensor with the Phoenix6 API, it returns values as a units::turn, as opposed to degrees or sensor ticks. I guess all I want to know is why use rotations as the default as opposed to encoder ticks or degrees?

1 Like

As for why turns instead of ticks, physical units are easier to work with and convert. Turns vs degrees is an aesthetic choice, and units::turn_t will autoconvert to your preferred unit type on assignment.

1 Like

Turns is the “natural” unit of rotation for most applications.

Mathematically, an argument can be made for radians - but radians are often inconvenient in physical application. Degrees are highly-familiar but weird and arbitrary.

As @calcmogul noted, the C++ units library will implicitly convert to whatever units you want.

As both Tyler and Oblarg have pointed out, turns is a more canonical unit type than encoder ticks, as they represent an angular position independent of the hardware. Other advantages:

  • Rotations are really easy to convert to other units – Multiply by 360 to get degrees, and multiply by 2pi to get radians. C++ teams get this for free with the units library.
    • Much of WPILib (particularly simulation) also operates in radians per second, rotations per second, or revolutions per minute, which all convert well to rotations.
  • Rotations are easy to reason about – What angle is 1.257 radians? It’s a lot easier to visualize 0.2 rotations.
  • Rotations are often mathematically nicer to work with than degrees – A lot of math operates in radians and radii, or it operates in rotations and circumferences. Degrees almost always need to be converted to radians or rotations somewhere down the line.
  • This wasn’t a deciding factor, but your PID/FF gains with degrees would also be very small – The Kraken X60 has a top speed of around 100 rotations/second, which is a kV of ~0.12. The degrees equivalent would be 36,000 degrees/second, which is a kV of ~0.00033333…
6 Likes

Rotations are honestly the best balance between human understandable units and a mathematically useful unit.

Want to do math with it? Multiply by Tau

Want to think of it visually? Half-turns, quarter turns, eight-turns are also easy to visualize