Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_ExternalAHRS/AP_ExternalAHRS.h
9701 views
1
/*
2
This program is free software: you can redistribute it and/or modify
3
it under the terms of the GNU General Public License as published by
4
the Free Software Foundation, either version 3 of the License, or
5
(at your option) any later version.
6
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
11
12
You should have received a copy of the GNU General Public License
13
along with this program. If not, see <http://www.gnu.org/licenses/>.
14
*/
15
/*
16
support for serial connected AHRS systems
17
*/
18
19
#pragma once
20
21
#include "AP_ExternalAHRS_config.h"
22
23
#if AP_EXTERNAL_AHRS_ENABLED
24
25
#include <AP_HAL/AP_HAL.h>
26
#include <AP_Param/AP_Param.h>
27
#include <AP_Common/Location.h>
28
#include <AP_NavEKF/AP_Nav_Common.h>
29
#include <AP_GPS/AP_GPS_FixType.h>
30
31
class AP_ExternalAHRS_backend;
32
33
class AP_ExternalAHRS {
34
35
public:
36
friend class AP_ExternalAHRS_backend;
37
friend class AP_ExternalAHRS_SBG;
38
friend class AP_ExternalAHRS_VectorNav;
39
40
AP_ExternalAHRS();
41
42
void init(void);
43
44
static const struct AP_Param::GroupInfo var_info[];
45
46
enum class DevType : uint8_t {
47
None = 0,
48
#if AP_EXTERNAL_AHRS_VECTORNAV_ENABLED
49
VecNav = 1,
50
#endif
51
#if AP_EXTERNAL_AHRS_MICROSTRAIN5_ENABLED
52
MicroStrain5 = 2,
53
#endif
54
#if AP_EXTERNAL_AHRS_INERTIALLABS_ENABLED
55
InertialLabs = 5,
56
#endif
57
// 3 reserved for AdNav
58
// 4 reserved for CINS
59
// 6 reserved for Trimble
60
#if AP_EXTERNAL_AHRS_MICROSTRAIN7_ENABLED
61
MicroStrain7 = 7,
62
#endif
63
#if AP_EXTERNAL_AHRS_SBG_ENABLED
64
SBG = 8,
65
#endif
66
// 9 reserved for EulerNav
67
// 10 reserved for Aeron
68
};
69
70
static AP_ExternalAHRS *get_singleton(void) {
71
return _singleton;
72
}
73
74
// expected IMU rate in Hz
75
float get_IMU_rate(void) const {
76
return rate.get();
77
}
78
79
// Get model/type name
80
const char* get_name() const;
81
82
enum class AvailableSensor {
83
GPS = (1U<<0),
84
IMU = (1U<<1),
85
BARO = (1U<<2),
86
COMPASS = (1U<<3),
87
};
88
89
// get serial port number, -1 for not enabled
90
int8_t get_port(AvailableSensor sensor) const;
91
92
struct state_t {
93
HAL_Semaphore sem;
94
95
Vector3f accel;
96
Vector3f gyro;
97
Quaternion quat; // NED
98
Location location;
99
Vector3f velocity;
100
Location origin;
101
102
bool have_quaternion;
103
bool have_origin;
104
bool have_location;
105
bool have_velocity;
106
107
uint32_t last_location_update_us;
108
} state;
109
110
// accessors for AP_AHRS
111
bool enabled() const;
112
bool healthy(void) const;
113
bool initialised(void) const;
114
bool get_quaternion(Quaternion &quat);
115
bool get_origin(Location &loc);
116
bool set_origin(const Location &loc);
117
bool get_location(Location &loc);
118
Vector2f get_groundspeed_vector();
119
bool get_velocity_NED(Vector3f &vel);
120
bool get_speed_down(float &speedD);
121
bool pre_arm_check(char *failure_msg, uint8_t failure_msg_len) const;
122
void get_filter_status(nav_filter_status &status) const;
123
bool get_gyro(Vector3f &gyro);
124
bool get_accel(Vector3f &accel);
125
void send_status_report(class GCS_MAVLINK &link) const;
126
bool get_variances(float &velVar, float &posVar, float &hgtVar, Vector3f &magVar, float &tasVar) const;
127
128
// update backend
129
void update();
130
131
/*
132
structures passed to other subsystems
133
*/
134
typedef struct {
135
uint8_t instance;
136
float pressure_pa;
137
float temperature;
138
} baro_data_message_t;
139
140
typedef struct {
141
Vector3f field;
142
} mag_data_message_t;
143
144
typedef struct {
145
uint16_t gps_week;
146
uint32_t ms_tow;
147
AP_GPS_FixType fix_type;
148
uint8_t satellites_in_view;
149
float horizontal_pos_accuracy;
150
float vertical_pos_accuracy;
151
float horizontal_vel_accuracy;
152
float hdop;
153
float vdop;
154
int32_t longitude;
155
int32_t latitude;
156
int32_t msl_altitude; // cm
157
float ned_vel_north;
158
float ned_vel_east;
159
float ned_vel_down;
160
} gps_data_message_t;
161
162
typedef struct {
163
Vector3f accel;
164
Vector3f gyro;
165
float temperature;
166
} ins_data_message_t;
167
168
typedef struct {
169
float differential_pressure; // Pa
170
float temperature; // degC
171
} airspeed_data_message_t;
172
173
// set GNSS disable for auxillary function GPS_DISABLE
174
void set_gnss_disable(bool disable) {
175
gnss_is_disabled = disable;
176
}
177
178
protected:
179
180
enum class OPTIONS {
181
VN_UNCOMP_IMU = 1U << 0,
182
SBG_EKF_AS_GNSS = 1U << 1,
183
};
184
bool option_is_set(OPTIONS option) const { return (options.get() & int32_t(option)) != 0; }
185
186
private:
187
AP_ExternalAHRS_backend *backend;
188
189
AP_Enum<DevType> devtype;
190
AP_Int16 rate;
191
AP_Int16 log_rate;
192
AP_Int16 options;
193
AP_Int16 sensors;
194
195
static AP_ExternalAHRS *_singleton;
196
197
// check if a sensor type is enabled
198
bool has_sensor(AvailableSensor sensor) const {
199
return (uint16_t(sensors.get()) & uint16_t(sensor)) != 0;
200
}
201
202
// set default of EAHRS_SENSORS
203
void set_default_sensors(uint16_t _sensors) {
204
sensors.set_default(_sensors);
205
}
206
207
uint32_t last_log_ms;
208
209
// true when user has disabled the GNSS
210
bool gnss_is_disabled;
211
};
212
213
namespace AP {
214
AP_ExternalAHRS &externalAHRS();
215
};
216
217
#endif // AP_EXTERNAL_AHRS_ENABLED
218
219
220