ART v1.0-alpha
A Robot Template that raises the floor for VRC teams
Loading...
Searching...
No Matches
Units.cpp
Go to the documentation of this file.
1
16#include "ART/Units.h"
17
18namespace art
19{
21 {
22 return m_value;
23 }
24
26 {
27 return m_value * 0.2f;
28 }
29
30 double Length::feet()
31 {
32 return inches() / 12.f;
33 }
34
36 {
37 return inches() * .0254f;
38 }
39
41 {
42 return inches() * 2.54f;
43 }
44
46 {
47 return inches() * 25.4f;
48 }
49
51 {
52 return inches() / 24.f;
53 }
54
55 Length Length::operator=(double const &f)
56 {
57 Length output;
58 output.m_value = f;
59 return output;
60 }
61
62 Length::operator double()
63 {
64 return m_value;
65 }
66
67 Length::Length() : m_value(0.0) {}
68
69 Length::Length(double f) : m_value(f) {}
70
71 Length Pixels(double pixels)
72 {
73 Length output;
74 output.m_value = pixels;
75 return output;
76 }
77
78 Length Inches(double inches)
79 {
80 Length output;
81 output.m_value = inches * 5;
82 return output;
83 }
84
85 Length Feet(double feet)
86 {
87 Length output;
88 output.m_value = feet * 5 * 12;
89 return output;
90 }
91
92 Length Meters(double meters)
93 {
94 Length output = Inches(meters);
95 output.m_value = output.m_value * 39.3700787402f;
96 return output;
97 }
98
99 Length Centimeters(double centimeters)
100 {
101 Length output = Inches(centimeters);
102 output.m_value = output.m_value * 0.393700787402f;
103 return output;
104 }
105
106 Length Millimeters(double millimeters)
107 {
108 Length output = Inches(millimeters);
109 output.m_value = output.m_value * .0393700787402f;
110 return output;
111 }
112
113 Length Tiles(double tiles)
114 {
115 Length output = Inches(tiles);
116 output.m_value = output.m_value * 24;
117 return output;
118 }
119
120 Angle Degrees(double degrees)
121 {
122 Angle output;
123 output.m_value = degrees * 3.14159265f / 180;
124 return output;
125 }
126
127 Angle Radians(double radians)
128 {
129 Angle output;
130 output.m_value = radians;
131 return output;
132 }
133
134 Angle Revolutions(double revolutions)
135 {
136 Angle output;
137 output.m_value = revolutions * 2.f * 3.14159265f;
138 return output;
139 }
140
141 Angle::Angle() : m_value(0.0) {}
142
143 Angle::Angle(double f) : m_value(f) {}
144
146 {
147 while (m_value > 3.14159265f)
148 {
149 m_value -= 2.f * 3.14159265f;
150 }
151 while (m_value < -3.14159265f)
152 {
153 m_value += 2.f * 3.14159265f;
154 }
155 }
156
157 Angle Angle::operator=(double const &f)
158 {
159 Angle output;
160 output.m_value = f;
161 return output;
162 }
163
164 Angle::operator double()
165 {
166 // constrain();
167 return m_value;
168 }
169
171 {
172 // constrain();
173 return m_value * 180 / 3.14159265f;
174 }
175
177 {
178 // constrain();
179 return m_value;
180 }
181
183 {
184 // constrain();
185 return m_value / (3.14159265f * 2.f);
186 }
187
189 {
190 Angle angle = target;
191 angle.constrain();
192 if (std::abs(angle.revolutions()) < .5)
193 {
194 return angle;
195 }
196 else
197 {
198 if (angle.revolutions() > 0)
199 {
200 return Revolutions(1 - angle.revolutions());
201 }
202 else
203 {
204 return Revolutions(1 + angle.revolutions());
205 }
206 }
207 return Angle();
208 }
209
210} // namespace art
Header containing several Unit classes.
A Utility Unit class for Angles.
Definition Units.h:275
double revolutions()
Returns the Angle in revolutions.
Definition Units.cpp:182
double m_value
The underlying value of the Angle.
Definition Units.h:405
Angle()
Construct a new Angle object.
Definition Units.cpp:141
double radians()
Returns the Angle in radians.
Definition Units.cpp:176
void constrain()
Constrains the Angle to the -180 to 180 range.
Definition Units.cpp:145
Angle operator=(double const &f)
Assign a value to the Angle object.
Definition Units.cpp:157
double degrees()
Returns the Angle in degrees.
Definition Units.cpp:170
A Utility Unit class for Length.
Definition Units.h:37
double centimeters()
Returns the Length in centimeters.
Definition Units.cpp:40
double meters()
Returns the Length in meters.
Definition Units.cpp:35
double m_value
The underlying value of Length.
Definition Units.h:207
double feet()
Returns the Length in feet.
Definition Units.cpp:30
double millimeters()
Returns the Length in millimeters.
Definition Units.cpp:45
Length()
Construct a new Length object.
Definition Units.cpp:67
double inches()
Returns the Length in inches.
Definition Units.cpp:25
Length operator=(double const &f)
Assign a value to the Length object.
Definition Units.cpp:55
double pixels()
Returns the Length in pixels.
Definition Units.cpp:20
double tiles()
Returns the Length in tiles.
Definition Units.cpp:50
Definition PID.h:20
Length Meters(double meters)
Constructs a Length from Meters.
Definition Units.cpp:92
Angle Degrees(double degrees)
Constructs an Angle from Degrees.
Definition Units.cpp:120
Length Centimeters(double centimeters)
Constructs a Length from Centimeters.
Definition Units.cpp:99
Length Inches(double inches)
Constructs a Length from Inches.
Definition Units.cpp:78
Length Tiles(double tiles)
Constructs a Length from Tiles.
Definition Units.cpp:113
Angle shortestTurnPath(const Angle target)
Returns the shortest turn path to reach the target angle.
Definition Units.cpp:188
Angle Radians(double radians)
Constructs an Angle from Radians.
Definition Units.cpp:127
Length Feet(double feet)
Constructs a Length from Feet.
Definition Units.cpp:85
Length Millimeters(double millimeters)
Constructs a Length from Millimeters.
Definition Units.cpp:106
Angle Revolutions(double revolutions)
Constructs an Angle from Revolutions.
Definition Units.cpp:134
Length Pixels(double pixels)
Constructs a Length from Pixels.
Definition Units.cpp:71