3namespace tinyrobotics {
6
7
8
9
10enum class SpeedUnit { MPS, KPH, FPS, MPH };
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
43 Speed(
float speed,
SpeedUnit unit) { setValue(speed, unit); }
45 void setValue(
float newSpeed,
SpeedUnit newUnit) {
50 float getValue(
SpeedUnit desiredUnit)
const {
51 if (
unit == desiredUnit)
return speed;
54 if (desiredUnit ==
SpeedUnit::KPH)
return speed * 3.6f;
55 if (desiredUnit ==
SpeedUnit::FPS)
return speed * 3.28084f;
56 if (desiredUnit ==
SpeedUnit::MPH)
return speed * 2.23694f;
59 if (desiredUnit ==
SpeedUnit::MPS)
return speed / 3.6f;
60 if (desiredUnit ==
SpeedUnit::FPS)
return speed * 0.911344f;
61 if (desiredUnit ==
SpeedUnit::MPH)
return speed * 0.621371f;
64 if (desiredUnit ==
SpeedUnit::MPS)
return speed / 3.28084f;
65 if (desiredUnit ==
SpeedUnit::KPH)
return speed * 1.09728f;
66 if (desiredUnit ==
SpeedUnit::MPH)
return speed * 0.681818f;
69 if (desiredUnit ==
SpeedUnit::MPS)
return speed / 2.23694f;
70 if (desiredUnit ==
SpeedUnit::KPH)
return speed * 1.60934f;
71 if (desiredUnit ==
SpeedUnit::FPS)
return speed * 1.46667f;
78 float otherSpeed = other.getValue(
unit);
83 float otherSpeed = other.getValue(
unit);
87 Speed operator*(
float scalar)
const {
91 Speed operator/(
float scalar)
const {
96 bool operator==(
const Speed& other)
const {
97 return speed == other.getValue(
unit);
100 bool operator!=(
const Speed& other)
const {
return !(*
this == other); }
102 bool operator<(
const Speed& other)
const {
103 return speed < other.getValue(
unit);
106 bool operator<=(
const Speed& other)
const {
107 return speed <= other.getValue(
unit);
110 bool operator>(
const Speed& other)
const {
111 return speed > other.getValue(
unit);
114 bool operator>=(
const Speed& other)
const {
115 return speed >= other.getValue(
unit);
119 speed += other.getValue(
unit);
124 speed -= other.getValue(
unit);
128 Speed& operator*=(
float scalar) {
133 Speed& operator/=(
float scalar) {
147using Velocity =
Speed;
Represents a speed measurement with unit conversion support.
Definition: Speed.h:40
SpeedUnit unit
Unit of the speed.
Definition: Speed.h:144
SpeedUnit
Supported speed units for conversion and representation.
Definition: Speed.h:10