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_ExternalAHRS/AP_ExternalAHRS.h
Views: 1798
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 HAL_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_VectorNav;
38
39
AP_ExternalAHRS();
40
41
void init(void);
42
43
static const struct AP_Param::GroupInfo var_info[];
44
45
enum class DevType : uint8_t {
46
None = 0,
47
#if AP_EXTERNAL_AHRS_VECTORNAV_ENABLED
48
VecNav = 1,
49
#endif
50
#if AP_EXTERNAL_AHRS_MICROSTRAIN5_ENABLED
51
MicroStrain5 = 2,
52
#endif
53
#if AP_EXTERNAL_AHRS_INERTIALLABS_ENABLED
54
InertialLabs = 5,
55
#endif
56
// 3 reserved for AdNav
57
// 4 reserved for CINS
58
// 6 reserved for Trimble
59
#if AP_EXTERNAL_AHRS_MICROSTRAIN7_ENABLED
60
MicroStrain7 = 7,
61
#endif
62
// 8 reserved for SBG
63
// 9 reserved for EulerNav
64
// 10 reserved for Aeron
65
};
66
67
static AP_ExternalAHRS *get_singleton(void) {
68
return _singleton;
69
}
70
71
// expected IMU rate in Hz
72
float get_IMU_rate(void) const {
73
return rate.get();
74
}
75
76
// Get model/type name
77
const char* get_name() const;
78
79
enum class AvailableSensor {
80
GPS = (1U<<0),
81
IMU = (1U<<1),
82
BARO = (1U<<2),
83
COMPASS = (1U<<3),
84
};
85
86
// get serial port number, -1 for not enabled
87
int8_t get_port(AvailableSensor sensor) const;
88
89
struct state_t {
90
HAL_Semaphore sem;
91
92
Vector3f accel;
93
Vector3f gyro;
94
Quaternion quat; // NED
95
Location location;
96
Vector3f velocity;
97
Location origin;
98
99
bool have_quaternion;
100
bool have_origin;
101
bool have_location;
102
bool have_velocity;
103
104
uint32_t last_location_update_us;
105
} state;
106
107
// accessors for AP_AHRS
108
bool enabled() const;
109
bool healthy(void) const;
110
bool initialised(void) const;
111
bool get_quaternion(Quaternion &quat);
112
bool get_origin(Location &loc);
113
bool set_origin(const Location &loc);
114
bool get_location(Location &loc);
115
Vector2f get_groundspeed_vector();
116
bool get_velocity_NED(Vector3f &vel);
117
bool get_speed_down(float &speedD);
118
bool pre_arm_check(char *failure_msg, uint8_t failure_msg_len) const;
119
void get_filter_status(nav_filter_status &status) const;
120
bool get_gyro(Vector3f &gyro);
121
bool get_accel(Vector3f &accel);
122
void send_status_report(class GCS_MAVLINK &link) const;
123
bool get_variances(float &velVar, float &posVar, float &hgtVar, Vector3f &magVar, float &tasVar) const;
124
125
// update backend
126
void update();
127
128
/*
129
structures passed to other subsystems
130
*/
131
typedef struct {
132
uint8_t instance;
133
float pressure_pa;
134
float temperature;
135
} baro_data_message_t;
136
137
typedef struct {
138
Vector3f field;
139
} mag_data_message_t;
140
141
typedef struct {
142
uint16_t gps_week;
143
uint32_t ms_tow;
144
AP_GPS_FixType fix_type;
145
uint8_t satellites_in_view;
146
float horizontal_pos_accuracy;
147
float vertical_pos_accuracy;
148
float horizontal_vel_accuracy;
149
float hdop;
150
float vdop;
151
int32_t longitude;
152
int32_t latitude;
153
int32_t msl_altitude; // cm
154
float ned_vel_north;
155
float ned_vel_east;
156
float ned_vel_down;
157
} gps_data_message_t;
158
159
typedef struct {
160
Vector3f accel;
161
Vector3f gyro;
162
float temperature;
163
} ins_data_message_t;
164
165
typedef struct {
166
float differential_pressure; // Pa
167
float temperature; // degC
168
} airspeed_data_message_t;
169
170
// set GNSS disable for auxillary function GPS_DISABLE
171
void set_gnss_disable(bool disable) {
172
gnss_is_disabled = disable;
173
}
174
175
protected:
176
177
enum class OPTIONS {
178
VN_UNCOMP_IMU = 1U << 0,
179
};
180
bool option_is_set(OPTIONS option) const { return (options.get() & int32_t(option)) != 0; }
181
182
private:
183
AP_ExternalAHRS_backend *backend;
184
185
AP_Enum<DevType> devtype;
186
AP_Int16 rate;
187
AP_Int16 log_rate;
188
AP_Int16 options;
189
AP_Int16 sensors;
190
191
static AP_ExternalAHRS *_singleton;
192
193
// check if a sensor type is enabled
194
bool has_sensor(AvailableSensor sensor) const {
195
return (uint16_t(sensors.get()) & uint16_t(sensor)) != 0;
196
}
197
198
// set default of EAHRS_SENSORS
199
void set_default_sensors(uint16_t _sensors) {
200
sensors.set_default(_sensors);
201
}
202
203
uint32_t last_log_ms;
204
205
// true when user has disabled the GNSS
206
bool gnss_is_disabled;
207
};
208
209
namespace AP {
210
AP_ExternalAHRS &externalAHRS();
211
};
212
213
#endif // HAL_EXTERNAL_AHRS_ENABLED
214
215
216