CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Compass/AP_Compass.h
Views: 1798
1
#pragma once
2
3
#include "AP_Compass_config.h"
4
5
#include <inttypes.h>
6
7
#include <AP_Common/AP_Common.h>
8
#include <AP_Declination/AP_Declination.h>
9
#include <AP_HAL/AP_HAL.h>
10
#include <AP_Math/AP_Math.h>
11
#include <AP_Param/AP_Param.h>
12
#include <GCS_MAVLink/GCS_MAVLink.h>
13
#include <AP_MSP/msp.h>
14
#include <AP_ExternalAHRS/AP_ExternalAHRS.h>
15
16
#include "AP_Compass_Backend.h"
17
#include "Compass_PerMotor.h"
18
#include <AP_Common/TSIndex.h>
19
20
// motor compensation types (for use with motor_comp_enabled)
21
#define AP_COMPASS_MOT_COMP_DISABLED 0x00
22
#define AP_COMPASS_MOT_COMP_THROTTLE 0x01
23
#define AP_COMPASS_MOT_COMP_CURRENT 0x02
24
#define AP_COMPASS_MOT_COMP_PER_MOTOR 0x03
25
26
// setup default mag orientation for some board types
27
#ifndef MAG_BOARD_ORIENTATION
28
#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BEBOP
29
# define MAG_BOARD_ORIENTATION ROTATION_YAW_90
30
#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && (CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBRAIN2 || \
31
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXFMINI)
32
# define MAG_BOARD_ORIENTATION ROTATION_YAW_270
33
#else
34
# define MAG_BOARD_ORIENTATION ROTATION_NONE
35
#endif
36
#endif
37
38
#ifndef COMPASS_MOT_ENABLED
39
#define COMPASS_MOT_ENABLED 1
40
#endif
41
#ifndef COMPASS_LEARN_ENABLED
42
#define COMPASS_LEARN_ENABLED AP_COMPASS_CALIBRATION_FIXED_YAW_ENABLED
43
#endif
44
45
// define default compass calibration fitness and consistency checks
46
#define AP_COMPASS_CALIBRATION_FITNESS_DEFAULT 16.0f
47
#define AP_COMPASS_MAX_XYZ_ANG_DIFF radians(90.0f)
48
#define AP_COMPASS_MAX_XY_ANG_DIFF radians(60.0f)
49
#define AP_COMPASS_MAX_XY_LENGTH_DIFF 200.0f
50
51
/**
52
maximum number of compass instances available on this platform. If more
53
than 1 then redundant sensors may be available
54
*/
55
#ifndef HAL_BUILD_AP_PERIPH
56
#ifndef HAL_COMPASS_MAX_SENSORS
57
#define HAL_COMPASS_MAX_SENSORS 3
58
#endif
59
#if HAL_COMPASS_MAX_SENSORS > 1
60
#define COMPASS_MAX_UNREG_DEV 5
61
#else
62
#define COMPASS_MAX_UNREG_DEV 0
63
#endif
64
#else
65
#ifndef HAL_COMPASS_MAX_SENSORS
66
#define HAL_COMPASS_MAX_SENSORS 1
67
#endif
68
#define COMPASS_MAX_UNREG_DEV 0
69
#endif
70
71
#define COMPASS_MAX_INSTANCES HAL_COMPASS_MAX_SENSORS
72
#define COMPASS_MAX_BACKEND HAL_COMPASS_MAX_SENSORS
73
74
#define MAX_CONNECTED_MAGS (COMPASS_MAX_UNREG_DEV+COMPASS_MAX_INSTANCES)
75
76
#include "CompassCalibrator.h"
77
78
class CompassLearn;
79
80
class Compass
81
{
82
friend class AP_Compass_Backend;
83
public:
84
Compass();
85
86
/* Do not allow copies */
87
CLASS_NO_COPY(Compass);
88
89
// get singleton instance
90
static Compass *get_singleton() {
91
return _singleton;
92
}
93
94
friend class CompassLearn;
95
96
/// Initialize the compass device.
97
///
98
/// @returns True if the compass was initialized OK, false if it was not
99
/// found or is not functioning.
100
///
101
void init();
102
103
/// Read the compass and update the mag_ variables.
104
///
105
bool read();
106
107
// available returns true if the compass is both enabled and has
108
// been initialised
109
bool available() const { return _enabled && init_done; }
110
111
/// Calculate the tilt-compensated heading_ variables.
112
///
113
/// @param dcm_matrix The current orientation rotation matrix
114
///
115
/// @returns heading in radians
116
///
117
float calculate_heading(const Matrix3f &dcm_matrix) const {
118
return calculate_heading(dcm_matrix, _first_usable);
119
}
120
float calculate_heading(const Matrix3f &dcm_matrix, uint8_t i) const;
121
122
/// Sets offset x/y/z values.
123
///
124
/// @param i compass instance
125
/// @param offsets Offsets to the raw mag_ values in milligauss.
126
///
127
void set_offsets(uint8_t i, const Vector3f &offsets);
128
129
/// Sets and saves the compass offset x/y/z values.
130
///
131
/// @param i compass instance
132
/// @param offsets Offsets to the raw mag_ values in milligauss.
133
///
134
void set_and_save_offsets(uint8_t i, const Vector3f &offsets);
135
#if AP_COMPASS_DIAGONALS_ENABLED
136
void set_and_save_diagonals(uint8_t i, const Vector3f &diagonals);
137
void set_and_save_offdiagonals(uint8_t i, const Vector3f &diagonals);
138
#endif
139
void set_and_save_scale_factor(uint8_t i, float scale_factor);
140
void set_and_save_orientation(uint8_t i, Rotation orientation);
141
142
/// Saves the current offset x/y/z values for one or all compasses
143
///
144
/// @param i compass instance
145
///
146
/// This should be invoked periodically to save the offset values maintained by
147
/// ::learn_offsets.
148
///
149
void save_offsets(uint8_t i);
150
void save_offsets(void);
151
152
// return the number of compass instances
153
uint8_t get_count(void) const { return _compass_count; }
154
155
// return the number of enabled sensors
156
uint8_t get_num_enabled(void) const;
157
158
/// Return the current field as a Vector3f in milligauss
159
const Vector3f &get_field(uint8_t i) const { return _get_state(Priority(i)).field; }
160
const Vector3f &get_field(void) const { return get_field(_first_usable); }
161
162
/// Return true if we have set a scale factor for a compass
163
bool have_scale_factor(uint8_t i) const;
164
165
#if COMPASS_MOT_ENABLED
166
// per-motor calibration access
167
void per_motor_calibration_start(void) {
168
_per_motor.calibration_start();
169
}
170
void per_motor_calibration_update(void) {
171
_per_motor.calibration_update();
172
}
173
void per_motor_calibration_end(void) {
174
_per_motor.calibration_end();
175
}
176
#endif
177
178
#if COMPASS_CAL_ENABLED
179
// compass calibrator interface
180
void cal_update();
181
182
// start_calibration_all will only return false if there are no
183
// compasses to calibrate.
184
bool start_calibration_all(bool retry=false, bool autosave=false, float delay_sec=0.0f, bool autoreboot = false);
185
186
void cancel_calibration_all();
187
188
bool compass_cal_requires_reboot() const { return _cal_requires_reboot; }
189
bool is_calibrating() const;
190
191
#if HAL_MAVLINK_BINDINGS_ENABLED
192
/*
193
handle an incoming MAG_CAL command
194
*/
195
MAV_RESULT handle_mag_cal_command(const mavlink_command_int_t &packet);
196
197
bool send_mag_cal_progress(const class GCS_MAVLINK& link);
198
bool send_mag_cal_report(const class GCS_MAVLINK& link);
199
#endif // HAL_MAVLINK_BINDINGS_ENABLED
200
#endif // COMPASS_CAL_ENABLED
201
202
// indicate which bit in LOG_BITMASK indicates we should log compass readings
203
void set_log_bit(uint32_t log_bit) { _log_bit = log_bit; }
204
205
// check if the compasses are pointing in the same direction
206
bool consistent() const;
207
208
/// Return the health of a compass
209
bool healthy(uint8_t i) const;
210
bool healthy(void) const { return healthy(_first_usable); }
211
uint8_t get_healthy_mask() const;
212
213
/// Returns the current offset values
214
///
215
/// @returns The current compass offsets in milligauss.
216
///
217
const Vector3f &get_offsets(uint8_t i) const { return _get_state(Priority(i)).offset; }
218
const Vector3f &get_offsets(void) const { return get_offsets(_first_usable); }
219
220
#if AP_COMPASS_DIAGONALS_ENABLED
221
const Vector3f &get_diagonals(uint8_t i) const { return _get_state(Priority(i)).diagonals; }
222
const Vector3f &get_diagonals(void) const { return get_diagonals(_first_usable); }
223
224
const Vector3f &get_offdiagonals(uint8_t i) const { return _get_state(Priority(i)).offdiagonals; }
225
const Vector3f &get_offdiagonals(void) const { return get_offdiagonals(_first_usable); }
226
#endif // AP_COMPASS_DIAGONALS_ENABLED
227
228
// learn offsets accessor
229
bool learn_offsets_enabled() const { return _learn == LEARN_INFLIGHT; }
230
231
/// return true if the compass should be used for yaw calculations
232
bool use_for_yaw(uint8_t i) const;
233
bool use_for_yaw(void) const;
234
235
/// Sets the local magnetic field declination.
236
///
237
/// @param radians Local field declination.
238
/// @param save_to_eeprom true to save to eeprom (false saves only to memory)
239
///
240
void set_declination(float radians, bool save_to_eeprom = true);
241
float get_declination() const;
242
243
bool auto_declination_enabled() const { return _auto_declination != 0; }
244
245
// set overall board orientation
246
void set_board_orientation(enum Rotation orientation) {
247
_board_orientation = orientation;
248
}
249
250
// get overall board orientation
251
enum Rotation get_board_orientation(void) const {
252
return _board_orientation;
253
}
254
255
/// Set the motor compensation type
256
///
257
/// @param comp_type 0 = disabled, 1 = enabled use throttle, 2 = enabled use current
258
///
259
void motor_compensation_type(const uint8_t comp_type);
260
261
/// get the motor compensation value.
262
uint8_t get_motor_compensation_type() const {
263
return _motor_comp_type;
264
}
265
266
/// Set the motor compensation factor x/y/z values.
267
///
268
/// @param i instance of compass
269
/// @param offsets Offsets multiplied by the throttle value and added to the raw mag_ values.
270
///
271
void set_motor_compensation(uint8_t i, const Vector3f &motor_comp_factor);
272
273
/// get motor compensation factors as a vector
274
const Vector3f& get_motor_compensation(uint8_t i) const { return _get_state(Priority(i)).motor_compensation; }
275
const Vector3f& get_motor_compensation(void) const { return get_motor_compensation(_first_usable); }
276
277
/// Saves the current motor compensation x/y/z values.
278
///
279
/// This should be invoked periodically to save the offset values calculated by the motor compensation auto learning
280
///
281
void save_motor_compensation();
282
283
/// Returns the current motor compensation offset values
284
///
285
/// @returns The current compass offsets in milligauss.
286
///
287
const Vector3f &get_motor_offsets(uint8_t i) const { return _get_state(Priority(i)).motor_offset; }
288
const Vector3f &get_motor_offsets(void) const { return get_motor_offsets(_first_usable); }
289
290
/// Set the throttle as a percentage from 0.0 to 1.0
291
/// @param thr_pct throttle expressed as a percentage from 0 to 1.0
292
void set_throttle(float thr_pct) {
293
if (_motor_comp_type == AP_COMPASS_MOT_COMP_THROTTLE) {
294
_thr = thr_pct;
295
}
296
}
297
298
#if COMPASS_MOT_ENABLED
299
/// Set the battery voltage for per-motor compensation
300
void set_voltage(float voltage) {
301
_per_motor.set_voltage(voltage);
302
}
303
#endif
304
305
/// Returns True if the compasses have been configured (i.e. offsets saved)
306
///
307
/// @returns True if compass has been configured
308
///
309
bool configured(uint8_t i);
310
bool configured(char *failure_msg, uint8_t failure_msg_len);
311
312
// return last update time in microseconds
313
uint32_t last_update_usec(void) const { return last_update_usec(_first_usable); }
314
uint32_t last_update_usec(uint8_t i) const { return _get_state(Priority(i)).last_update_usec; }
315
316
uint32_t last_update_ms(void) const { return last_update_ms(_first_usable); }
317
uint32_t last_update_ms(uint8_t i) const { return _get_state(Priority(i)).last_update_ms; }
318
319
static const struct AP_Param::GroupInfo var_info[];
320
321
enum LearnType {
322
LEARN_NONE=0,
323
LEARN_INTERNAL=1,
324
LEARN_EKF=2,
325
LEARN_INFLIGHT=3
326
};
327
328
// return the chosen learning type
329
enum LearnType get_learn_type(void) const {
330
return (enum LearnType)_learn.get();
331
}
332
333
// set the learning type
334
void set_learn_type(enum LearnType type, bool save) {
335
if (save) {
336
_learn.set_and_save((int8_t)type);
337
} else {
338
_learn.set((int8_t)type);
339
}
340
}
341
342
// return maximum allowed compass offsets
343
uint16_t get_offsets_max(void) const {
344
return (uint16_t)_offset_max.get();
345
}
346
347
uint8_t get_filter_range() const { return uint8_t(_filter_range.get()); }
348
349
#if AP_COMPASS_CALIBRATION_FIXED_YAW_ENABLED
350
/*
351
fast compass calibration given vehicle position and yaw
352
*/
353
bool mag_cal_fixed_yaw(float yaw_deg, uint8_t compass_mask,
354
float lat_deg, float lon_deg,
355
bool force_use=false);
356
#endif
357
358
#if AP_COMPASS_MSP_ENABLED
359
void handle_msp(const MSP::msp_compass_data_message_t &pkt);
360
#endif
361
362
#if AP_COMPASS_EXTERNALAHRS_ENABLED
363
void handle_external(const AP_ExternalAHRS::mag_data_message_t &pkt);
364
#endif
365
366
// force save of current calibration as valid
367
void force_save_calibration(void);
368
369
// get the first compass marked for use by COMPASSx_USE
370
uint8_t get_first_usable(void) const { return _first_usable; }
371
372
private:
373
static Compass *_singleton;
374
375
// Use Priority and StateIndex typesafe index types
376
// to distinguish between two different type of indexing
377
// We use StateIndex for access by Backend
378
// and Priority for access by Frontend
379
DECLARE_TYPESAFE_INDEX(Priority, uint8_t);
380
DECLARE_TYPESAFE_INDEX(StateIndex, uint8_t);
381
382
/// Register a new compas driver, allocating an instance number
383
///
384
/// @param dev_id Dev ID of compass to register against
385
///
386
/// @return instance number saved against the dev id or first available empty instance number
387
bool register_compass(int32_t dev_id, uint8_t& instance);
388
389
// load backend drivers
390
bool _add_backend(AP_Compass_Backend *backend);
391
void _probe_external_i2c_compasses(void);
392
void _detect_backends(void);
393
void probe_i2c_spi_compasses(void);
394
#if AP_COMPASS_DRONECAN_ENABLED
395
void probe_dronecan_compasses(void);
396
#endif
397
398
#if COMPASS_CAL_ENABLED
399
// compass cal
400
void _update_calibration_trampoline();
401
bool _accept_calibration(uint8_t i);
402
bool _accept_calibration_mask(uint8_t mask);
403
void _cancel_calibration(uint8_t i);
404
void _cancel_calibration_mask(uint8_t mask);
405
uint8_t _get_cal_mask();
406
bool _start_calibration(uint8_t i, bool retry=false, float delay_sec=0.0f);
407
bool _start_calibration_mask(uint8_t mask, bool retry=false, bool autosave=false, float delay_sec=0.0f, bool autoreboot=false);
408
bool _auto_reboot() const { return _compass_cal_autoreboot; }
409
#if HAL_MAVLINK_BINDINGS_ENABLED
410
Priority next_cal_progress_idx[MAVLINK_COMM_NUM_BUFFERS];
411
Priority next_cal_report_idx[MAVLINK_COMM_NUM_BUFFERS];
412
#endif
413
#endif // COMPASS_CAL_ENABLED
414
415
// see if we already have probed a i2c driver by bus number and address
416
bool _have_i2c_driver(uint8_t bus_num, uint8_t address) const;
417
418
#if AP_COMPASS_CALIBRATION_FIXED_YAW_ENABLED
419
/*
420
get mag field with the effects of offsets, diagonals and
421
off-diagonals removed
422
*/
423
bool get_uncorrected_field(uint8_t instance, Vector3f &field) const;
424
#endif
425
426
#if COMPASS_CAL_ENABLED
427
//keep track of which calibrators have been saved
428
RestrictIDTypeArray<bool, COMPASS_MAX_INSTANCES, Priority> _cal_saved;
429
bool _cal_autosave;
430
431
//autoreboot after compass calibration
432
bool _compass_cal_autoreboot;
433
bool _cal_requires_reboot;
434
bool _cal_has_run;
435
#endif // COMPASS_CAL_ENABLED
436
437
// enum of drivers for COMPASS_DISBLMSK
438
enum DriverType {
439
#if AP_COMPASS_HMC5843_ENABLED
440
DRIVER_HMC5843 =0,
441
#endif
442
#if AP_COMPASS_LSM303D_ENABLED
443
DRIVER_LSM303D =1,
444
#endif
445
#if AP_COMPASS_AK8963_ENABLED
446
DRIVER_AK8963 =2,
447
#endif
448
#if AP_COMPASS_BMM150_ENABLED
449
DRIVER_BMM150 =3,
450
#endif
451
#if AP_COMPASS_LSM9DS1_ENABLED
452
DRIVER_LSM9DS1 =4,
453
#endif
454
#if AP_COMPASS_LIS3MDL_ENABLED
455
DRIVER_LIS3MDL =5,
456
#endif
457
#if AP_COMPASS_AK09916_ENABLED
458
DRIVER_AK09916 =6,
459
#endif
460
#if AP_COMPASS_IST8310_ENABLED
461
DRIVER_IST8310 =7,
462
#endif
463
#if AP_COMPASS_ICM20948_ENABLED
464
DRIVER_ICM20948 =8,
465
#endif
466
#if AP_COMPASS_MMC3416_ENABLED
467
DRIVER_MMC3416 =9,
468
#endif
469
#if AP_COMPASS_DRONECAN_ENABLED
470
DRIVER_UAVCAN =11,
471
#endif
472
#if AP_COMPASS_QMC5883L_ENABLED
473
DRIVER_QMC5883L =12,
474
#endif
475
#if AP_COMPASS_SITL_ENABLED
476
DRIVER_SITL =13,
477
#endif
478
#if AP_COMPASS_MAG3110_ENABLED
479
DRIVER_MAG3110 =14,
480
#endif
481
#if AP_COMPASS_IST8308_ENABLED
482
DRIVER_IST8308 =15,
483
#endif
484
#if AP_COMPASS_RM3100_ENABLED
485
DRIVER_RM3100 =16,
486
#endif
487
#if AP_COMPASS_MSP_ENABLED
488
DRIVER_MSP =17,
489
#endif
490
#if AP_COMPASS_EXTERNALAHRS_ENABLED
491
DRIVER_EXTERNALAHRS =18,
492
#endif
493
#if AP_COMPASS_MMC5XX3_ENABLED
494
DRIVER_MMC5XX3 =19,
495
#endif
496
#if AP_COMPASS_QMC5883P_ENABLED
497
DRIVER_QMC5883P =20,
498
#endif
499
#if AP_COMPASS_BMM350_ENABLED
500
DRIVER_BMM350 =21,
501
#endif
502
#if AP_COMPASS_IIS2MDC_ENABLED
503
DRIVER_IIS2MDC =22,
504
#endif
505
};
506
507
bool _driver_enabled(enum DriverType driver_type);
508
509
// backend objects
510
AP_Compass_Backend *_backends[COMPASS_MAX_BACKEND];
511
uint8_t _backend_count;
512
513
// whether to enable the compass drivers at all
514
AP_Int8 _enabled;
515
516
// number of registered compasses.
517
uint8_t _compass_count;
518
519
// number of unregistered compasses.
520
uint8_t _unreg_compass_count;
521
522
// settable parameters
523
AP_Int8 _learn;
524
525
// board orientation from AHRS
526
enum Rotation _board_orientation = ROTATION_NONE;
527
528
// declination in radians
529
AP_Float _declination;
530
531
// enable automatic declination code
532
AP_Int8 _auto_declination;
533
534
// stores which bit is used to indicate we should log compass readings
535
uint32_t _log_bit = -1;
536
537
// motor compensation type
538
// 0 = disabled, 1 = enabled for throttle, 2 = enabled for current
539
AP_Int8 _motor_comp_type;
540
541
// automatic compass orientation on calibration
542
AP_Int8 _rotate_auto;
543
544
// throttle expressed as a percentage from 0 ~ 1.0, used for motor compensation
545
float _thr;
546
547
struct mag_state {
548
AP_Int8 external;
549
bool healthy;
550
bool registered;
551
Compass::Priority priority;
552
AP_Int8 orientation;
553
AP_Vector3f offset;
554
#if AP_COMPASS_DIAGONALS_ENABLED
555
AP_Vector3f diagonals;
556
AP_Vector3f offdiagonals;
557
#endif
558
AP_Float scale_factor;
559
560
// device id detected at init.
561
// saved to eeprom when offsets are saved allowing ram &
562
// eeprom values to be compared as consistency check
563
AP_Int32 dev_id;
564
// Initialised when compass is detected
565
int32_t detected_dev_id;
566
// Initialised at boot from saved devid
567
int32_t expected_dev_id;
568
569
// factors multiplied by throttle and added to compass outputs
570
AP_Vector3f motor_compensation;
571
572
// latest compensation added to compass
573
Vector3f motor_offset;
574
575
// corrected magnetic field strength
576
Vector3f field;
577
578
// when we last got data
579
uint32_t last_update_ms;
580
uint32_t last_update_usec;
581
582
// board specific orientation
583
enum Rotation rotation;
584
585
// accumulated samples, protected by _sem, used by AP_Compass_Backend
586
Vector3f accum;
587
uint32_t accum_count;
588
// We only copy persistent params
589
void copy_from(const mag_state& state);
590
};
591
592
//Create an Array of mag_state to be accessible by StateIndex only
593
RestrictIDTypeArray<mag_state, COMPASS_MAX_INSTANCES+1, StateIndex> _state;
594
595
//Convert Priority to StateIndex
596
StateIndex _get_state_id(Priority priority) const;
597
//Get State Struct by Priority
598
const struct mag_state& _get_state(Priority priority) const { return _state[_get_state_id(priority)]; }
599
//Convert StateIndex to Priority
600
Priority _get_priority(StateIndex state_id) { return _state[state_id].priority; }
601
//Method to detect compass beyond initialisation stage
602
void _detect_runtime(void);
603
// This method reorganises devid list to match
604
// priority list, only call before detection at boot
605
#if COMPASS_MAX_INSTANCES > 1
606
void _reorder_compass_params();
607
#endif
608
// Update Priority List for Mags, by default, we just
609
// load them as they come up the first time
610
Priority _update_priority_list(int32_t dev_id);
611
612
// method to check if the mag with the devid
613
// is a replacement mag
614
bool is_replacement_mag(uint32_t dev_id);
615
616
//remove the devid from unreg compass list
617
void remove_unreg_dev_id(uint32_t devid);
618
619
void _reset_compass_id();
620
//Create Arrays to be accessible by Priority only
621
RestrictIDTypeArray<AP_Int8, COMPASS_MAX_INSTANCES, Priority> _use_for_yaw;
622
#if COMPASS_MAX_INSTANCES > 1
623
RestrictIDTypeArray<AP_Int32, COMPASS_MAX_INSTANCES, Priority> _priority_did_stored_list;
624
RestrictIDTypeArray<int32_t, COMPASS_MAX_INSTANCES, Priority> _priority_did_list;
625
#endif
626
627
AP_Int16 _offset_max;
628
629
// bitmask of options
630
enum class Option : uint16_t {
631
CAL_REQUIRE_GPS = (1U<<0),
632
ALLOW_DRONECAN_AUTO_REPLACEMENT = (1U<<1),
633
};
634
bool option_set(Option opt) const { return (_options.get() & uint16_t(opt)) != 0; }
635
AP_Int16 _options;
636
637
#if COMPASS_CAL_ENABLED
638
RestrictIDTypeArray<CompassCalibrator*, COMPASS_MAX_INSTANCES, Priority> _calibrator;
639
#endif
640
641
#if COMPASS_MOT_ENABLED
642
// per-motor compass compensation
643
Compass_PerMotor _per_motor{*this};
644
#endif
645
646
AP_Float _calibration_threshold;
647
648
// mask of driver types to not load. Bit positions match DEVTYPE_ in backend
649
AP_Int32 _driver_type_mask;
650
651
#if COMPASS_MAX_UNREG_DEV
652
// Put extra dev ids detected
653
AP_Int32 extra_dev_id[COMPASS_MAX_UNREG_DEV];
654
uint32_t _previously_unreg_mag[COMPASS_MAX_UNREG_DEV];
655
#endif
656
657
AP_Int8 _filter_range;
658
659
CompassLearn *learn;
660
bool learn_allocated;
661
662
/// Sets the initial location used to get declination
663
///
664
/// @param latitude GPS Latitude.
665
/// @param longitude GPS Longitude.
666
///
667
void try_set_initial_location();
668
bool _initial_location_set;
669
670
bool _cal_thread_started;
671
672
#if AP_COMPASS_MSP_ENABLED
673
uint8_t msp_instance_mask;
674
#endif
675
bool init_done;
676
677
bool suppress_devid_save;
678
679
uint8_t _first_usable; // first compass usable based on COMPASSx_USE param
680
};
681
682
namespace AP {
683
Compass &compass();
684
};
685
686