Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
wrapped_float.hpp
Go to the documentation of this file.
1#ifndef FANG_ROBOTICS_MCB_TRAP_WRAPPED_FLOAT_HPP
2#define FANG_ROBOTICS_MCB_TRAP_WRAPPED_FLOAT_HPP
4namespace trap
5{
6 namespace algorithms
7 {
12 template<typename Unit>
14 {
15 public:
17 WrappedFloat(Unit value, Unit lowerBound, Unit upperBound)
18 : m_wrappedFloat{static_cast<float>(value),static_cast<float>(lowerBound), static_cast<float>(upperBound)}
19 {
20 }
21
23 : m_wrappedFloat(wrappedFloat.getWrappedValue(), wrappedFloat.getLowerBound(), wrappedFloat.getUpperBound())
24 {
25 }
26
27 bool operator==(const WrappedFloat& other) const
28 {
29 return m_wrappedFloat == other.m_wrappedFloat;
30 }
31
32 void operator+=(const WrappedFloat& other)
33 {
34 m_wrappedFloat += other.m_wrappedFloat;
35 }
36
37 void operator-=(const WrappedFloat& other)
38 {
39 m_wrappedFloat -= other.m_wrappedFloat;
40 }
41
43 {
44 return WrappedFloat {m_wrappedFloat + other.m_wrappedFloat};
45 }
46
48 {
49 return WrappedFloat {m_wrappedFloat - other.m_wrappedFloat};
50 }
51
52 Unit minDifference(const WrappedFloat& other) const
53 {
54 return Unit{m_wrappedFloat.minDifference(other.m_wrappedFloat.getWrappedValue())};
55 }
56
57 Unit minDifference(const Unit& unwrappedValue) const
58 {
59 return Unit{m_wrappedFloat.minDifference(static_cast<float>(unwrappedValue))};
60 }
61
62 void shiftBounds(Unit shiftMagnitude)
63 {
64 m_wrappedFloat.shiftBounds(static_cast<float>(shiftMagnitude));
65 }
66
67
68 static Unit limitValue(const WrappedFloat& valueToLimit, const Unit min, const Unit max, int* status)
69 {
70 const float floatValue{TappedFloat::limitValue(valueToLimit.m_wrappedFloat,
71 static_cast<float>(min),
72 static_cast<float>(max),
73 status)};
74 return Unit{floatValue};
75 }
76
77 static Unit limitValue(const WrappedFloat& valueToLimit, const WrappedFloat& min, const WrappedFloat& max, int* status)
78 {
79 const float floatValue{TappedFloat::limitValue(valueToLimit.m_wrappedFloat,
80 min.m_wrappedFloat,
81 max.m_wrappedFloat,
82 status)};
83 return Unit{floatValue};
84 }
85
86 bool withinRange(const WrappedFloat& lowerBound, const WrappedFloat upperBound) const
87 {
88 return m_wrappedFloat.withinRange(lowerBound.m_wrappedFloat, upperBound.m_wrappedFloat);
89 }
90
91 static Unit rangeOverlap(const WrappedFloat& lowerA, const WrappedFloat& upperA,
92 const WrappedFloat& lowerB, const WrappedFloat& upperB)
93 {
94 const float floatResult{TappedFloat::rangeOverlap(lowerA.m_wrappedFloat, upperA.m_wrappedFloat, lowerB.m_wrappedFloat, upperB.m_wrappedFloat)};
95 return Unit{floatResult};
96 }
97
98 inline Unit getUnwrappedValue() const
99 {
100 return Unit{m_wrappedFloat.getUnwrappedValue()};
101 }
102
103 inline Unit getWrappedValue() const
104 {
105 return Unit{m_wrappedFloat.getWrappedValue()};
106 }
107
108 inline void setWrappedValue(const Unit& newValue)
109 {
110 m_wrappedFloat.setWrappedValue(static_cast<float>(newValue));
111 }
112
113 inline void setUnwrappedValue(const Unit& newValue)
114 {
115 m_wrappedFloat.setUnwrappedValue(static_cast<float>(newValue));
116 }
117
119 {
120 return WrappedFloat(m_wrappedFloat.getNormalized());
121 }
122
123 inline int getRevolutions() const
124 {
125 return m_wrappedFloat.getRevolutions();
126 }
127
128 inline Unit getUpperBound() const
129 {
130 return Unit{m_wrappedFloat.getUpperBound()};
131 }
132
133 inline Unit getLowerBound() const
134 {
135 return Unit{m_wrappedFloat.getLowerBound()};
136 }
137
138 operator double() const
139 {
140 return m_wrappedFloat.getWrappedValue();
141 }
142
143 operator Unit() const
144 {
145 return Unit{m_wrappedFloat.getWrappedValue()};
146 }
147
148 private:
149 TappedFloat m_wrappedFloat;
150 };
151 }
152}
153#endif
Definition wrapped_float.hpp:51
WrappedFloat getNormalized() const
Definition wrapped_float.hpp:315
float getLowerBound() const
Definition wrapped_float.hpp:335
float getWrappedValue() const
Definition wrapped_float.hpp:294
void setUnwrappedValue(float newUnwrappedValue)
Definition wrapped_float.hpp:308
static float limitValue(const WrappedFloat &valueToLimit, const WrappedFloat &min, const WrappedFloat &max, int *status)
Definition wrapped_float.cpp:153
float minDifference(const WrappedFloat &other) const
Definition wrapped_float.cpp:97
bool withinRange(const WrappedFloat &lowerBound, const WrappedFloat &upperBound) const
Definition wrapped_float.cpp:190
void shiftBounds(float shiftMagnitude)
Definition wrapped_float.cpp:121
float getUpperBound() const
Definition wrapped_float.hpp:330
static float rangeOverlap(const WrappedFloat &lowerA, const WrappedFloat &upperA, const WrappedFloat &lowerB, const WrappedFloat &upperB)
Definition wrapped_float.cpp:200
void setWrappedValue(float newWrappedValue)
Definition wrapped_float.hpp:299
int getRevolutions() const
Definition wrapped_float.hpp:325
float getUnwrappedValue() const
Definition wrapped_float.hpp:286
Definition wrapped_float.hpp:14
Unit getWrappedValue() const
Definition wrapped_float.hpp:103
Unit minDifference(const WrappedFloat &other) const
Definition wrapped_float.hpp:52
bool operator==(const WrappedFloat &other) const
Definition wrapped_float.hpp:27
bool withinRange(const WrappedFloat &lowerBound, const WrappedFloat upperBound) const
Definition wrapped_float.hpp:86
static Unit limitValue(const WrappedFloat &valueToLimit, const WrappedFloat &min, const WrappedFloat &max, int *status)
Definition wrapped_float.hpp:77
void operator+=(const WrappedFloat &other)
Definition wrapped_float.hpp:32
void operator-=(const WrappedFloat &other)
Definition wrapped_float.hpp:37
WrappedFloat(Unit value, Unit lowerBound, Unit upperBound)
Definition wrapped_float.hpp:17
int getRevolutions() const
Definition wrapped_float.hpp:123
Unit getUpperBound() const
Definition wrapped_float.hpp:128
Unit minDifference(const Unit &unwrappedValue) const
Definition wrapped_float.hpp:57
WrappedFloat operator+(const WrappedFloat &other) const
Definition wrapped_float.hpp:42
Unit getLowerBound() const
Definition wrapped_float.hpp:133
void setWrappedValue(const Unit &newValue)
Definition wrapped_float.hpp:108
WrappedFloat(const tap::algorithms::WrappedFloat &wrappedFloat)
Definition wrapped_float.hpp:22
WrappedFloat getNormalized() const
Definition wrapped_float.hpp:118
void shiftBounds(Unit shiftMagnitude)
Definition wrapped_float.hpp:62
void setUnwrappedValue(const Unit &newValue)
Definition wrapped_float.hpp:113
static Unit limitValue(const WrappedFloat &valueToLimit, const Unit min, const Unit max, int *status)
Definition wrapped_float.hpp:68
Unit getUnwrappedValue() const
Definition wrapped_float.hpp:98
WrappedFloat operator-(const WrappedFloat &other) const
Definition wrapped_float.hpp:47
static Unit rangeOverlap(const WrappedFloat &lowerA, const WrappedFloat &upperA, const WrappedFloat &lowerB, const WrappedFloat &upperB)
Definition wrapped_float.hpp:91
tap::algorithms::WrappedFloat TappedFloat
Definition wrapped_float.hpp:16
Definition dimensional_smooth_pid.hpp:8