2017-03-01 07:17:45 -04:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2022-07-06 07:04:19 -03:00
|
|
|
#include "AP_VisualOdom_config.h"
|
2020-04-06 00:17:42 -03:00
|
|
|
|
|
|
|
#if HAL_VISUALODOM_ENABLED
|
|
|
|
|
2017-03-01 07:17:45 -04:00
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_Param/AP_Param.h>
|
2022-11-06 21:24:49 -04:00
|
|
|
#include <GCS_MAVLink/GCS_config.h>
|
|
|
|
#if HAL_GCS_ENABLED
|
|
|
|
#include <GCS_MAVLink/GCS_MAVLink.h>
|
|
|
|
#endif
|
2021-09-17 09:15:13 -03:00
|
|
|
#include <AP_Math/AP_Math.h>
|
2017-03-01 07:17:45 -04:00
|
|
|
|
|
|
|
class AP_VisualOdom_Backend;
|
|
|
|
|
|
|
|
#define AP_VISUALODOM_TIMEOUT_MS 300
|
|
|
|
|
|
|
|
class AP_VisualOdom
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
AP_VisualOdom();
|
|
|
|
|
2018-04-06 05:05:14 -03:00
|
|
|
// get singleton instance
|
|
|
|
static AP_VisualOdom *get_singleton() {
|
|
|
|
return _singleton;
|
|
|
|
}
|
|
|
|
|
2017-03-01 07:17:45 -04:00
|
|
|
// external position backend types (used by _TYPE parameter)
|
2021-12-18 02:08:13 -04:00
|
|
|
enum class VisualOdom_Type {
|
|
|
|
None = 0,
|
2023-04-14 21:58:02 -03:00
|
|
|
#if AP_VISUALODOM_MAV_ENABLED
|
2021-12-18 02:08:13 -04:00
|
|
|
MAV = 1,
|
2023-04-14 21:58:02 -03:00
|
|
|
#endif
|
|
|
|
#if AP_VISUALODOM_INTELT265_ENABLED
|
2021-12-18 02:08:13 -04:00
|
|
|
IntelT265 = 2,
|
|
|
|
VOXL = 3,
|
2023-04-14 21:58:02 -03:00
|
|
|
#endif
|
2017-03-01 07:17:45 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// detect and initialise any sensors
|
|
|
|
void init();
|
|
|
|
|
|
|
|
// return true if sensor is enabled
|
|
|
|
bool enabled() const;
|
|
|
|
|
|
|
|
// return true if sensor is basically healthy (we are receiving data)
|
|
|
|
bool healthy() const;
|
|
|
|
|
2020-04-02 09:04:44 -03:00
|
|
|
// get user defined orientation
|
|
|
|
enum Rotation get_orientation() const { return (enum Rotation)_orientation.get(); }
|
|
|
|
|
2020-04-09 21:41:14 -03:00
|
|
|
// get user defined scaling applied to position estimates
|
|
|
|
float get_pos_scale() const { return _pos_scale; }
|
|
|
|
|
2017-03-01 07:17:45 -04:00
|
|
|
// return a 3D vector defining the position offset of the camera in meters relative to the body frame origin
|
|
|
|
const Vector3f &get_pos_offset(void) const { return _pos_offset; }
|
|
|
|
|
2020-04-13 02:04:06 -03:00
|
|
|
// return the sensor delay in milliseconds (see _DELAY_MS parameter)
|
|
|
|
uint16_t get_delay_ms() const { return MAX(0, _delay_ms); }
|
|
|
|
|
2020-05-13 05:30:40 -03:00
|
|
|
// return velocity measurement noise in m/s
|
|
|
|
float get_vel_noise() const { return _vel_noise; }
|
2020-06-03 23:56:44 -03:00
|
|
|
|
|
|
|
// return position measurement noise in m
|
|
|
|
float get_pos_noise() const { return _pos_noise; }
|
|
|
|
|
|
|
|
// return yaw measurement noise in rad
|
|
|
|
float get_yaw_noise() const { return _yaw_noise; }
|
2020-05-13 05:30:40 -03:00
|
|
|
|
2021-09-17 09:15:13 -03:00
|
|
|
#if HAL_GCS_ENABLED
|
2020-03-31 02:41:54 -03:00
|
|
|
// consume vision_position_delta mavlink messages
|
|
|
|
void handle_vision_position_delta_msg(const mavlink_message_t &msg);
|
2021-09-17 09:15:13 -03:00
|
|
|
#endif
|
2017-03-01 07:17:45 -04:00
|
|
|
|
2020-03-26 01:38:51 -03:00
|
|
|
// general purpose methods to consume position estimate data and send to EKF
|
|
|
|
// distances in meters, roll, pitch and yaw are in radians
|
2023-08-07 01:05:25 -03:00
|
|
|
void handle_pose_estimate(uint64_t remote_time_us, uint32_t time_ms, float x, float y, float z, float roll, float pitch, float yaw, float posErr, float angErr, uint8_t reset_counter);
|
|
|
|
void handle_pose_estimate(uint64_t remote_time_us, uint32_t time_ms, float x, float y, float z, const Quaternion &attitude, float posErr, float angErr, uint8_t reset_counter);
|
2020-05-13 05:30:40 -03:00
|
|
|
|
|
|
|
// general purpose methods to consume velocity estimate data and send to EKF
|
|
|
|
// velocity in NED meters per second
|
|
|
|
void handle_vision_speed_estimate(uint64_t remote_time_us, uint32_t time_ms, const Vector3f &vel, uint8_t reset_counter);
|
2020-03-26 01:38:51 -03:00
|
|
|
|
2023-01-20 03:22:04 -04:00
|
|
|
// request sensor's yaw be aligned with vehicle's AHRS/EKF attitude
|
|
|
|
void request_align_yaw_to_ahrs();
|
2020-03-26 01:38:51 -03:00
|
|
|
|
2020-09-03 01:49:36 -03:00
|
|
|
// update position offsets to align to AHRS position
|
|
|
|
// should only be called when this library is not being used as the position source
|
|
|
|
void align_position_to_ahrs(bool align_xy, bool align_z);
|
|
|
|
|
2020-03-26 01:38:51 -03:00
|
|
|
// returns false if we fail arming checks, in which case the buffer will be populated with a failure message
|
|
|
|
bool pre_arm_check(char *failure_msg, uint8_t failure_msg_len) const;
|
|
|
|
|
2017-03-01 07:17:45 -04:00
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
2021-12-18 02:08:13 -04:00
|
|
|
VisualOdom_Type get_type(void) const {
|
|
|
|
return _type;
|
|
|
|
}
|
|
|
|
|
2017-03-01 07:17:45 -04:00
|
|
|
private:
|
|
|
|
|
2018-04-06 05:05:14 -03:00
|
|
|
static AP_VisualOdom *_singleton;
|
|
|
|
|
2017-03-01 07:17:45 -04:00
|
|
|
// parameters
|
2021-12-18 02:08:13 -04:00
|
|
|
AP_Enum<VisualOdom_Type> _type; // sensor type
|
2017-03-01 07:17:45 -04:00
|
|
|
AP_Vector3f _pos_offset; // position offset of the camera in the body frame
|
|
|
|
AP_Int8 _orientation; // camera orientation on vehicle frame
|
2020-04-09 21:41:14 -03:00
|
|
|
AP_Float _pos_scale; // position scale factor applied to sensor values
|
2020-04-13 02:04:06 -03:00
|
|
|
AP_Int16 _delay_ms; // average delay relative to inertial measurements
|
2020-05-13 05:30:40 -03:00
|
|
|
AP_Float _vel_noise; // velocity measurement noise in m/s
|
2020-06-03 23:56:44 -03:00
|
|
|
AP_Float _pos_noise; // position measurement noise in meters
|
|
|
|
AP_Float _yaw_noise; // yaw measurement noise in radians
|
2017-03-01 07:17:45 -04:00
|
|
|
|
|
|
|
// reference to backends
|
|
|
|
AP_VisualOdom_Backend *_driver;
|
|
|
|
};
|
2018-04-06 05:05:14 -03:00
|
|
|
|
|
|
|
namespace AP {
|
|
|
|
AP_VisualOdom *visualodom();
|
|
|
|
};
|
2020-04-06 00:17:42 -03:00
|
|
|
|
|
|
|
#endif // HAL_VISUALODOM_ENABLED
|