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_Logging.cpp
Views: 1798
#include <AP_Logger/AP_Logger_config.h>12#if HAL_LOGGING_ENABLED34#include "AP_AHRS.h"5#include <AP_Logger/AP_Logger.h>67#include <AC_AttitudeControl/AC_AttitudeControl.h>8#include <AC_AttitudeControl/AC_PosControl.h>91011// Write an AHRS2 packet12void AP_AHRS::Write_AHRS2() const13{14Vector3f euler;15Location loc;16Quaternion quat;17if (!get_secondary_attitude(euler) || !get_secondary_position(loc) || !get_secondary_quaternion(quat)) {18return;19}20const struct log_AHRS pkt{21LOG_PACKET_HEADER_INIT(LOG_AHR2_MSG),22time_us : AP_HAL::micros64(),23roll : (int16_t)(degrees(euler.x)*100),24pitch : (int16_t)(degrees(euler.y)*100),25yaw : (uint16_t)(wrap_360_cd(degrees(euler.z)*100)),26alt : loc.alt*1.0e-2f,27lat : loc.lat,28lng : loc.lng,29q1 : quat.q1,30q2 : quat.q2,31q3 : quat.q3,32q4 : quat.q4,33};34AP::logger().WriteBlock(&pkt, sizeof(pkt));35}3637// Write AOA and SSA38void AP_AHRS::Write_AOA_SSA(void) const39{40const struct log_AOA_SSA aoa_ssa{41LOG_PACKET_HEADER_INIT(LOG_AOA_SSA_MSG),42time_us : AP_HAL::micros64(),43AOA : getAOA(),44SSA : getSSA()45};4647AP::logger().WriteBlock(&aoa_ssa, sizeof(aoa_ssa));48}4950// Write an attitude packet, targets in degrees51void AP_AHRS::Write_Attitude(const Vector3f &targets) const52{53const struct log_Attitude pkt{54LOG_PACKET_HEADER_INIT(LOG_ATTITUDE_MSG),55time_us : AP_HAL::micros64(),56control_roll : targets.x,57roll : degrees(roll),58control_pitch : targets.y,59pitch : degrees(pitch),60control_yaw : wrap_360(targets.z),61yaw : wrap_360(degrees(yaw)),62active : uint8_t(active_EKF_type()),63};64AP::logger().WriteBlock(&pkt, sizeof(pkt));65}6667void AP_AHRS::Write_Origin(LogOriginType origin_type, const Location &loc) const68{69const struct log_ORGN pkt{70LOG_PACKET_HEADER_INIT(LOG_ORGN_MSG),71time_us : AP_HAL::micros64(),72origin_type : (uint8_t)origin_type,73latitude : loc.lat,74longitude : loc.lng,75altitude : loc.alt76};77AP::logger().WriteBlock(&pkt, sizeof(pkt));78}7980// Write a POS packet81void AP_AHRS::Write_POS() const82{83Location loc;84if (!get_location(loc)) {85return;86}87float home, origin;88AP::ahrs().get_relative_position_D_home(home);89const struct log_POS pkt{90LOG_PACKET_HEADER_INIT(LOG_POS_MSG),91time_us : AP_HAL::micros64(),92lat : loc.lat,93lng : loc.lng,94alt : loc.alt*1.0e-2f,95rel_home_alt : -home,96rel_origin_alt : get_relative_position_D_origin(origin) ? -origin : AP::logger().quiet_nanf(),97};98AP::logger().WriteBlock(&pkt, sizeof(pkt));99}100101// Write a packet for video stabilisation102void AP_AHRS::write_video_stabilisation() const103{104Quaternion current_attitude;105get_quat_body_to_ned(current_attitude);106Vector3f accel = get_accel() - get_accel_bias();107const struct log_Video_Stabilisation pkt {108LOG_PACKET_HEADER_INIT(LOG_VIDEO_STABILISATION_MSG),109time_us : AP_HAL::micros64(),110gyro_x : state.gyro_estimate.x,111gyro_y : state.gyro_estimate.y,112gyro_z : state.gyro_estimate.z,113accel_x : accel.x,114accel_y : accel.y,115accel_z : accel.z,116Q1 : current_attitude.q1,117Q2 : current_attitude.q2,118Q3 : current_attitude.q3,119Q4 : current_attitude.q4,120};121AP::logger().WriteBlock(&pkt, sizeof(pkt));122}123124// Write an attitude view packet, targets in degrees125void AP_AHRS_View::Write_AttitudeView(const Vector3f &targets) const126{127const struct log_Attitude pkt{128LOG_PACKET_HEADER_INIT(LOG_ATTITUDE_MSG),129time_us : AP_HAL::micros64(),130control_roll : targets.x,131roll : degrees(roll),132control_pitch : targets.y,133pitch : degrees(pitch),134control_yaw : wrap_360(targets.z),135yaw : wrap_360(degrees(yaw)),136active : uint8_t(AP::ahrs().active_EKF_type()),137};138AP::logger().WriteBlock(&pkt, sizeof(pkt));139}140141#endif // HAL_LOGGING_ENABLED142143144