-
Notifications
You must be signed in to change notification settings - Fork 1k
/
stabilizer.c
843 lines (703 loc) · 22.5 KB
/
stabilizer.c
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
/**
* || ____ _ __
* +------+ / __ )(_) /_______________ _____ ___
* | 0xBC | / __ / / __/ ___/ ___/ __ `/_ / / _ \
* +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
* || || /_____/_/\__/\___/_/ \__,_/ /___/\___/
*
* Crazyflie Firmware
*
* Copyright (C) 2011-2022 Bitcraze AB
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, in version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
#define DEBUG_MODULE "STAB"
#include <math.h>
#include "FreeRTOS.h"
#include "task.h"
#include "system.h"
#include "log.h"
#include "param.h"
#include "debug.h"
#include "motors.h"
#include "pm.h"
#include "platform.h"
#include "stabilizer.h"
#include "sensors.h"
#include "commander.h"
#include "crtp_commander_high_level.h"
#include "crtp_localization_service.h"
#include "controller.h"
#include "power_distribution.h"
#include "collision_avoidance.h"
#include "health.h"
#include "supervisor.h"
#include "estimator.h"
#include "usddeck.h"
#include "quatcompress.h"
#include "statsCnt.h"
#include "static_mem.h"
#include "rateSupervisor.h"
static bool isInit;
static uint32_t inToOutLatency;
// State variables for the stabilizer
static setpoint_t setpoint;
static sensorData_t sensorData;
static state_t state;
static control_t control;
static motors_thrust_uncapped_t motorThrustUncapped;
static motors_thrust_uncapped_t motorThrustBatCompUncapped;
static motors_thrust_pwm_t motorPwm;
// For scratch storage - never logged or passed to other subsystems.
static setpoint_t tempSetpoint;
static StateEstimatorType estimatorType;
static ControllerType controllerType;
static STATS_CNT_RATE_DEFINE(stabilizerRate, 500);
static rateSupervisor_t rateSupervisorContext;
static bool rateWarningDisplayed = false;
static struct {
// position - mm
int16_t x;
int16_t y;
int16_t z;
// velocity - mm / sec
int16_t vx;
int16_t vy;
int16_t vz;
// acceleration - mm / sec^2
int16_t ax;
int16_t ay;
int16_t az;
// compressed quaternion, see quatcompress.h
int32_t quat;
// angular velocity - milliradians / sec
int16_t rateRoll;
int16_t ratePitch;
int16_t rateYaw;
} stateCompressed;
static struct {
// position - mm
int16_t x;
int16_t y;
int16_t z;
// velocity - mm / sec
int16_t vx;
int16_t vy;
int16_t vz;
// acceleration - mm / sec^2
int16_t ax;
int16_t ay;
int16_t az;
} setpointCompressed;
STATIC_MEM_TASK_ALLOC(stabilizerTask, STABILIZER_TASK_STACKSIZE);
static void stabilizerTask(void* param);
static void calcSensorToOutputLatency(const sensorData_t *sensorData)
{
uint64_t outTimestamp = usecTimestamp();
inToOutLatency = outTimestamp - sensorData->interruptTimestamp;
}
static void compressState()
{
stateCompressed.x = state.position.x * 1000.0f;
stateCompressed.y = state.position.y * 1000.0f;
stateCompressed.z = state.position.z * 1000.0f;
stateCompressed.vx = state.velocity.x * 1000.0f;
stateCompressed.vy = state.velocity.y * 1000.0f;
stateCompressed.vz = state.velocity.z * 1000.0f;
stateCompressed.ax = state.acc.x * 9.81f * 1000.0f;
stateCompressed.ay = state.acc.y * 9.81f * 1000.0f;
stateCompressed.az = (state.acc.z + 1) * 9.81f * 1000.0f;
float const q[4] = {
state.attitudeQuaternion.x,
state.attitudeQuaternion.y,
state.attitudeQuaternion.z,
state.attitudeQuaternion.w};
stateCompressed.quat = quatcompress(q);
float const deg2millirad = ((float)M_PI * 1000.0f) / 180.0f;
stateCompressed.rateRoll = sensorData.gyro.x * deg2millirad;
stateCompressed.ratePitch = -sensorData.gyro.y * deg2millirad;
stateCompressed.rateYaw = sensorData.gyro.z * deg2millirad;
}
static void compressSetpoint()
{
setpointCompressed.x = setpoint.position.x * 1000.0f;
setpointCompressed.y = setpoint.position.y * 1000.0f;
setpointCompressed.z = setpoint.position.z * 1000.0f;
setpointCompressed.vx = setpoint.velocity.x * 1000.0f;
setpointCompressed.vy = setpoint.velocity.y * 1000.0f;
setpointCompressed.vz = setpoint.velocity.z * 1000.0f;
setpointCompressed.ax = setpoint.acceleration.x * 1000.0f;
setpointCompressed.ay = setpoint.acceleration.y * 1000.0f;
setpointCompressed.az = setpoint.acceleration.z * 1000.0f;
}
void stabilizerInit(StateEstimatorType estimator)
{
if(isInit)
return;
sensorsInit();
stateEstimatorInit(estimator);
controllerInit(ControllerTypeAutoSelect);
powerDistributionInit();
motorsInit(platformConfigGetMotorMapping());
collisionAvoidanceInit();
estimatorType = stateEstimatorGetType();
controllerType = controllerGetType();
STATIC_MEM_TASK_CREATE(stabilizerTask, stabilizerTask, STABILIZER_TASK_NAME, NULL, STABILIZER_TASK_PRI);
isInit = true;
}
bool stabilizerTest(void)
{
bool pass = true;
pass &= sensorsTest();
pass &= stateEstimatorTest();
pass &= controllerTest();
pass &= powerDistributionTest();
pass &= motorsTest();
pass &= collisionAvoidanceTest();
return pass;
}
static void batteryCompensation(const motors_thrust_uncapped_t* motorThrustUncapped, motors_thrust_uncapped_t* motorThrustBatCompUncapped)
{
float supplyVoltage = pmGetBatteryVoltage();
for (int motor = 0; motor < STABILIZER_NR_OF_MOTORS; motor++)
{
motorThrustBatCompUncapped->list[motor] = motorsCompensateBatteryVoltage(motor, motorThrustUncapped->list[motor], supplyVoltage);
}
}
static void setMotorRatios(const motors_thrust_pwm_t* motorPwm)
{
motorsSetRatio(MOTOR_M1, motorPwm->motors.m1);
motorsSetRatio(MOTOR_M2, motorPwm->motors.m2);
motorsSetRatio(MOTOR_M3, motorPwm->motors.m3);
motorsSetRatio(MOTOR_M4, motorPwm->motors.m4);
}
static void updateStateEstimatorAndControllerTypes() {
if (stateEstimatorGetType() != estimatorType) {
stateEstimatorSwitchTo(estimatorType);
estimatorType = stateEstimatorGetType();
}
if (controllerGetType() != controllerType) {
controllerInit(controllerType);
controllerType = controllerGetType();
}
}
static void logCapWarning(const bool isCapped) {
#ifdef CONFIG_LOG_MOTOR_CAP_WARNING
static uint32_t nextReportTick = 0;
if (isCapped) {
uint32_t now = xTaskGetTickCount();
if (now > nextReportTick) {
DEBUG_PRINT("Warning: motor thrust saturated\n");
nextReportTick = now + M2T(3000);
}
}
#endif
}
static void controlMotors(const control_t* control) {
powerDistribution(control, &motorThrustUncapped);
batteryCompensation(&motorThrustUncapped, &motorThrustBatCompUncapped);
const bool isCapped = powerDistributionCap(&motorThrustBatCompUncapped, &motorPwm);
logCapWarning(isCapped);
setMotorRatios(&motorPwm);
}
/* The stabilizer loop runs at 1kHz. It is the
* responsibility of the different functions to run slower by skipping call
* (ie. returning without modifying the output structure).
*/
static void stabilizerTask(void* param)
{
stabilizerStep_t stabilizerStep;
uint32_t lastWakeTime;
vTaskSetApplicationTaskTag(0, (void*)TASK_STABILIZER_ID_NBR);
//Wait for the system to be fully started to start stabilization loop
systemWaitStart();
DEBUG_PRINT("Wait for sensor calibration...\n");
// Wait for sensors to be calibrated
lastWakeTime = xTaskGetTickCount();
while(!sensorsAreCalibrated()) {
vTaskDelayUntil(&lastWakeTime, F2T(RATE_MAIN_LOOP));
}
// Initialize stabilizerStep to something else than 0
stabilizerStep = 1;
systemWaitStart();
DEBUG_PRINT("Starting stabilizer loop\n");
rateSupervisorInit(&rateSupervisorContext, xTaskGetTickCount(), M2T(1000), 997, 1003, 1);
while(1) {
// The sensor should unlock at 1kHz
sensorsWaitDataReady();
// update sensorData struct (for logging variables)
sensorsAcquire(&sensorData);
if (healthShallWeRunTest()) {
healthRunTests(&sensorData);
} else {
updateStateEstimatorAndControllerTypes();
stateEstimator(&state, stabilizerStep);
const bool areMotorsAllowedToRun = supervisorAreMotorsAllowedToRun();
// Critical for safety, be careful if you modify this code!
crtpCommanderBlock(! areMotorsAllowedToRun);
if (crtpCommanderHighLevelGetSetpoint(&tempSetpoint, &state, stabilizerStep)) {
commanderSetSetpoint(&tempSetpoint, COMMANDER_PRIORITY_HIGHLEVEL);
}
commanderGetSetpoint(&setpoint, &state);
// Critical for safety, be careful if you modify this code!
// Let the supervisor update it's view of the current situation
supervisorUpdate(&sensorData, &setpoint, stabilizerStep);
// Let the collision avoidance module modify the setpoint, if needed
collisionAvoidanceUpdateSetpoint(&setpoint, &sensorData, &state, stabilizerStep);
// Critical for safety, be careful if you modify this code!
// Let the supervisor modify the setpoint to handle exceptional conditions
supervisorOverrideSetpoint(&setpoint);
controller(&control, &setpoint, &sensorData, &state, stabilizerStep);
// Critical for safety, be careful if you modify this code!
// The supervisor will already set thrust to 0 in the setpoint if needed, but to be extra sure prevent motors from running.
if (areMotorsAllowedToRun) {
controlMotors(&control);
} else {
motorsStop();
}
// Compute compressed log formats
compressState();
compressSetpoint();
#ifdef CONFIG_DECK_USD
// Log data to uSD card if configured
if (usddeckLoggingEnabled()
&& usddeckLoggingMode() == usddeckLoggingMode_SynchronousStabilizer
&& RATE_DO_EXECUTE(usddeckFrequency(), stabilizerStep)) {
usddeckTriggerLogging();
}
#endif
calcSensorToOutputLatency(&sensorData);
stabilizerStep++;
STATS_CNT_RATE_EVENT(&stabilizerRate);
if (!rateSupervisorValidate(&rateSupervisorContext, xTaskGetTickCount())) {
if (!rateWarningDisplayed) {
DEBUG_PRINT("WARNING: stabilizer loop rate is off (%lu)\n", rateSupervisorLatestCount(&rateSupervisorContext));
rateWarningDisplayed = true;
}
}
}
#ifdef CONFIG_MOTORS_ESC_PROTOCOL_DSHOT
motorsBurstDshot();
#endif
}
}
/**
* Parameters to set the estimator and controller type
* for the stabilizer module
*/
PARAM_GROUP_START(stabilizer)
/**
* @brief Estimator type Auto select(0), complementary(1), extended kalman(2), **unscented kalman(3) (Default: 0)
*
* ** Experimental, needs to be enabled in kbuild
*/
PARAM_ADD_CORE(PARAM_UINT8, estimator, &estimatorType)
/**
* @brief Controller type Auto select(0), PID(1), Mellinger(2), INDI(3), Brescianini(4) (Default: 0)
*/
PARAM_ADD_CORE(PARAM_UINT8, controller, &controllerType)
PARAM_GROUP_STOP(stabilizer)
/**
* Log group for the current controller target
*
* Note: all members may not be updated depending on how the system is used
*/
LOG_GROUP_START(ctrltarget)
/**
* @brief Desired position X [m]
*/
LOG_ADD_CORE(LOG_FLOAT, x, &setpoint.position.x)
/**
* @brief Desired position Y [m]
*/
LOG_ADD_CORE(LOG_FLOAT, y, &setpoint.position.y)
/**
* @brief Desired position X [m]
*/
LOG_ADD_CORE(LOG_FLOAT, z, &setpoint.position.z)
/**
* @brief Desired velocity X [m/s]
*/
LOG_ADD_CORE(LOG_FLOAT, vx, &setpoint.velocity.x)
/**
* @brief Desired velocity Y [m/s]
*/
LOG_ADD_CORE(LOG_FLOAT, vy, &setpoint.velocity.y)
/**
* @brief Desired velocity Z [m/s]
*/
LOG_ADD_CORE(LOG_FLOAT, vz, &setpoint.velocity.z)
/**
* @brief Desired acceleration X [m/s^2]
*/
LOG_ADD_CORE(LOG_FLOAT, ax, &setpoint.acceleration.x)
/**
* @brief Desired acceleration Y [m/s^2]
*/
LOG_ADD_CORE(LOG_FLOAT, ay, &setpoint.acceleration.y)
/**
* @brief Desired acceleration Z [m/s^2]
*/
LOG_ADD_CORE(LOG_FLOAT, az, &setpoint.acceleration.z)
/**
* @brief Desired attitude, roll [deg]
*/
LOG_ADD_CORE(LOG_FLOAT, roll, &setpoint.attitude.roll)
/**
* @brief Desired attitude, pitch [deg]
*/
LOG_ADD_CORE(LOG_FLOAT, pitch, &setpoint.attitude.pitch)
/**
* @brief Desired attitude rate, yaw rate [deg/s]
*/
LOG_ADD_CORE(LOG_FLOAT, yaw, &setpoint.attitudeRate.yaw)
LOG_GROUP_STOP(ctrltarget)
/**
* Log group for the current controller target, compressed format.
* This flavour of the controller target logs are defined with types
* that use less space and makes it possible to add more logs to a
* log configuration.
*
* Note: all members may not be updated depending on how the system is used
*/
LOG_GROUP_START(ctrltargetZ)
/**
* @brief Desired position X [mm]
*/
LOG_ADD(LOG_INT16, x, &setpointCompressed.x)
/**
* @brief Desired position Y [mm]
*/
LOG_ADD(LOG_INT16, y, &setpointCompressed.y)
/**
* @brief Desired position Z [mm]
*/
LOG_ADD(LOG_INT16, z, &setpointCompressed.z)
/**
* @brief Desired velocity X [mm/s]
*/
LOG_ADD(LOG_INT16, vx, &setpointCompressed.vx)
/**
* @brief Desired velocity Y [mm/s]
*/
LOG_ADD(LOG_INT16, vy, &setpointCompressed.vy)
/**
* @brief Desired velocity Z [mm/s]
*/
LOG_ADD(LOG_INT16, vz, &setpointCompressed.vz)
/**
* @brief Desired acceleration X [mm/s^2]
*/
LOG_ADD(LOG_INT16, ax, &setpointCompressed.ax)
/**
* @brief Desired acceleration Y [mm/s^2]
*/
LOG_ADD(LOG_INT16, ay, &setpointCompressed.ay)
/**
* @brief Desired acceleration Z [mm/s^2]
*/
LOG_ADD(LOG_INT16, az, &setpointCompressed.az)
LOG_GROUP_STOP(ctrltargetZ)
/**
* Logs to set the estimator and controller type
* for the stabilizer module
*/
LOG_GROUP_START(stabilizer)
/**
* @brief Estimated roll
* Note: Same as stateEstimate.roll
*/
LOG_ADD(LOG_FLOAT, roll, &state.attitude.roll)
/**
* @brief Estimated pitch
* Note: Same as stateEstimate.pitch
*/
LOG_ADD(LOG_FLOAT, pitch, &state.attitude.pitch)
/**
* @brief Estimated yaw
* Note: same as stateEstimate.yaw
*/
LOG_ADD(LOG_FLOAT, yaw, &state.attitude.yaw)
/**
* @brief Current thrust
*/
LOG_ADD(LOG_FLOAT, thrust, &control.thrust)
/**
* @brief Rate of stabilizer loop
*/
STATS_CNT_RATE_LOG_ADD(rtStab, &stabilizerRate)
/**
* @brief Latency from sampling of sensor to motor output
* Note: Used for debugging but could also be used as a system test
*/
LOG_ADD(LOG_UINT32, intToOut, &inToOutLatency)
LOG_GROUP_STOP(stabilizer)
/**
* Log group for accelerometer sensor measurement, based on body frame.
* Compensated for a miss-alignment by gravity at startup.
*
* For data on measurement noise please see information from the sensor
* manufacturer. To see what accelerometer sensor is in your Crazyflie or Bolt
* please check documentation on the Bitcraze webpage or check the parameter
* group `imu_sensors`.
*/
LOG_GROUP_START(acc)
/**
* @brief Acceleration in X [Gs]
*/
LOG_ADD_CORE(LOG_FLOAT, x, &sensorData.acc.x)
/**
* @brief Acceleration in Y [Gs]
*/
LOG_ADD_CORE(LOG_FLOAT, y, &sensorData.acc.y)
/**
* @brief Acceleration in Z [Gs]
*/
LOG_ADD_CORE(LOG_FLOAT, z, &sensorData.acc.z)
LOG_GROUP_STOP(acc)
#ifdef LOG_SEC_IMU
LOG_GROUP_START(accSec)
LOG_ADD(LOG_FLOAT, x, &sensorData.accSec.x)
LOG_ADD(LOG_FLOAT, y, &sensorData.accSec.y)
LOG_ADD(LOG_FLOAT, z, &sensorData.accSec.z)
LOG_GROUP_STOP(accSec)
#endif
/**
* Log group for the barometer.
*
* For data on measurement noise please see information from the sensor
* manufacturer. To see what barometer sensor is in your Crazyflie or Bolt
* please check documentation on the Bitcraze webpage or check the parameter
* group `imu_sensors`.
*/
LOG_GROUP_START(baro)
/**
* @brief Altitude above Sea Level [m]
*/
LOG_ADD_CORE(LOG_FLOAT, asl, &sensorData.baro.asl)
/**
* @brief Temperature [degrees Celsius]
*/
LOG_ADD(LOG_FLOAT, temp, &sensorData.baro.temperature)
/**
* @brief Air preassure [mbar]
*/
LOG_ADD_CORE(LOG_FLOAT, pressure, &sensorData.baro.pressure)
LOG_GROUP_STOP(baro)
/**
* Log group for gyroscopes.
*
* For data on measurement noise please see information from the sensor
* manufacturer. To see what gyroscope sensor is in your Crazyflie or Bolt
* please check documentation on the Bitcraze webpage or check the parameter
* group `imu_sensors`.
*/
LOG_GROUP_START(gyro)
/**
* @brief Angular velocity (rotation) around the X-axis, after filtering [deg/s]
*/
LOG_ADD_CORE(LOG_FLOAT, x, &sensorData.gyro.x)
/**
* @brief Angular velocity (rotation) around the Y-axis, after filtering [deg/s]
*/
LOG_ADD_CORE(LOG_FLOAT, y, &sensorData.gyro.y)
/**
* @brief Angular velocity (rotation) around the Z-axis, after filtering [deg/s]
*/
LOG_ADD_CORE(LOG_FLOAT, z, &sensorData.gyro.z)
LOG_GROUP_STOP(gyro)
#ifdef LOG_SEC_IMU
LOG_GROUP_START(gyroSec)
LOG_ADD(LOG_FLOAT, x, &sensorData.gyroSec.x)
LOG_ADD(LOG_FLOAT, y, &sensorData.gyroSec.y)
LOG_ADD(LOG_FLOAT, z, &sensorData.gyroSec.z)
LOG_GROUP_STOP(gyroSec)
#endif
/**
* Log group for magnetometer.
*
* Currently only present on Crazyflie 2.0
*/
LOG_GROUP_START(mag)
/**
* @brief Magnetometer X axis, after filtering [gauss]
*/
LOG_ADD_CORE(LOG_FLOAT, x, &sensorData.mag.x)
/**
* @brief Magnetometer Y axis, after filtering [gauss]
*/
LOG_ADD_CORE(LOG_FLOAT, y, &sensorData.mag.y)
/**
* @brief Magnetometer Z axis, after filtering [gauss]
*/
LOG_ADD_CORE(LOG_FLOAT, z, &sensorData.mag.z)
LOG_GROUP_STOP(mag)
LOG_GROUP_START(controller)
LOG_ADD(LOG_INT16, ctr_yaw, &control.yaw)
LOG_GROUP_STOP(controller)
/**
* Log group for the state estimator, the currently estimated state of the platform.
*
* Note: all values may not be updated depending on which estimator that is used.
*/
LOG_GROUP_START(stateEstimate)
/**
* @brief The estimated position of the platform in the global reference frame, X [m]
*/
LOG_ADD_CORE(LOG_FLOAT, x, &state.position.x)
/**
* @brief The estimated position of the platform in the global reference frame, Y [m]
*/
LOG_ADD_CORE(LOG_FLOAT, y, &state.position.y)
/**
* @brief The estimated position of the platform in the global reference frame, Z [m]
*/
LOG_ADD_CORE(LOG_FLOAT, z, &state.position.z)
/**
* @brief The velocity of the Crazyflie in the global reference frame, X [m/s]
*/
LOG_ADD_CORE(LOG_FLOAT, vx, &state.velocity.x)
/**
* @brief The velocity of the Crazyflie in the global reference frame, Y [m/s]
*/
LOG_ADD_CORE(LOG_FLOAT, vy, &state.velocity.y)
/**
* @brief The velocity of the Crazyflie in the global reference frame, Z [m/s]
*/
LOG_ADD_CORE(LOG_FLOAT, vz, &state.velocity.z)
/**
* @brief The acceleration of the Crazyflie in the global reference frame, X [Gs]
*/
LOG_ADD_CORE(LOG_FLOAT, ax, &state.acc.x)
/**
* @brief The acceleration of the Crazyflie in the global reference frame, Y [Gs]
*/
LOG_ADD_CORE(LOG_FLOAT, ay, &state.acc.y)
/**
* @brief The acceleration of the Crazyflie in the global reference frame, without considering gravity, Z [Gs]
*/
LOG_ADD_CORE(LOG_FLOAT, az, &state.acc.z)
/**
* @brief Attitude, roll angle [deg]
*/
LOG_ADD_CORE(LOG_FLOAT, roll, &state.attitude.roll)
/**
* @brief Attitude, pitch angle (legacy CF2 body coordinate system, where pitch is inverted) [deg]
*/
LOG_ADD_CORE(LOG_FLOAT, pitch, &state.attitude.pitch)
/**
* @brief Attitude, yaw angle [deg]
*/
LOG_ADD_CORE(LOG_FLOAT, yaw, &state.attitude.yaw)
/**
* @brief Attitude as a quaternion, x
*/
LOG_ADD_CORE(LOG_FLOAT, qx, &state.attitudeQuaternion.x)
/**
* @brief Attitude as a quaternion, y
*/
LOG_ADD_CORE(LOG_FLOAT, qy, &state.attitudeQuaternion.y)
/**
* @brief Attitude as a quaternion, z
*/
LOG_ADD_CORE(LOG_FLOAT, qz, &state.attitudeQuaternion.z)
/**
* @brief Attitude as a quaternion, w
*/
LOG_ADD_CORE(LOG_FLOAT, qw, &state.attitudeQuaternion.w)
LOG_GROUP_STOP(stateEstimate)
/**
* Log group for the state estimator, compressed format. This flavour of the
* estimator logs are defined with types that use less space and makes it possible to
* add more logs to a log configuration.
*
* Note: all values may not be updated depending on which estimator that is used.
*/
LOG_GROUP_START(stateEstimateZ)
/**
* @brief The position of the Crazyflie in the global reference frame, X [mm]
*/
LOG_ADD(LOG_INT16, x, &stateCompressed.x)
/**
* @brief The position of the Crazyflie in the global reference frame, Y [mm]
*/
LOG_ADD(LOG_INT16, y, &stateCompressed.y)
/**
* @brief The position of the Crazyflie in the global reference frame, Z [mm]
*/
LOG_ADD(LOG_INT16, z, &stateCompressed.z)
/**
* @brief The velocity of the Crazyflie in the global reference frame, X [mm/s]
*/
LOG_ADD(LOG_INT16, vx, &stateCompressed.vx)
/**
* @brief The velocity of the Crazyflie in the global reference frame, Y [mm/s]
*/
LOG_ADD(LOG_INT16, vy, &stateCompressed.vy)
/**
* @brief The velocity of the Crazyflie in the global reference frame, Z [mm/s]
*/
LOG_ADD(LOG_INT16, vz, &stateCompressed.vz)
/**
* @brief The acceleration of the Crazyflie in the global reference frame, X [mm/s]
*/
LOG_ADD(LOG_INT16, ax, &stateCompressed.ax)
/**
* @brief The acceleration of the Crazyflie in the global reference frame, Y [mm/s]
*/
LOG_ADD(LOG_INT16, ay, &stateCompressed.ay)
/**
* @brief The acceleration of the Crazyflie in the global reference frame, including gravity, Z [mm/s]
*/
LOG_ADD(LOG_INT16, az, &stateCompressed.az)
/**
* @brief Attitude as a compressed quaternion, see see quatcompress.h for details
*/
LOG_ADD(LOG_UINT32, quat, &stateCompressed.quat)
/**
* @brief Roll rate (angular velocity) [milliradians / sec]
*/
LOG_ADD(LOG_INT16, rateRoll, &stateCompressed.rateRoll)
/**
* @brief Pitch rate (angular velocity) [milliradians / sec]
*/
LOG_ADD(LOG_INT16, ratePitch, &stateCompressed.ratePitch)
/**
* @brief Yaw rate (angular velocity) [milliradians / sec]
*/
LOG_ADD(LOG_INT16, rateYaw, &stateCompressed.rateYaw)
LOG_GROUP_STOP(stateEstimateZ)
LOG_GROUP_START(motor)
/**
* @brief Requested motor power for m1, including battery compensation. Same scale as the motor PWM but uncapped
* and may have values outside the [0 - UINT16_MAX] range.
*/
LOG_ADD(LOG_INT32, m1req, &motorThrustBatCompUncapped.motors.m1)
/**
* @brief Requested motor power for m1, including battery compensation. Same scale as the motor PWM but uncapped
* and may have values outside the [0 - UINT16_MAX] range.
*/
LOG_ADD(LOG_INT32, m2req, &motorThrustBatCompUncapped.motors.m2)
/**
* @brief Requested motor power for m1, including battery compensation. Same scale as the motor PWM but uncapped
* and may have values outside the [0 - UINT16_MAX] range.
*/
LOG_ADD(LOG_INT32, m3req, &motorThrustBatCompUncapped.motors.m3)
/**
* @brief Requested motor power for m1, including battery compensation. Same scale as the motor PWM but uncapped
* and may have values outside the [0 - UINT16_MAX] range.
*/
LOG_ADD(LOG_INT32, m4req, &motorThrustBatCompUncapped.motors.m4)
LOG_GROUP_STOP(motor)