Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AP_AHRS/AP_AHRS_External.cpp
Views: 1798
#include "AP_AHRS_External.h"12#if AP_AHRS_EXTERNAL_ENABLED34#include <AP_ExternalAHRS/AP_ExternalAHRS.h>5#include <AP_AHRS/AP_AHRS.h>67// true if the AHRS has completed initialisation8bool AP_AHRS_External::initialised(void) const9{10return AP::externalAHRS().initialised();11}1213void AP_AHRS_External::update()14{15AP::externalAHRS().update();16}1718bool AP_AHRS_External::healthy() const {19return AP::externalAHRS().healthy();20}2122void AP_AHRS_External::get_results(AP_AHRS_Backend::Estimates &results)23{24Quaternion quat;25auto &extahrs = AP::externalAHRS();26const AP_InertialSensor &_ins = AP::ins();27if (!extahrs.get_quaternion(quat)) {28return;29}30quat.rotation_matrix(results.dcm_matrix);31results.dcm_matrix = results.dcm_matrix * AP::ahrs().get_rotation_vehicle_body_to_autopilot_body();32results.dcm_matrix.to_euler(&results.roll_rad, &results.pitch_rad, &results.yaw_rad);3334results.gyro_drift.zero();35if (!extahrs.get_gyro(results.gyro_estimate)) {36results.gyro_estimate = _ins.get_gyro();37}3839Vector3f accel;40if (!extahrs.get_accel(accel)) {41accel = _ins.get_accel();42}4344const Vector3f accel_ef = results.dcm_matrix * AP::ahrs().get_rotation_autopilot_body_to_vehicle_body() * accel;45results.accel_ef = accel_ef;4647results.location_valid = AP::externalAHRS().get_location(results.location);48}4950bool AP_AHRS_External::get_quaternion(Quaternion &quat) const51{52return AP::externalAHRS().get_quaternion(quat);53}5455Vector2f AP_AHRS_External::groundspeed_vector()56{57return AP::externalAHRS().get_groundspeed_vector();58}596061bool AP_AHRS_External::get_relative_position_NED_origin(Vector3f &vec) const62{63auto &extahrs = AP::externalAHRS();64Location loc, orgn;65if (extahrs.get_origin(orgn) &&66extahrs.get_location(loc)) {67const Vector2f diff2d = orgn.get_distance_NE(loc);68vec = Vector3f(diff2d.x, diff2d.y,69-(loc.alt - orgn.alt)*0.01);70return true;71}72return false;73}7475bool AP_AHRS_External::get_relative_position_NE_origin(Vector2f &posNE) const76{77auto &extahrs = AP::externalAHRS();7879Location loc, orgn;80if (!extahrs.get_location(loc) ||81!extahrs.get_origin(orgn)) {82return false;83}84posNE = orgn.get_distance_NE(loc);85return true;86}8788bool AP_AHRS_External::get_relative_position_D_origin(float &posD) const89{90auto &extahrs = AP::externalAHRS();9192Location orgn, loc;93if (!extahrs.get_origin(orgn) ||94!extahrs.get_location(loc)) {95return false;96}97posD = -(loc.alt - orgn.alt)*0.01;98return true;99}100101bool AP_AHRS_External::get_velocity_NED(Vector3f &vec) const102{103return AP::externalAHRS().get_velocity_NED(vec);104}105106bool AP_AHRS_External::get_vert_pos_rate_D(float &velocity) const107{108return AP::externalAHRS().get_speed_down(velocity);109}110111bool AP_AHRS_External::pre_arm_check(bool requires_position, char *failure_msg, uint8_t failure_msg_len) const112{113return AP::externalAHRS().pre_arm_check(failure_msg, failure_msg_len);114}115116bool AP_AHRS_External::get_filter_status(nav_filter_status &status) const117{118AP::externalAHRS().get_filter_status(status);119return true;120}121122void AP_AHRS_External::send_ekf_status_report(GCS_MAVLINK &link) const123{124AP::externalAHRS().send_status_report(link);125}126127bool AP_AHRS_External::get_origin(Location &ret) const128{129return AP::externalAHRS().get_origin(ret);130}131132void AP_AHRS_External::get_control_limits(float &ekfGndSpdLimit, float &ekfNavVelGainScaler) const133{134// lower gains in VTOL controllers when flying on DCM135ekfGndSpdLimit = 50.0;136ekfNavVelGainScaler = 0.5;137}138139#endif140141142