@@ -63,14 +63,17 @@ typedef void (*packetDecoder_t)(setpoint_t *setpoint, uint8_t type, const void *
63
63
64
64
/* ---===== 1 - packetType_e enum =====--- */
65
65
enum packet_type {
66
- stopType = 0 ,
67
- velocityWorldType = 1 ,
68
- zDistanceType = 2 ,
69
- cppmEmuType = 3 ,
70
- altHoldType = 4 ,
71
- hoverType = 5 ,
72
- fullStateType = 6 ,
73
- positionType = 7 ,
66
+ stopType = 0 ,
67
+ legacyVelocityWorldType = 1 ,
68
+ legacyZDistanceType = 2 ,
69
+ cppmEmuType = 3 ,
70
+ altHoldType = 4 ,
71
+ legacyHoverType = 5 ,
72
+ fullStateType = 6 ,
73
+ positionType = 7 ,
74
+ velocityWorldType = 8 ,
75
+ zDistanceType = 9 ,
76
+ hoverType = 10 ,
74
77
};
75
78
76
79
/* ---===== 2 - Decoding functions =====--- */
@@ -86,15 +89,16 @@ static void stopDecoder(setpoint_t *setpoint, uint8_t type, const void *data, si
86
89
return ;
87
90
}
88
91
89
- /* velocityDecoder
90
- * Set the Crazyflie velocity in the world coordinate system
91
- */
92
92
struct velocityPacket_s {
93
93
float vx ; // m in the world frame of reference
94
94
float vy ; // ...
95
95
float vz ; // ...
96
96
float yawrate ; // deg/s
97
97
} __attribute__((packed ));
98
+
99
+ /* velocityDecoder
100
+ * Set the Crazyflie velocity in the world coordinate system
101
+ */
98
102
static void velocityDecoder (setpoint_t * setpoint , uint8_t type , const void * data , size_t datalen )
99
103
{
100
104
const struct velocityPacket_s * values = data ;
@@ -111,18 +115,41 @@ static void velocityDecoder(setpoint_t *setpoint, uint8_t type, const void *data
111
115
112
116
setpoint -> mode .yaw = modeVelocity ;
113
117
114
- setpoint -> attitudeRate .yaw = - values -> yawrate ;
118
+ setpoint -> attitudeRate .yaw = values -> yawrate ;
115
119
}
116
120
117
- /* zDistanceDecoder
118
- * Set the Crazyflie absolute height and roll/pitch angles
121
+ /* legacyVelocityDecoder
122
+ * Set the Crazyflie velocity in the world coordinate system
119
123
*/
124
+ static void legacyVelocityDecoder (setpoint_t * setpoint , uint8_t type , const void * data , size_t datalen )
125
+ {
126
+ const struct velocityPacket_s * values = data ;
127
+
128
+ ASSERT (datalen == sizeof (struct velocityPacket_s ));
129
+
130
+ setpoint -> mode .x = modeVelocity ;
131
+ setpoint -> mode .y = modeVelocity ;
132
+ setpoint -> mode .z = modeVelocity ;
133
+
134
+ setpoint -> velocity .x = values -> vx ;
135
+ setpoint -> velocity .y = values -> vy ;
136
+ setpoint -> velocity .z = values -> vz ;
137
+
138
+ setpoint -> mode .yaw = modeVelocity ;
139
+
140
+ setpoint -> attitudeRate .yaw = - values -> yawrate ;
141
+ }
142
+
120
143
struct zDistancePacket_s {
121
144
float roll ; // deg
122
145
float pitch ; // ...
123
146
float yawrate ; // deg/s
124
147
float zDistance ; // m in the world frame of reference
125
148
} __attribute__((packed ));
149
+
150
+ /* zDistanceDecoder
151
+ * Set the Crazyflie absolute height and roll/pitch angles
152
+ */
126
153
static void zDistanceDecoder (setpoint_t * setpoint , uint8_t type , const void * data , size_t datalen )
127
154
{
128
155
const struct zDistancePacket_s * values = data ;
@@ -135,6 +162,33 @@ static void zDistanceDecoder(setpoint_t *setpoint, uint8_t type, const void *dat
135
162
setpoint -> position .z = values -> zDistance ;
136
163
137
164
165
+ setpoint -> mode .yaw = modeVelocity ;
166
+
167
+ setpoint -> attitudeRate .yaw = values -> yawrate ;
168
+
169
+
170
+ setpoint -> mode .roll = modeAbs ;
171
+ setpoint -> mode .pitch = modeAbs ;
172
+
173
+ setpoint -> attitude .roll = values -> roll ;
174
+ setpoint -> attitude .pitch = values -> pitch ;
175
+ }
176
+
177
+ /* legacyZDistanceDecoder
178
+ * Set the Crazyflie absolute height and roll/pitch angles
179
+ */
180
+ static void legacyZDistanceDecoder (setpoint_t * setpoint , uint8_t type , const void * data , size_t datalen )
181
+ {
182
+ const struct zDistancePacket_s * values = data ;
183
+
184
+
185
+ ASSERT (datalen == sizeof (struct zDistancePacket_s ));
186
+
187
+ setpoint -> mode .z = modeAbs ;
188
+
189
+ setpoint -> position .z = values -> zDistance ;
190
+
191
+
138
192
setpoint -> mode .yaw = modeVelocity ;
139
193
140
194
setpoint -> attitudeRate .yaw = - values -> yawrate ;
@@ -286,7 +340,7 @@ static void altHoldDecoder(setpoint_t *setpoint, uint8_t type, const void *data,
286
340
287
341
setpoint -> mode .yaw = modeVelocity ;
288
342
289
- setpoint -> attitudeRate .yaw = - values -> yawrate ;
343
+ setpoint -> attitudeRate .yaw = values -> yawrate ;
290
344
291
345
292
346
setpoint -> mode .roll = modeAbs ;
@@ -296,15 +350,17 @@ static void altHoldDecoder(setpoint_t *setpoint, uint8_t type, const void *data,
296
350
setpoint -> attitude .pitch = values -> pitch ;
297
351
}
298
352
299
- /* hoverDecoder
300
- * Set the Crazyflie absolute height and velocity in the body coordinate system
301
- */
302
353
struct hoverPacket_s {
303
354
float vx ; // m/s in the body frame of reference
304
355
float vy ; // ...
305
356
float yawrate ; // deg/s
306
357
float zDistance ; // m in the world frame of reference
307
358
} __attribute__((packed ));
359
+
360
+ /* hoverDecoder
361
+ * Set the Crazyflie absolute height and velocity in the body coordinate system
362
+ */
363
+
308
364
static void hoverDecoder (setpoint_t * setpoint , uint8_t type , const void * data , size_t datalen )
309
365
{
310
366
const struct hoverPacket_s * values = data ;
@@ -315,6 +371,31 @@ static void hoverDecoder(setpoint_t *setpoint, uint8_t type, const void *data, s
315
371
setpoint -> position .z = values -> zDistance ;
316
372
317
373
374
+ setpoint -> mode .yaw = modeVelocity ;
375
+ setpoint -> attitudeRate .yaw = values -> yawrate ;
376
+
377
+
378
+ setpoint -> mode .x = modeVelocity ;
379
+ setpoint -> mode .y = modeVelocity ;
380
+ setpoint -> velocity .x = values -> vx ;
381
+ setpoint -> velocity .y = values -> vy ;
382
+
383
+ setpoint -> velocity_body = true;
384
+ }
385
+
386
+ /* legacyHoverDecoder
387
+ * Set the Crazyflie absolute height and velocity in the body coordinate system
388
+ */
389
+ static void legacyHoverDecoder (setpoint_t * setpoint , uint8_t type , const void * data , size_t datalen )
390
+ {
391
+ const struct hoverPacket_s * values = data ;
392
+
393
+ ASSERT (datalen == sizeof (struct hoverPacket_s ));
394
+
395
+ setpoint -> mode .z = modeAbs ;
396
+ setpoint -> position .z = values -> zDistance ;
397
+
398
+
318
399
setpoint -> mode .yaw = modeVelocity ;
319
400
setpoint -> attitudeRate .yaw = - values -> yawrate ;
320
401
@@ -354,7 +435,7 @@ static void fullStateDecoder(setpoint_t *setpoint, uint8_t type, const void *dat
354
435
setpoint->velocity.x = (values->v ## x) / 1000.0f; \
355
436
setpoint->acceleration.x = (values->a ## x) / 1000.0f; \
356
437
setpoint->jerk.x = 0.0f; \
357
-
438
+
358
439
UNPACK (x )
359
440
UNPACK (y )
360
441
UNPACK (z )
@@ -401,14 +482,17 @@ static void positionDecoder(setpoint_t *setpoint, uint8_t type, const void *data
401
482
402
483
/* ---===== 3 - packetDecoders array =====--- */
403
484
const static packetDecoder_t packetDecoders [] = {
404
- [stopType ] = stopDecoder ,
405
- [velocityWorldType ] = velocityDecoder ,
406
- [zDistanceType ] = zDistanceDecoder ,
407
- [cppmEmuType ] = cppmEmuDecoder ,
408
- [altHoldType ] = altHoldDecoder ,
409
- [hoverType ] = hoverDecoder ,
410
- [fullStateType ] = fullStateDecoder ,
411
- [positionType ] = positionDecoder ,
485
+ [stopType ] = stopDecoder ,
486
+ [legacyVelocityWorldType ] = legacyVelocityDecoder ,
487
+ [legacyZDistanceType ] = legacyZDistanceDecoder ,
488
+ [cppmEmuType ] = cppmEmuDecoder ,
489
+ [altHoldType ] = altHoldDecoder ,
490
+ [legacyHoverType ] = legacyHoverDecoder ,
491
+ [fullStateType ] = fullStateDecoder ,
492
+ [positionType ] = positionDecoder ,
493
+ [velocityWorldType ] = velocityDecoder ,
494
+ [zDistanceType ] = zDistanceDecoder ,
495
+ [hoverType ] = hoverDecoder ,
412
496
};
413
497
414
498
/* Decoder switch */
@@ -436,7 +520,7 @@ void crtpCommanderGenericDecodeSetpoint(setpoint_t *setpoint, CRTPPacket *pk)
436
520
* configure the maximum angle/rate output given a maximum stick input
437
521
* for CRTP packets with emulated CPPM channels (e.g. RC transmitters connecting
438
522
* directly to the NRF radio, often with a 4-in-1 Multimodule), or for CPPM channels
439
- * from an external receiver.
523
+ * from an external receiver.
440
524
*/
441
525
PARAM_GROUP_START (cppm )
442
526
0 commit comments