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_DAL/AP_DAL_InertialSensor.cpp
Views: 1798
#include "AP_DAL_InertialSensor.h"12#include <AP_Logger/AP_Logger.h>3#include "AP_DAL.h"45AP_DAL_InertialSensor::AP_DAL_InertialSensor()6{7for (uint8_t i=0; i<ARRAY_SIZE(_RISI); i++) {8_RISI[i].instance = i;9}1011}1213void AP_DAL_InertialSensor::start_frame()14{15const auto &ins = AP::ins();1617const log_RISH old_RISH = _RISH;1819_RISH.loop_rate_hz = ins.get_loop_rate_hz();20_RISH.first_usable_gyro = ins.get_first_usable_gyro();21_RISH.loop_delta_t = ins.get_loop_delta_t();22_RISH.first_usable_accel = ins.get_first_usable_accel();23_RISH.accel_count = ins.get_accel_count();24_RISH.gyro_count = ins.get_gyro_count();25WRITE_REPLAY_BLOCK_IFCHANGED(RISH, _RISH, old_RISH);2627for (uint8_t i=0; i<ARRAY_SIZE(_RISI); i++) {28log_RISI &RISI = _RISI[i];29const log_RISI old_RISI = RISI;3031// accel data32RISI.use_accel = ins.use_accel(i);33if (RISI.use_accel) {34RISI.get_delta_velocity_ret = ins.get_delta_velocity(i, RISI.delta_velocity, RISI.delta_velocity_dt);35}3637// gryo data38RISI.use_gyro = ins.use_gyro(i);39if (RISI.use_gyro) {40RISI.get_delta_angle_ret = ins.get_delta_angle(i, RISI.delta_angle, RISI.delta_angle_dt);41}4243update_filtered(i);4445WRITE_REPLAY_BLOCK_IFCHANGED(RISI, RISI, old_RISI);4647// update sensor position48pos[i] = ins.get_imu_pos_offset(i);49}50}5152// update filtered gyro and accel53void AP_DAL_InertialSensor::update_filtered(uint8_t i)54{55if (!is_positive(alpha)) {56// we use a constant 10Hz for EKF filtered accel/gyro, making the EKF57// independent of the INS filter settings58const float cutoff_hz = 10.0;59alpha = calc_lowpass_alpha_dt(get_loop_delta_t(), cutoff_hz);60}61if (is_positive(_RISI[i].delta_angle_dt)) {62gyro_filtered[i] += ((_RISI[i].delta_angle/_RISI[i].delta_angle_dt) - gyro_filtered[i]) * alpha;63}64if (is_positive(_RISI[i].delta_velocity_dt)) {65accel_filtered[i] += ((_RISI[i].delta_velocity/_RISI[i].delta_velocity_dt) - accel_filtered[i]) * alpha;66}67}686970