Haptic Controller
Loading...
Searching...
No Matches
angles.hpp
Go to the documentation of this file.
1#pragma once
2#include <wiring.h>
3#include <optional>
4#include "utils/helpers.hpp"
5
13
18constexpr float convert_angular_units(
19 float ang, const AngleUnits curr_unit,
20 const AngleUnits desr_unit)
21{
22 if (curr_unit == AngleUnits::RADIANS && desr_unit == AngleUnits::DEGREES) {
23 return ang *= (RAD_TO_DEG);
24 }
25 if (curr_unit == AngleUnits::RADIANS && desr_unit == AngleUnits::REVS) {
26 return ang /= (TWO_PI);
27 }
28 if (curr_unit == AngleUnits::DEGREES && desr_unit == AngleUnits::RADIANS) {
29 return ang *= (DEG_TO_RAD);
30 }
31 if (curr_unit == AngleUnits::DEGREES && desr_unit == AngleUnits::REVS) {
32 return ang /= (360.0f);
33 }
34 if (curr_unit == AngleUnits::REVS && desr_unit == AngleUnits::RADIANS) {
35 return ang *= (TWO_PI);
36 }
37 if (curr_unit == AngleUnits::REVS && desr_unit == AngleUnits::DEGREES) {
38 return ang *= (360.0f);
39 }
40 return ang;
41}
42
48 const Limits<float> & angLimits, const AngleUnits curr_unit,
49 const AngleUnits desr_unit)
50{
51 if (curr_unit == AngleUnits::RADIANS && desr_unit == AngleUnits::DEGREES) {
52 return {angLimits.lower * static_cast<float>(RAD_TO_DEG), angLimits.upper * static_cast<float>(RAD_TO_DEG)};
53 }
54 if (curr_unit == AngleUnits::RADIANS && desr_unit == AngleUnits::REVS) {
55 return {angLimits.lower / static_cast<float>(TWO_PI), angLimits.upper / static_cast<float>(TWO_PI)};
56 }
57 if (curr_unit == AngleUnits::DEGREES && desr_unit == AngleUnits::RADIANS) {
58 return {angLimits.lower * static_cast<float>(DEG_TO_RAD), angLimits.upper * static_cast<float>(DEG_TO_RAD)};
59 }
60 if (curr_unit == AngleUnits::DEGREES && desr_unit == AngleUnits::REVS) {
61 return {angLimits.lower / (360.0f), angLimits.upper / (360.0f)};
62 }
63 if (curr_unit == AngleUnits::REVS && desr_unit == AngleUnits::RADIANS) {
64 return {angLimits.lower * static_cast<float>(TWO_PI), angLimits.upper * static_cast<float>(TWO_PI)};
65 }
66 if (curr_unit == AngleUnits::REVS && desr_unit == AngleUnits::DEGREES) {
67 return {angLimits.lower * (360.0f), angLimits.upper * (360.0f)};
68 }
69 return angLimits;
70}
constexpr float convert_angular_units(float ang, const AngleUnits curr_unit, const AngleUnits desr_unit)
Converts an angle from one unit to another.
Definition angles.hpp:18
AngleUnits
Possible angle units, radians, degrees, revolutions.
Definition angles.hpp:8
@ RADIANS
Definition angles.hpp:9
@ REVS
Definition angles.hpp:11
@ DEGREES
Definition angles.hpp:10
Limit struct to store upper and lower limits.
Definition helpers.hpp:34
T upper
Definition helpers.hpp:36
T lower
Definition helpers.hpp:35