2016-02-17 21:25:09 -04:00
|
|
|
#pragma once
|
2015-02-16 00:37:13 -04:00
|
|
|
|
2015-08-28 05:11:52 -03:00
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_Math/AP_Math.h>
|
2016-06-16 14:10:48 -03:00
|
|
|
#include <GCS_MAVLink/GCS_MAVLink.h>
|
|
|
|
#include <stdint.h>
|
2016-07-15 14:30:21 -03:00
|
|
|
#include "PosVelEKF.h"
|
2018-07-11 09:58:38 -03:00
|
|
|
#include <AP_HAL/utility/RingBuffer.h>
|
2018-04-10 12:20:26 -03:00
|
|
|
#include <AP_AHRS/AP_AHRS.h>
|
2015-02-16 00:37:13 -04:00
|
|
|
|
|
|
|
// declare backend classes
|
|
|
|
class AC_PrecLand_Backend;
|
|
|
|
class AC_PrecLand_Companion;
|
|
|
|
class AC_PrecLand_IRLock;
|
2016-11-10 07:41:17 -04:00
|
|
|
class AC_PrecLand_SITL_Gazebo;
|
2016-11-11 01:10:35 -04:00
|
|
|
class AC_PrecLand_SITL;
|
2015-02-16 00:37:13 -04:00
|
|
|
|
|
|
|
class AC_PrecLand
|
|
|
|
{
|
|
|
|
// declare backends as friends
|
|
|
|
friend class AC_PrecLand_Backend;
|
|
|
|
friend class AC_PrecLand_Companion;
|
|
|
|
friend class AC_PrecLand_IRLock;
|
2016-11-10 07:41:17 -04:00
|
|
|
friend class AC_PrecLand_SITL_Gazebo;
|
2016-11-11 01:10:35 -04:00
|
|
|
friend class AC_PrecLand_SITL;
|
2015-02-16 00:37:13 -04:00
|
|
|
|
|
|
|
public:
|
2018-07-15 21:29:20 -03:00
|
|
|
AC_PrecLand();
|
2017-12-12 21:06:10 -04:00
|
|
|
|
|
|
|
/* Do not allow copies */
|
|
|
|
AC_PrecLand(const AC_PrecLand &other) = delete;
|
|
|
|
AC_PrecLand &operator=(const AC_PrecLand&) = delete;
|
|
|
|
|
2015-02-16 00:37:13 -04:00
|
|
|
// precision landing behaviours (held in PRECLAND_ENABLED parameter)
|
|
|
|
enum PrecLandBehaviour {
|
|
|
|
PRECLAND_BEHAVIOUR_DISABLED,
|
|
|
|
PRECLAND_BEHAVIOR_ALWAYSLAND,
|
|
|
|
PRECLAND_BEHAVIOR_CAUTIOUS
|
|
|
|
};
|
|
|
|
|
|
|
|
// types of precision landing (used for PRECLAND_TYPE parameter)
|
|
|
|
enum PrecLandType {
|
|
|
|
PRECLAND_TYPE_NONE = 0,
|
|
|
|
PRECLAND_TYPE_COMPANION,
|
2016-11-10 07:41:17 -04:00
|
|
|
PRECLAND_TYPE_IRLOCK,
|
|
|
|
PRECLAND_TYPE_SITL_GAZEBO,
|
2016-11-11 01:10:35 -04:00
|
|
|
PRECLAND_TYPE_SITL,
|
2015-02-16 00:37:13 -04:00
|
|
|
};
|
|
|
|
|
2016-06-16 14:10:48 -03:00
|
|
|
// perform any required initialisation of landing controllers
|
2018-09-21 04:01:30 -03:00
|
|
|
// update_rate_hz should be the rate at which the update method will be called in hz
|
|
|
|
void init(uint16_t update_rate_hz);
|
2015-02-16 00:37:13 -04:00
|
|
|
|
2016-06-16 14:10:48 -03:00
|
|
|
// returns true if precision landing is healthy
|
2016-07-15 14:30:21 -03:00
|
|
|
bool healthy() const { return _backend_state.healthy; }
|
2015-02-16 00:37:13 -04:00
|
|
|
|
2017-03-16 05:01:16 -03:00
|
|
|
// returns true if precision landing is enabled (used only for logging)
|
|
|
|
bool enabled() const { return _enabled.get(); }
|
|
|
|
|
2016-06-16 14:10:48 -03:00
|
|
|
// returns time of last update
|
2016-07-15 14:30:21 -03:00
|
|
|
uint32_t last_update_ms() const { return _last_update_ms; }
|
2016-06-16 14:10:48 -03:00
|
|
|
|
2018-08-07 22:23:08 -03:00
|
|
|
// returns time of last time target was seen
|
|
|
|
uint32_t last_backend_los_meas_ms() const { return _last_backend_los_meas_ms; }
|
|
|
|
|
|
|
|
// returns estimator type
|
|
|
|
uint8_t estimator_type() const { return _estimator_type; }
|
|
|
|
|
|
|
|
// returns ekf outlier count
|
|
|
|
uint32_t ekf_outlier_count() const { return _outlier_reject_count; }
|
|
|
|
|
2017-03-16 05:01:16 -03:00
|
|
|
// give chance to driver to get updates from sensor, should be called at 400hz
|
2016-07-15 14:30:21 -03:00
|
|
|
void update(float rangefinder_alt_cm, bool rangefinder_alt_valid);
|
2015-02-16 00:37:13 -04:00
|
|
|
|
2017-03-16 05:01:16 -03:00
|
|
|
// returns target position relative to the EKF origin
|
2017-02-27 18:50:04 -04:00
|
|
|
bool get_target_position_cm(Vector2f& ret);
|
2016-06-16 14:10:48 -03:00
|
|
|
|
2018-08-07 22:23:08 -03:00
|
|
|
// returns target relative position as 3D vector
|
|
|
|
void get_target_position_measurement_cm(Vector3f& ret);
|
|
|
|
|
2016-06-16 14:10:48 -03:00
|
|
|
// returns target position relative to vehicle
|
2017-02-27 18:50:04 -04:00
|
|
|
bool get_target_position_relative_cm(Vector2f& ret);
|
2016-06-16 14:10:48 -03:00
|
|
|
|
|
|
|
// returns target velocity relative to vehicle
|
2017-02-27 18:50:04 -04:00
|
|
|
bool get_target_velocity_relative_cms(Vector2f& ret);
|
2016-06-16 14:10:48 -03:00
|
|
|
|
|
|
|
// returns true when the landing target has been detected
|
2017-02-27 18:50:04 -04:00
|
|
|
bool target_acquired();
|
2016-06-16 14:10:48 -03:00
|
|
|
|
|
|
|
// process a LANDING_TARGET mavlink message
|
2015-09-11 08:00:18 -03:00
|
|
|
void handle_msg(mavlink_message_t* msg);
|
|
|
|
|
2015-02-16 00:37:13 -04:00
|
|
|
// parameter var table
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
|
|
|
private:
|
2017-02-27 18:50:04 -04:00
|
|
|
enum estimator_type_t {
|
2017-03-16 05:01:16 -03:00
|
|
|
ESTIMATOR_TYPE_RAW_SENSOR = 0,
|
|
|
|
ESTIMATOR_TYPE_KALMAN_FILTER = 1
|
2017-02-27 18:50:04 -04:00
|
|
|
};
|
|
|
|
|
2016-06-16 14:10:48 -03:00
|
|
|
// returns enabled parameter as an behaviour
|
2015-02-16 00:37:13 -04:00
|
|
|
enum PrecLandBehaviour get_behaviour() const { return (enum PrecLandBehaviour)(_enabled.get()); }
|
|
|
|
|
2017-03-16 05:01:16 -03:00
|
|
|
// run target position estimator
|
2017-02-27 18:50:04 -04:00
|
|
|
void run_estimator(float rangefinder_alt_m, bool rangefinder_alt_valid);
|
2017-03-16 05:01:16 -03:00
|
|
|
|
2019-02-04 14:10:57 -04:00
|
|
|
// If a new measurement was retrieved, sets _target_pos_rel_meas_NED and returns true
|
2017-03-17 19:37:42 -03:00
|
|
|
bool construct_pos_meas_using_rangefinder(float rangefinder_alt_m, bool rangefinder_alt_valid);
|
|
|
|
|
2017-03-16 05:01:16 -03:00
|
|
|
// get vehicle body frame 3D vector from vehicle to target. returns true on success, false on failure
|
2017-02-27 18:50:04 -04:00
|
|
|
bool retrieve_los_meas(Vector3f& target_vec_unit_body);
|
2017-03-16 05:01:16 -03:00
|
|
|
|
|
|
|
// calculate target's position and velocity relative to the vehicle (used as input to position controller)
|
|
|
|
// results are stored in_target_pos_rel_out_NE, _target_vel_rel_out_NE
|
2017-02-27 18:50:04 -04:00
|
|
|
void run_output_prediction();
|
|
|
|
|
2015-02-16 00:37:13 -04:00
|
|
|
// parameters
|
|
|
|
AP_Int8 _enabled; // enabled/disabled and behaviour
|
2017-02-27 18:50:04 -04:00
|
|
|
AP_Int8 _type; // precision landing sensor type
|
2017-04-11 21:19:21 -03:00
|
|
|
AP_Int8 _bus; // which sensor bus
|
2017-02-27 18:50:04 -04:00
|
|
|
AP_Int8 _estimator_type; // precision landing estimator type
|
2018-09-19 00:34:47 -03:00
|
|
|
AP_Float _lag; // sensor lag in seconds
|
2016-07-15 14:30:21 -03:00
|
|
|
AP_Float _yaw_align; // Yaw angle from body x-axis to sensor x-axis.
|
|
|
|
AP_Float _land_ofs_cm_x; // Desired landing position of the camera forward of the target in vehicle body frame
|
|
|
|
AP_Float _land_ofs_cm_y; // Desired landing position of the camera right of the target in vehicle body frame
|
2019-02-04 14:10:57 -04:00
|
|
|
AP_Float _accel_noise; // accelerometer process noise
|
2017-03-17 19:37:42 -03:00
|
|
|
AP_Vector3f _cam_offset; // Position of the camera relative to the CG
|
2015-02-16 00:37:13 -04:00
|
|
|
|
2017-03-16 05:01:16 -03:00
|
|
|
uint32_t _last_update_ms; // system time in millisecond when update was last called
|
|
|
|
bool _target_acquired; // true if target has been seen recently
|
|
|
|
uint32_t _last_backend_los_meas_ms; // system time target was last seen
|
2016-06-16 14:10:48 -03:00
|
|
|
|
2017-03-16 05:01:16 -03:00
|
|
|
PosVelEKF _ekf_x, _ekf_y; // Kalman Filter for x and y axis
|
|
|
|
uint32_t _outlier_reject_count; // mini-EKF's outlier counter (3 consecutive outliers lead to EKF accepting updates)
|
2016-07-15 14:30:21 -03:00
|
|
|
|
2017-03-16 05:01:16 -03:00
|
|
|
Vector3f _target_pos_rel_meas_NED; // target's relative position as 3D vector
|
2017-02-27 18:50:04 -04:00
|
|
|
|
2017-03-17 19:37:42 -03:00
|
|
|
Vector2f _target_pos_rel_est_NE; // target's position relative to the IMU, not compensated for lag
|
|
|
|
Vector2f _target_vel_rel_est_NE; // target's velocity relative to the IMU, not compensated for lag
|
2017-02-27 18:50:04 -04:00
|
|
|
|
2017-03-17 19:37:42 -03:00
|
|
|
Vector2f _target_pos_rel_out_NE; // target's position relative to the camera, fed into position controller
|
|
|
|
Vector2f _target_vel_rel_out_NE; // target's velocity relative to the CG, fed into position controller
|
2017-02-27 18:50:04 -04:00
|
|
|
|
2018-07-11 09:58:38 -03:00
|
|
|
// structure and buffer to hold a history of vehicle velocity
|
2017-02-27 18:50:04 -04:00
|
|
|
struct inertial_data_frame_s {
|
2017-03-16 05:01:16 -03:00
|
|
|
Matrix3f Tbn; // dcm rotation matrix to rotate body frame to north
|
2017-02-27 18:50:04 -04:00
|
|
|
Vector3f correctedVehicleDeltaVelocityNED;
|
|
|
|
Vector3f inertialNavVelocity;
|
|
|
|
bool inertialNavVelocityValid;
|
|
|
|
float dt;
|
2018-07-11 09:58:38 -03:00
|
|
|
uint64_t time_usec;
|
2017-02-27 18:50:04 -04:00
|
|
|
};
|
2018-07-11 09:58:38 -03:00
|
|
|
ObjectArray<inertial_data_frame_s> *_inertial_history;
|
2015-02-16 00:37:13 -04:00
|
|
|
|
|
|
|
// backend state
|
|
|
|
struct precland_state {
|
|
|
|
bool healthy;
|
|
|
|
} _backend_state;
|
|
|
|
AC_PrecLand_Backend *_backend; // pointers to backend precision landing driver
|
|
|
|
};
|