Skip to content

Commit 16c5630

Browse files
authored
Merge pull request #1456 from bitcraze/rik/yawconvention
Revert " #338: Fix yawrate sign in commander_generic packets"
2 parents a67821c + a29c74b commit 16c5630

File tree

2 files changed

+113
-29
lines changed

2 files changed

+113
-29
lines changed

src/modules/interface/crtp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <stdint.h>
3131
#include <stdbool.h>
3232

33-
#define CRTP_PROTOCOL_VERSION 8
33+
#define CRTP_PROTOCOL_VERSION 9
3434

3535
#define CRTP_MAX_DATA_SIZE 30
3636

src/modules/src/crtp_commander_generic.c

Lines changed: 112 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,17 @@ typedef void (*packetDecoder_t)(setpoint_t *setpoint, uint8_t type, const void *
6363

6464
/* ---===== 1 - packetType_e enum =====--- */
6565
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,
7477
};
7578

7679
/* ---===== 2 - Decoding functions =====--- */
@@ -86,15 +89,16 @@ static void stopDecoder(setpoint_t *setpoint, uint8_t type, const void *data, si
8689
return;
8790
}
8891

89-
/* velocityDecoder
90-
* Set the Crazyflie velocity in the world coordinate system
91-
*/
9292
struct velocityPacket_s {
9393
float vx; // m in the world frame of reference
9494
float vy; // ...
9595
float vz; // ...
9696
float yawrate; // deg/s
9797
} __attribute__((packed));
98+
99+
/* velocityDecoder
100+
* Set the Crazyflie velocity in the world coordinate system
101+
*/
98102
static void velocityDecoder(setpoint_t *setpoint, uint8_t type, const void *data, size_t datalen)
99103
{
100104
const struct velocityPacket_s *values = data;
@@ -111,18 +115,41 @@ static void velocityDecoder(setpoint_t *setpoint, uint8_t type, const void *data
111115

112116
setpoint->mode.yaw = modeVelocity;
113117

114-
setpoint->attitudeRate.yaw = -values->yawrate;
118+
setpoint->attitudeRate.yaw = values->yawrate;
115119
}
116120

117-
/* zDistanceDecoder
118-
* Set the Crazyflie absolute height and roll/pitch angles
121+
/* legacyVelocityDecoder
122+
* Set the Crazyflie velocity in the world coordinate system
119123
*/
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+
120143
struct zDistancePacket_s {
121144
float roll; // deg
122145
float pitch; // ...
123146
float yawrate; // deg/s
124147
float zDistance; // m in the world frame of reference
125148
} __attribute__((packed));
149+
150+
/* zDistanceDecoder
151+
* Set the Crazyflie absolute height and roll/pitch angles
152+
*/
126153
static void zDistanceDecoder(setpoint_t *setpoint, uint8_t type, const void *data, size_t datalen)
127154
{
128155
const struct zDistancePacket_s *values = data;
@@ -135,6 +162,33 @@ static void zDistanceDecoder(setpoint_t *setpoint, uint8_t type, const void *dat
135162
setpoint->position.z = values->zDistance;
136163

137164

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+
138192
setpoint->mode.yaw = modeVelocity;
139193

140194
setpoint->attitudeRate.yaw = -values->yawrate;
@@ -286,7 +340,7 @@ static void altHoldDecoder(setpoint_t *setpoint, uint8_t type, const void *data,
286340

287341
setpoint->mode.yaw = modeVelocity;
288342

289-
setpoint->attitudeRate.yaw = -values->yawrate;
343+
setpoint->attitudeRate.yaw = values->yawrate;
290344

291345

292346
setpoint->mode.roll = modeAbs;
@@ -296,15 +350,17 @@ static void altHoldDecoder(setpoint_t *setpoint, uint8_t type, const void *data,
296350
setpoint->attitude.pitch = values->pitch;
297351
}
298352

299-
/* hoverDecoder
300-
* Set the Crazyflie absolute height and velocity in the body coordinate system
301-
*/
302353
struct hoverPacket_s {
303354
float vx; // m/s in the body frame of reference
304355
float vy; // ...
305356
float yawrate; // deg/s
306357
float zDistance; // m in the world frame of reference
307358
} __attribute__((packed));
359+
360+
/* hoverDecoder
361+
* Set the Crazyflie absolute height and velocity in the body coordinate system
362+
*/
363+
308364
static void hoverDecoder(setpoint_t *setpoint, uint8_t type, const void *data, size_t datalen)
309365
{
310366
const struct hoverPacket_s *values = data;
@@ -315,6 +371,31 @@ static void hoverDecoder(setpoint_t *setpoint, uint8_t type, const void *data, s
315371
setpoint->position.z = values->zDistance;
316372

317373

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+
318399
setpoint->mode.yaw = modeVelocity;
319400
setpoint->attitudeRate.yaw = -values->yawrate;
320401

@@ -354,7 +435,7 @@ static void fullStateDecoder(setpoint_t *setpoint, uint8_t type, const void *dat
354435
setpoint->velocity.x = (values->v ## x) / 1000.0f; \
355436
setpoint->acceleration.x = (values->a ## x) / 1000.0f; \
356437
setpoint->jerk.x = 0.0f; \
357-
438+
358439
UNPACK(x)
359440
UNPACK(y)
360441
UNPACK(z)
@@ -401,14 +482,17 @@ static void positionDecoder(setpoint_t *setpoint, uint8_t type, const void *data
401482

402483
/* ---===== 3 - packetDecoders array =====--- */
403484
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,
412496
};
413497

414498
/* Decoder switch */
@@ -436,7 +520,7 @@ void crtpCommanderGenericDecodeSetpoint(setpoint_t *setpoint, CRTPPacket *pk)
436520
* configure the maximum angle/rate output given a maximum stick input
437521
* for CRTP packets with emulated CPPM channels (e.g. RC transmitters connecting
438522
* 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.
440524
*/
441525
PARAM_GROUP_START(cppm)
442526

0 commit comments

Comments
 (0)