-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommTypes.h
More file actions
222 lines (196 loc) · 3.9 KB
/
commTypes.h
File metadata and controls
222 lines (196 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#ifndef COMM_TYPES_H
#define COMM_TYPES_H
/************* AUXILIAR TYPES ************/
#include "commConfig.h"
#include <stdint.h>
enum class RadioFunction { receiver, sender };
/*
* Network type / catergory configuration
* Attencion: Limited in 15
*/
enum class NetworkType { unknown = 0, generic, ssl, vss };
/*
* Type of the packet position.
* Attention: Limited in 8
*/
enum class PositionType {
unknown = 0,
source,
stop,
motionControl,
rotateControl,
rotateInPoint,
globalMotionControl
};
enum class refereeCommand {
halt = 0,
stop = 4,
forceStart = 11,
ballPlacementYellow = 16,
ballPlacementBlue = 17
};
typedef struct {
uint8_t payload;
uint64_t addr[2];
bool ack;
uint8_t receiveChannel;
uint8_t sendChannel;
uint8_t pipeNum;
bool reConfig;
RadioFunction function;
} NetworkConfig;
typedef struct Motors {
union {
struct {
double m1;
double m2;
double m3;
double m4;
};
double m[4];
};
Motors() {
m1 = 0;
m2 = 0;
m3 = 0;
m4 = 0;
}
Motors(const Motors& other) {
m1 = other.m1;
m2 = other.m2;
m3 = other.m3;
m4 = other.m4;
}
inline Motors operator+(const Motors& a) const {
Motors b;
b.m1 = m1 + a.m1;
b.m2 = m2 + a.m2;
b.m3 = m3 + a.m3;
b.m4 = m4 + a.m4;
return b;
}
inline Motors operator+=(const Motors& a) {
m1 += a.m1;
m2 += a.m2;
m3 += a.m3;
m4 += a.m4;
return *this;
}
inline Motors operator=(const Motors& a) {
m1 = a.m1;
m2 = a.m2;
m3 = a.m3;
m4 = a.m4;
return *this;
}
} Motors;
typedef struct Vector {
double x = 0;
double y = 0;
double w = 0;
Vector() {
x = 0;
y = 0;
w = 0;
}
Vector(double _x, double _y, double _w) {
x = _x;
y = _y;
w = _w;
}
inline Vector operator+(const Vector& a) const {
Vector b;
b.x = x + a.x;
b.y = y + a.y;
b.w = w + a.w;
return b;
}
inline Vector operator-(const Vector& a) const {
Vector b;
b.x = x - a.x;
b.y = y - a.y;
b.w = w - a.w;
return b;
}
inline Vector operator*(const double a) const {
Vector b;
b.x = x * a;
b.y = y * a;
b.w = w * a;
return b;
}
} Vector;
typedef struct KickFlags {
bool front = false;
bool chip = false;
bool charge = false;
float kickStrength = 0;
bool ball = false;
bool dribbler = false;
bool bypassIR = false;
float dribblerSpeed = 0;
KickFlags& operator=(const KickFlags& a) {
front = a.front;
chip = a.chip;
charge = a.charge;
kickStrength = a.kickStrength;
ball = a.ball;
dribbler = a.dribbler;
bypassIR = a.bypassIR;
dribblerSpeed = a.dribblerSpeed;
return *this;
}
} KickFlags;
typedef struct RobotPosition {
Vector v;
bool resetOdometry{};
PositionType type = PositionType::unknown;
double maxSpeed{};
double minSpeed{};
double rotateKp{};
bool usingPropSpeed{};
double minDistanceToPropSpeed{};
bool rotateInClockWise{};
double orbitRadius{};
double approachKp{};
RobotPosition& operator=(const RobotPosition& a) {
resetOdometry = a.resetOdometry;
v = a.v;
type = a.type;
maxSpeed = a.maxSpeed;
minSpeed = a.minSpeed;
rotateKp = a.rotateKp;
usingPropSpeed = a.usingPropSpeed;
minDistanceToPropSpeed = a.minDistanceToPropSpeed;
rotateInClockWise = a.rotateInClockWise;
orbitRadius = a.orbitRadius;
approachKp = a.approachKp;
return *this;
}
} RobotPosition;
typedef struct {
int id = -1;
msgType type;
Motors m;
Motors current;
Vector v;
double dribbler = 0;
double kickLoad = 0;
bool ball = false;
double battery = 0;
uint8_t count = 0;
} RobotInfo;
typedef struct {
int id = -1;
msgType type;
double m1;
double m2;
double m1_desired;
double m2_desired;
int counter;
double battery = 0;
double accel_x = 0;
double accel_y = 0;
double angular_velocity = 0;
} VSSRobotInfo;
#endif // COMM_TYPES_H