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_DroneCAN.h
Views: 1798
1
#pragma once
2
3
#include "AP_Compass.h"
4
5
#if AP_COMPASS_DRONECAN_ENABLED
6
7
#include "AP_Compass_Backend.h"
8
9
#include <AP_DroneCAN/AP_DroneCAN.h>
10
11
class AP_Compass_DroneCAN : public AP_Compass_Backend {
12
public:
13
AP_Compass_DroneCAN(AP_DroneCAN* ap_dronecan, uint32_t devid);
14
15
void read(void) override;
16
17
static bool subscribe_msgs(AP_DroneCAN* ap_dronecan);
18
static AP_Compass_Backend* probe(uint8_t index);
19
static uint32_t get_detected_devid(uint8_t index) { return _detected_modules[index].devid; }
20
static void handle_magnetic_field(AP_DroneCAN *ap_dronecan, const CanardRxTransfer& transfer, const uavcan_equipment_ahrs_MagneticFieldStrength& msg);
21
static void handle_magnetic_field_2(AP_DroneCAN *ap_dronecan, const CanardRxTransfer& transfer, const uavcan_equipment_ahrs_MagneticFieldStrength2 &msg);
22
#if AP_COMPASS_DRONECAN_HIRES_ENABLED
23
static void handle_magnetic_field_hires(AP_DroneCAN *ap_dronecan, const CanardRxTransfer& transfer, const dronecan_sensors_magnetometer_MagneticFieldStrengthHiRes &msg);
24
#endif
25
26
private:
27
bool init();
28
29
// callback for DroneCAN messages
30
void handle_mag_msg(const Vector3f &mag);
31
32
static AP_Compass_DroneCAN* get_dronecan_backend(AP_DroneCAN* ap_dronecan, uint8_t node_id, uint8_t sensor_id);
33
34
uint8_t _instance;
35
36
uint32_t _devid;
37
38
// Module Detection Registry
39
static struct DetectedModules {
40
AP_DroneCAN* ap_dronecan;
41
uint8_t node_id;
42
uint8_t sensor_id;
43
AP_Compass_DroneCAN *driver;
44
uint32_t devid;
45
} _detected_modules[COMPASS_MAX_BACKEND];
46
47
static HAL_Semaphore _sem_registry;
48
};
49
50
#endif // AP_COMPASS_DRONECAN_ENABLED
51
52