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_AHRS/AP_AHRS_SIM.h
Views: 1798
1
#pragma once
2
3
/*
4
This program is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
/*
19
* SITL-based AHRS (Attitude Heading Reference System) interface for
20
* ArduPilot
21
*
22
*/
23
24
#include "AP_AHRS_config.h"
25
26
#if AP_AHRS_SIM_ENABLED
27
28
#include "AP_AHRS_Backend.h"
29
30
#include <GCS_MAVLink/GCS.h>
31
#include <SITL/SITL.h>
32
33
#if HAL_NAVEKF3_AVAILABLE
34
#include <AP_NavEKF3/AP_NavEKF3.h>
35
#endif
36
37
class AP_AHRS_SIM : public AP_AHRS_Backend {
38
public:
39
40
#if HAL_NAVEKF3_AVAILABLE
41
AP_AHRS_SIM(NavEKF3 &_EKF3) :
42
AP_AHRS_Backend(),
43
EKF3(_EKF3)
44
{ }
45
~AP_AHRS_SIM() {}
46
#else
47
// a version of the constructor which doesn't take a non-existant
48
// NavEKF3 class instance as a parameter.
49
AP_AHRS_SIM() : AP_AHRS_Backend() { }
50
#endif
51
52
CLASS_NO_COPY(AP_AHRS_SIM);
53
54
// reset the current gyro drift estimate
55
// should be called if gyro offsets are recalculated
56
void reset_gyro_drift() override {};
57
58
// Methods
59
void update() override { }
60
void get_results(Estimates &results) override;
61
void reset() override { return; }
62
63
// get latest altitude estimate above ground level in meters and validity flag
64
bool get_hagl(float &hagl) const override WARN_IF_UNUSED;
65
66
// return a wind estimation vector, in m/s
67
bool wind_estimate(Vector3f &wind) const override;
68
69
// return an airspeed estimate if available. return true
70
// if we have an estimate
71
bool airspeed_EAS(float &airspeed_ret) const override;
72
73
// return an airspeed estimate if available. return true
74
// if we have an estimate from a specific sensor index
75
bool airspeed_EAS(uint8_t airspeed_index, float &airspeed_ret) const override;
76
77
// return a ground vector estimate in meters/second, in North/East order
78
Vector2f groundspeed_vector() override;
79
80
bool use_compass() override { return true; }
81
82
// return the quaternion defining the rotation from NED to XYZ (body) axes
83
bool get_quaternion(Quaternion &quat) const override WARN_IF_UNUSED;
84
85
// is the AHRS subsystem healthy?
86
bool healthy() const override { return true; }
87
88
bool get_velocity_NED(Vector3f &vec) const override;
89
90
// Get a derivative of the vertical position in m/s which is kinematically consistent with the vertical position is required by some control loops.
91
// This is different to the vertical velocity from the EKF which is not always consistent with the vertical position due to the various errors that are being corrected for.
92
bool get_vert_pos_rate_D(float &velocity) const override;
93
94
// returns false if we fail arming checks, in which case the buffer will be populated with a failure message
95
// requires_position should be true if horizontal position configuration should be checked (not used)
96
bool pre_arm_check(bool requires_position, char *failure_msg, uint8_t failure_msg_len) const override { return true; }
97
98
// get_filter_status - returns filter status as a series of flags
99
bool get_filter_status(nav_filter_status &status) const override;
100
101
// relative-origin functions for fallback in AP_InertialNav
102
bool get_origin(Location &ret) const override;
103
bool get_relative_position_NED_origin(Vector3f &vec) const override;
104
bool get_relative_position_NE_origin(Vector2f &posNE) const override;
105
bool get_relative_position_D_origin(float &posD) const override;
106
107
void send_ekf_status_report(class GCS_MAVLINK &link) const override;
108
109
void get_control_limits(float &ekfGndSpdLimit, float &controlScaleXY) const override;
110
bool get_innovations(Vector3f &velInnov, Vector3f &posInnov, Vector3f &magInnov, float &tasInnov, float &yawInnov) const override;
111
bool get_variances(float &velVar, float &posVar, float &hgtVar, Vector3f &magVar, float &tasVar) const override;
112
113
private:
114
115
// dead-reckoning support
116
bool get_location(Location &loc) const;
117
118
#if HAL_NAVEKF3_AVAILABLE
119
// a reference to the EKF3 backend that we can use to send in
120
// body-frame-odometry data into the EKF. Rightfully there should
121
// be something over in the SITL directory doing this.
122
NavEKF3 &EKF3;
123
#endif
124
125
class SITL::SIM *_sitl;
126
uint32_t _last_body_odm_update_ms;
127
};
128
129
#endif // AP_AHRS_SIM_ENABLED
130
131