2020-11-05 19:22:38 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "AP_DAL_InertialSensor.h"
|
|
|
|
#include "AP_DAL_Baro.h"
|
|
|
|
#include "AP_DAL_GPS.h"
|
|
|
|
#include "AP_DAL_RangeFinder.h"
|
|
|
|
#include "AP_DAL_Compass.h"
|
|
|
|
#include "AP_DAL_Airspeed.h"
|
|
|
|
#include "AP_DAL_Beacon.h"
|
|
|
|
#include "AP_DAL_VisualOdom.h"
|
|
|
|
|
|
|
|
#include "LogStructure.h"
|
|
|
|
|
2020-11-11 03:39:39 -04:00
|
|
|
#include <stdio.h>
|
2020-11-07 17:29:45 -04:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <cstddef>
|
|
|
|
|
|
|
|
|
2020-11-05 19:22:38 -04:00
|
|
|
#define DAL_CORE(c) AP::dal().logging_core(c)
|
|
|
|
|
2020-11-06 18:30:16 -04:00
|
|
|
class NavEKF2;
|
|
|
|
class NavEKF3;
|
|
|
|
|
2020-11-05 19:22:38 -04:00
|
|
|
class AP_DAL {
|
|
|
|
public:
|
|
|
|
|
2020-11-07 17:29:45 -04:00
|
|
|
enum class FrameType : uint8_t {
|
|
|
|
InitialiseFilterEKF2 = 1U<<0,
|
|
|
|
UpdateFilterEKF2 = 1U<<1,
|
2020-11-05 19:22:38 -04:00
|
|
|
InitialiseFilterEKF3 = 1<<2,
|
|
|
|
UpdateFilterEKF3 = 1<<3,
|
|
|
|
LogWriteEKF2 = 1<<4,
|
|
|
|
LogWriteEKF3 = 1<<5,
|
|
|
|
};
|
|
|
|
|
2020-11-15 23:33:33 -04:00
|
|
|
enum class Event : uint8_t {
|
2020-11-05 19:22:38 -04:00
|
|
|
resetGyroBias = 0,
|
|
|
|
resetHeightDatum = 1,
|
2020-11-20 15:38:49 -04:00
|
|
|
//setInhibitGPS = 2, // removed
|
2021-05-28 00:51:54 -03:00
|
|
|
//setTakeoffExpected = 3, // removed
|
|
|
|
//unsetTakeoffExpected = 4, // removed
|
|
|
|
//setTouchdownExpected = 5, // removed
|
|
|
|
//unsetTouchdownExpected = 6, // removed
|
2020-11-20 15:38:49 -04:00
|
|
|
//setInhibitGpsVertVelUse = 7, // removed
|
|
|
|
//unsetInhibitGpsVertVelUse = 8, // removed
|
2020-11-05 19:22:38 -04:00
|
|
|
setTerrainHgtStable = 9,
|
|
|
|
unsetTerrainHgtStable = 10,
|
|
|
|
requestYawReset = 11,
|
|
|
|
checkLaneSwitch = 12,
|
2022-05-27 08:28:22 -03:00
|
|
|
setSourceSet0 = 13,
|
|
|
|
setSourceSet1 = 14,
|
|
|
|
setSourceSet2 = 15,
|
2020-11-05 19:22:38 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// must remain the same as AP_AHRS_VehicleClass numbers-wise
|
|
|
|
enum class VehicleClass : uint8_t {
|
|
|
|
UNKNOWN,
|
|
|
|
GROUND,
|
|
|
|
COPTER,
|
|
|
|
FIXED_WING,
|
|
|
|
SUBMARINE,
|
|
|
|
};
|
|
|
|
|
|
|
|
AP_DAL() {}
|
|
|
|
|
|
|
|
static AP_DAL *get_singleton() {
|
|
|
|
if (!_singleton) {
|
|
|
|
_singleton = new AP_DAL();
|
|
|
|
}
|
|
|
|
return _singleton;
|
|
|
|
}
|
|
|
|
|
|
|
|
void start_frame(FrameType frametype);
|
|
|
|
void end_frame(void);
|
2020-11-07 02:26:53 -04:00
|
|
|
uint64_t micros64() const { return _RFRH.time_us; }
|
|
|
|
uint32_t micros() const { return _micros; }
|
|
|
|
uint32_t millis() const { return _millis; }
|
2020-11-05 19:22:38 -04:00
|
|
|
|
2020-11-15 23:33:33 -04:00
|
|
|
void log_event2(Event event);
|
2020-11-05 19:22:38 -04:00
|
|
|
void log_SetOriginLLH2(const Location &loc);
|
2020-11-14 05:50:50 -04:00
|
|
|
void log_writeDefaultAirSpeed2(const float aspeed, const float uncertainty);
|
2020-11-05 19:22:38 -04:00
|
|
|
|
2020-11-15 23:33:33 -04:00
|
|
|
void log_event3(Event event);
|
2020-11-05 19:22:38 -04:00
|
|
|
void log_SetOriginLLH3(const Location &loc);
|
2020-11-14 05:50:50 -04:00
|
|
|
void log_writeDefaultAirSpeed3(const float aspeed, const float uncertainty);
|
2020-11-05 19:22:38 -04:00
|
|
|
void log_writeEulerYawAngle(float yawAngle, float yawAngleErr, uint32_t timeStamp_ms, uint8_t type);
|
|
|
|
|
|
|
|
enum class StateMask {
|
|
|
|
ARMED = (1U<<0),
|
|
|
|
};
|
|
|
|
|
2020-11-06 17:24:04 -04:00
|
|
|
// EKF ID for timing checks
|
|
|
|
enum class EKFType : uint8_t {
|
|
|
|
EKF2 = 0,
|
|
|
|
EKF3 = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
// check if we are low on CPU for this core
|
|
|
|
bool ekf_low_time_remaining(EKFType etype, uint8_t core);
|
|
|
|
|
2020-11-05 19:22:38 -04:00
|
|
|
// returns armed state for the current frame
|
2020-11-08 00:03:05 -04:00
|
|
|
bool get_armed() const { return _RFRN.armed; }
|
2020-11-05 19:22:38 -04:00
|
|
|
|
|
|
|
// memory available at start of current frame. While this could
|
|
|
|
// potentially change as we go through the frame, the
|
|
|
|
// ramifications of being out of memory are that you don't start
|
|
|
|
// the EKF, so the simplicity of having one value for the entire
|
|
|
|
// frame is worthwhile.
|
2021-01-17 18:16:40 -04:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
|
|
|
uint32_t available_memory() const { return _RFRN.available_memory + 10240; }
|
|
|
|
#else
|
2020-11-07 02:26:53 -04:00
|
|
|
uint32_t available_memory() const { return _RFRN.available_memory; }
|
2021-01-17 18:16:40 -04:00
|
|
|
#endif
|
2020-11-05 19:22:38 -04:00
|
|
|
|
|
|
|
int8_t get_ekf_type(void) const {
|
|
|
|
return _RFRN.ekf_type;
|
|
|
|
}
|
|
|
|
|
2020-11-07 02:26:53 -04:00
|
|
|
int snprintf(char* str, size_t size, const char *format, ...) const;
|
2020-11-05 19:22:38 -04:00
|
|
|
|
|
|
|
// copied in AP_HAL/Util.h
|
|
|
|
enum Memory_Type {
|
|
|
|
MEM_DMA_SAFE,
|
|
|
|
MEM_FAST
|
|
|
|
};
|
2020-11-07 02:26:53 -04:00
|
|
|
void *malloc_type(size_t size, enum Memory_Type mem_type) const;
|
2020-11-05 19:22:38 -04:00
|
|
|
|
|
|
|
AP_DAL_InertialSensor &ins() { return _ins; }
|
|
|
|
AP_DAL_Baro &baro() { return _baro; }
|
|
|
|
AP_DAL_GPS &gps() { return _gps; }
|
2020-11-26 05:57:31 -04:00
|
|
|
|
2020-11-05 19:22:38 -04:00
|
|
|
AP_DAL_RangeFinder *rangefinder() {
|
2020-11-26 05:57:31 -04:00
|
|
|
return _rangefinder;
|
2020-11-05 19:22:38 -04:00
|
|
|
}
|
|
|
|
AP_DAL_Airspeed *airspeed() {
|
2020-11-26 05:57:31 -04:00
|
|
|
return _airspeed;
|
2020-11-05 19:22:38 -04:00
|
|
|
}
|
|
|
|
AP_DAL_Beacon *beacon() {
|
2020-11-26 05:57:31 -04:00
|
|
|
return _beacon;
|
2020-11-05 19:22:38 -04:00
|
|
|
}
|
2020-11-06 06:21:46 -04:00
|
|
|
#if HAL_VISUALODOM_ENABLED
|
2020-11-05 19:22:38 -04:00
|
|
|
AP_DAL_VisualOdom *visualodom() {
|
2020-11-26 05:57:31 -04:00
|
|
|
return _visualodom;
|
2020-11-05 19:22:38 -04:00
|
|
|
}
|
2020-11-06 06:21:46 -04:00
|
|
|
#endif
|
2020-11-05 19:22:38 -04:00
|
|
|
|
|
|
|
AP_DAL_Compass &compass() { return _compass; }
|
|
|
|
|
|
|
|
// random methods that AP_NavEKF3 wants to call on AHRS:
|
|
|
|
bool airspeed_sensor_enabled(void) const {
|
|
|
|
return _RFRN.ahrs_airspeed_sensor_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
// this replaces AP::ahrs()->EAS2TAS(), which should probably go
|
|
|
|
// away in favour of just using the Baro method.
|
|
|
|
// get apparent to true airspeed ratio
|
|
|
|
float get_EAS2TAS(void) const {
|
|
|
|
return _RFRN.EAS2TAS;
|
|
|
|
}
|
|
|
|
|
|
|
|
VehicleClass get_vehicle_class(void) const {
|
|
|
|
return (VehicleClass)_RFRN.vehicle_class;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool get_fly_forward(void) const {
|
|
|
|
return _RFRN.fly_forward;
|
|
|
|
}
|
|
|
|
|
2021-05-28 00:51:54 -03:00
|
|
|
bool get_takeoff_expected(void) const {
|
|
|
|
return _RFRN.takeoff_expected;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool get_touchdown_expected(void) const {
|
|
|
|
return _RFRN.touchdown_expected;
|
|
|
|
}
|
|
|
|
|
|
|
|
// for EKF usage to enable takeoff expected to true
|
|
|
|
void set_takeoff_expected();
|
|
|
|
|
2020-11-08 00:18:47 -04:00
|
|
|
// get ahrs trim
|
2020-11-05 19:22:38 -04:00
|
|
|
const Vector3f &get_trim() const {
|
2020-11-08 00:18:47 -04:00
|
|
|
return _RFRN.ahrs_trim;
|
2020-11-05 19:22:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const Matrix3f &get_rotation_vehicle_body_to_autopilot_body(void) const {
|
|
|
|
return _rotation_vehicle_body_to_autopilot_body;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the home location. This is const to prevent any changes to
|
|
|
|
// home without telling AHRS about the change
|
|
|
|
const struct Location &get_home(void) const {
|
|
|
|
return _home;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t get_time_flying_ms(void) const {
|
|
|
|
return _RFRH.time_flying_ms;
|
|
|
|
}
|
|
|
|
|
2020-11-08 21:28:58 -04:00
|
|
|
bool opticalflow_enabled(void) const {
|
|
|
|
return _RFRN.opticalflow_enabled;
|
|
|
|
}
|
|
|
|
|
2020-11-27 04:21:12 -04:00
|
|
|
bool wheelencoder_enabled(void) const {
|
|
|
|
return _RFRN.wheelencoder_enabled;
|
|
|
|
}
|
|
|
|
|
2020-11-06 18:30:16 -04:00
|
|
|
// log optical flow data
|
|
|
|
void writeOptFlowMeas(const uint8_t rawFlowQuality, const Vector2f &rawFlowRates, const Vector2f &rawGyroRates, const uint32_t msecFlowMeas, const Vector3f &posOffset);
|
2020-11-06 19:57:42 -04:00
|
|
|
|
|
|
|
// log external nav data
|
|
|
|
void writeExtNavData(const Vector3f &pos, const Quaternion &quat, float posErr, float angErr, uint32_t timeStamp_ms, uint16_t delay_ms, uint32_t resetTime_ms);
|
|
|
|
void writeExtNavVelData(const Vector3f &vel, float err, uint32_t timeStamp_ms, uint16_t delay_ms);
|
|
|
|
|
2020-11-06 20:34:06 -04:00
|
|
|
// log wheel odomotry data
|
|
|
|
void writeWheelOdom(float delAng, float delTime, uint32_t timeStamp_ms, const Vector3f &posOffset, float radius);
|
2020-11-07 01:58:32 -04:00
|
|
|
void writeBodyFrameOdom(float quality, const Vector3f &delPos, const Vector3f &delAng, float delTime, uint32_t timeStamp_ms, uint16_t delay_ms, const Vector3f &posOffset);
|
2020-11-06 20:34:06 -04:00
|
|
|
|
2020-11-05 19:22:38 -04:00
|
|
|
// Replay support:
|
|
|
|
void handle_message(const log_RFRH &msg) {
|
|
|
|
_RFRH = msg;
|
|
|
|
_micros = _RFRH.time_us;
|
|
|
|
_millis = _RFRH.time_us / 1000UL;
|
|
|
|
}
|
|
|
|
void handle_message(const log_RFRN &msg) {
|
|
|
|
_RFRN = msg;
|
|
|
|
_home.lat = msg.lat;
|
|
|
|
_home.lng = msg.lng;
|
|
|
|
_home.alt = msg.alt;
|
|
|
|
}
|
2020-11-06 18:30:16 -04:00
|
|
|
void handle_message(const log_RFRF &msg, NavEKF2 &ekf2, NavEKF3 &ekf3);
|
2020-11-05 19:22:38 -04:00
|
|
|
|
|
|
|
void handle_message(const log_RISH &msg) {
|
|
|
|
_ins.handle_message(msg);
|
|
|
|
}
|
|
|
|
void handle_message(const log_RISI &msg) {
|
|
|
|
_ins.handle_message(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void handle_message(const log_RASH &msg) {
|
2020-11-26 05:57:31 -04:00
|
|
|
if (_airspeed == nullptr) {
|
|
|
|
_airspeed = new AP_DAL_Airspeed;
|
|
|
|
}
|
|
|
|
_airspeed->handle_message(msg);
|
2020-11-05 19:22:38 -04:00
|
|
|
}
|
|
|
|
void handle_message(const log_RASI &msg) {
|
2020-11-26 05:57:31 -04:00
|
|
|
if (_airspeed == nullptr) {
|
|
|
|
_airspeed = new AP_DAL_Airspeed;
|
|
|
|
}
|
|
|
|
_airspeed->handle_message(msg);
|
2020-11-05 19:22:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_message(const log_RBRH &msg) {
|
|
|
|
_baro.handle_message(msg);
|
|
|
|
}
|
|
|
|
void handle_message(const log_RBRI &msg) {
|
|
|
|
_baro.handle_message(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void handle_message(const log_RRNH &msg) {
|
2020-11-26 05:57:31 -04:00
|
|
|
if (_rangefinder == nullptr) {
|
|
|
|
_rangefinder = new AP_DAL_RangeFinder;
|
|
|
|
}
|
|
|
|
_rangefinder->handle_message(msg);
|
2020-11-05 19:22:38 -04:00
|
|
|
}
|
|
|
|
void handle_message(const log_RRNI &msg) {
|
2020-11-26 05:57:31 -04:00
|
|
|
if (_rangefinder == nullptr) {
|
|
|
|
_rangefinder = new AP_DAL_RangeFinder;
|
|
|
|
}
|
|
|
|
_rangefinder->handle_message(msg);
|
2020-11-05 19:22:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_message(const log_RGPH &msg) {
|
|
|
|
_gps.handle_message(msg);
|
|
|
|
}
|
|
|
|
void handle_message(const log_RGPI &msg) {
|
|
|
|
_gps.handle_message(msg);
|
|
|
|
}
|
|
|
|
void handle_message(const log_RGPJ &msg) {
|
|
|
|
_gps.handle_message(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void handle_message(const log_RMGH &msg) {
|
|
|
|
_compass.handle_message(msg);
|
|
|
|
}
|
|
|
|
void handle_message(const log_RMGI &msg) {
|
|
|
|
_compass.handle_message(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void handle_message(const log_RBCH &msg) {
|
2020-11-26 05:57:31 -04:00
|
|
|
if (_beacon == nullptr) {
|
|
|
|
_beacon = new AP_DAL_Beacon;
|
|
|
|
}
|
|
|
|
_beacon->handle_message(msg);
|
2020-11-05 19:22:38 -04:00
|
|
|
}
|
|
|
|
void handle_message(const log_RBCI &msg) {
|
2020-11-26 05:57:31 -04:00
|
|
|
if (_beacon == nullptr) {
|
|
|
|
_beacon = new AP_DAL_Beacon;
|
|
|
|
}
|
|
|
|
_beacon->handle_message(msg);
|
2020-11-05 19:22:38 -04:00
|
|
|
}
|
|
|
|
void handle_message(const log_RVOH &msg) {
|
2020-11-06 06:21:46 -04:00
|
|
|
#if HAL_VISUALODOM_ENABLED
|
2020-11-26 05:57:31 -04:00
|
|
|
if (_visualodom == nullptr) {
|
|
|
|
_visualodom = new AP_DAL_VisualOdom;
|
|
|
|
}
|
|
|
|
_visualodom->handle_message(msg);
|
2020-11-06 06:21:46 -04:00
|
|
|
#endif
|
2020-11-05 19:22:38 -04:00
|
|
|
}
|
2020-11-06 18:30:16 -04:00
|
|
|
void handle_message(const log_ROFH &msg, NavEKF2 &ekf2, NavEKF3 &ekf3);
|
2020-11-06 19:57:42 -04:00
|
|
|
void handle_message(const log_REPH &msg, NavEKF2 &ekf2, NavEKF3 &ekf3);
|
|
|
|
void handle_message(const log_REVH &msg, NavEKF2 &ekf2, NavEKF3 &ekf3);
|
2020-11-06 20:34:06 -04:00
|
|
|
void handle_message(const log_RWOH &msg, NavEKF2 &ekf2, NavEKF3 &ekf3);
|
2020-11-07 01:58:32 -04:00
|
|
|
void handle_message(const log_RBOH &msg, NavEKF2 &ekf2, NavEKF3 &ekf3);
|
2020-11-05 19:22:38 -04:00
|
|
|
|
|
|
|
// map core number for replay
|
|
|
|
uint8_t logging_core(uint8_t c) const;
|
|
|
|
|
|
|
|
// write out a DAL log message. If old_msg is non-null, then
|
|
|
|
// only write if the content has changed
|
|
|
|
static void WriteLogMessage(enum LogMessages msg_type, void *msg, const void *old_msg, uint8_t msg_size);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
static AP_DAL *_singleton;
|
|
|
|
|
2020-11-06 19:57:42 -04:00
|
|
|
// framing structures
|
2020-11-05 19:22:38 -04:00
|
|
|
struct log_RFRH _RFRH;
|
|
|
|
struct log_RFRF _RFRF;
|
|
|
|
struct log_RFRN _RFRN;
|
2020-11-06 19:57:42 -04:00
|
|
|
|
|
|
|
// push-based sensor structures
|
2020-11-06 18:30:16 -04:00
|
|
|
struct log_ROFH _ROFH;
|
2020-11-06 19:57:42 -04:00
|
|
|
struct log_REPH _REPH;
|
|
|
|
struct log_REVH _REVH;
|
2020-11-06 20:34:06 -04:00
|
|
|
struct log_RWOH _RWOH;
|
2020-11-07 01:58:32 -04:00
|
|
|
struct log_RBOH _RBOH;
|
2020-11-05 19:22:38 -04:00
|
|
|
|
|
|
|
// cached variables for speed:
|
|
|
|
uint32_t _micros;
|
|
|
|
uint32_t _millis;
|
|
|
|
|
|
|
|
Matrix3f _rotation_vehicle_body_to_autopilot_body;
|
|
|
|
Location _home;
|
|
|
|
uint32_t _last_imu_time_us;
|
|
|
|
|
|
|
|
AP_DAL_InertialSensor _ins;
|
|
|
|
AP_DAL_Baro _baro;
|
|
|
|
AP_DAL_GPS _gps;
|
2020-11-26 05:57:31 -04:00
|
|
|
AP_DAL_RangeFinder *_rangefinder;
|
2020-11-05 19:22:38 -04:00
|
|
|
AP_DAL_Compass _compass;
|
2020-11-26 05:57:31 -04:00
|
|
|
AP_DAL_Airspeed *_airspeed;
|
|
|
|
AP_DAL_Beacon *_beacon;
|
2020-11-06 06:21:46 -04:00
|
|
|
#if HAL_VISUALODOM_ENABLED
|
2020-11-26 05:57:31 -04:00
|
|
|
AP_DAL_VisualOdom *_visualodom;
|
2020-11-06 06:21:46 -04:00
|
|
|
#endif
|
2020-11-05 19:22:38 -04:00
|
|
|
|
|
|
|
static bool logging_started;
|
|
|
|
static bool force_write;
|
2020-11-06 18:30:16 -04:00
|
|
|
|
|
|
|
bool ekf2_init_done;
|
|
|
|
bool ekf3_init_done;
|
2020-11-26 05:57:31 -04:00
|
|
|
|
|
|
|
void init_sensors(void);
|
|
|
|
bool init_done;
|
2020-11-05 19:22:38 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#define WRITE_REPLAY_BLOCK(sname,v) AP_DAL::WriteLogMessage(LOG_## sname ##_MSG, &v, nullptr, offsetof(log_ ##sname, _end))
|
2020-11-07 17:29:45 -04:00
|
|
|
#define WRITE_REPLAY_BLOCK_IFCHANGED(sname,v,old) do { static_assert(sizeof(v) == sizeof(old), "types must match"); \
|
2020-11-06 16:46:15 -04:00
|
|
|
AP_DAL::WriteLogMessage(LOG_## sname ##_MSG, &v, &old, offsetof(log_ ##sname, _end)); } \
|
|
|
|
while (0)
|
2020-11-05 19:22:38 -04:00
|
|
|
|
|
|
|
namespace AP {
|
|
|
|
AP_DAL &dal();
|
|
|
|
};
|
|
|
|
|
2020-11-06 21:35:04 -04:00
|
|
|
// replay printf for debugging
|
|
|
|
void rprintf(const char *format, ...);
|
2020-11-05 19:22:38 -04:00
|
|
|
|