mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-03-11 03:29:17 +01:00
AHRS: Tidied up calibration sequence
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1831 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
b2d56ca34c
commit
683aa2b480
@ -1,858 +1,853 @@
|
|||||||
/**
|
/**
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @addtogroup AHRS AHRS
|
* @addtogroup AHRS AHRS
|
||||||
* @brief The AHRS Modules perform
|
* @brief The AHRS Modules perform
|
||||||
*
|
*
|
||||||
* @{
|
* @{
|
||||||
* @addtogroup AHRS_Main
|
* @addtogroup AHRS_Main
|
||||||
* @brief Main function which does the hardware dependent stuff
|
* @brief Main function which does the hardware dependent stuff
|
||||||
* @{
|
* @{
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @file ahrs.c
|
* @file ahrs.c
|
||||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
* @brief INSGPS Test Program
|
* @brief INSGPS Test Program
|
||||||
* @see The GNU Public License (GPL) Version 3
|
* @see The GNU Public License (GPL) Version 3
|
||||||
*
|
*
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
* for more details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License along
|
* You should have received a copy of the GNU General Public License along
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* OpenPilot Includes */
|
/* OpenPilot Includes */
|
||||||
#include "ahrs.h"
|
#include "ahrs.h"
|
||||||
#include "ahrs_adc.h"
|
#include "ahrs_adc.h"
|
||||||
#include "ahrs_timer.h"
|
#include "ahrs_timer.h"
|
||||||
#include "pios_opahrs_proto.h"
|
#include "pios_opahrs_proto.h"
|
||||||
//#include "ahrs_fsm.h" /* lfsm_state */
|
//#include "ahrs_fsm.h" /* lfsm_state */
|
||||||
#include "insgps.h"
|
#include "insgps.h"
|
||||||
#include "CoordinateConversions.h"
|
#include "CoordinateConversions.h"
|
||||||
#include "ahrs_spi_comm.h"
|
#include "ahrs_spi_comm.h"
|
||||||
|
|
||||||
// For debugging the raw sensors
|
// For debugging the raw sensors
|
||||||
//#define DUMP_RAW
|
//#define DUMP_RAW
|
||||||
//#define DUMP_FRIENDLY
|
//#define DUMP_FRIENDLY
|
||||||
//#define DUMP_EKF
|
//#define DUMP_EKF
|
||||||
|
|
||||||
#ifdef DUMP_EKF
|
#ifdef DUMP_EKF
|
||||||
#define NUMX 13 // number of states, X is the state vector
|
#define NUMX 13 // number of states, X is the state vector
|
||||||
#define NUMW 9 // number of plant noise inputs, w is disturbance noise vector
|
#define NUMW 9 // number of plant noise inputs, w is disturbance noise vector
|
||||||
#define NUMV 10 // number of measurements, v is the measurement noise vector
|
#define NUMV 10 // number of measurements, v is the measurement noise vector
|
||||||
#define NUMU 6 // number of deterministic inputs, U is the input vector
|
#define NUMU 6 // number of deterministic inputs, U is the input vector
|
||||||
extern float F[NUMX][NUMX], G[NUMX][NUMW], H[NUMV][NUMX]; // linearized system matrices
|
extern float F[NUMX][NUMX], G[NUMX][NUMW], H[NUMV][NUMX]; // linearized system matrices
|
||||||
extern float P[NUMX][NUMX], X[NUMX]; // covariance matrix and state vector
|
extern float P[NUMX][NUMX], X[NUMX]; // covariance matrix and state vector
|
||||||
extern float Q[NUMW], R[NUMV]; // input noise and measurement noise variances
|
extern float Q[NUMW], R[NUMV]; // input noise and measurement noise variances
|
||||||
extern float K[NUMX][NUMV]; // feedback gain matrix
|
extern float K[NUMX][NUMV]; // feedback gain matrix
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
volatile enum algorithms ahrs_algorithm;
|
volatile enum algorithms ahrs_algorithm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @addtogroup AHRS_Structures Local Structres
|
* @addtogroup AHRS_Structures Local Structres
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//! Contains the data from the mag sensor chip
|
//! Contains the data from the mag sensor chip
|
||||||
struct mag_sensor {
|
struct mag_sensor {
|
||||||
uint8_t id[4];
|
uint8_t id[4];
|
||||||
uint8_t updated;
|
uint8_t updated;
|
||||||
struct {
|
struct {
|
||||||
int16_t axis[3];
|
int16_t axis[3];
|
||||||
} raw;
|
} raw;
|
||||||
struct {
|
struct {
|
||||||
float axis[3];
|
float axis[3];
|
||||||
} scaled;
|
} scaled;
|
||||||
struct {
|
struct {
|
||||||
float bias[3];
|
float bias[3];
|
||||||
float scale[3];
|
float scale[3];
|
||||||
float variance[3];
|
float variance[3];
|
||||||
} calibration;
|
} calibration;
|
||||||
} mag_data;
|
} mag_data;
|
||||||
|
|
||||||
//! Contains the data from the accelerometer
|
//! Contains the data from the accelerometer
|
||||||
struct accel_sensor {
|
struct accel_sensor {
|
||||||
struct {
|
struct {
|
||||||
uint16_t x;
|
uint16_t x;
|
||||||
uint16_t y;
|
uint16_t y;
|
||||||
uint16_t z;
|
uint16_t z;
|
||||||
} raw;
|
} raw;
|
||||||
struct {
|
struct {
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
float z;
|
float z;
|
||||||
} filtered;
|
} filtered;
|
||||||
struct {
|
struct {
|
||||||
float bias[3];
|
float bias[3];
|
||||||
float scale[3];
|
float scale[3];
|
||||||
float variance[3];
|
float variance[3];
|
||||||
} calibration;
|
} calibration;
|
||||||
} accel_data;
|
} accel_data;
|
||||||
|
|
||||||
//! Contains the data from the gyro
|
//! Contains the data from the gyro
|
||||||
struct gyro_sensor {
|
struct gyro_sensor {
|
||||||
struct {
|
struct {
|
||||||
uint16_t x;
|
uint16_t x;
|
||||||
uint16_t y;
|
uint16_t y;
|
||||||
uint16_t z;
|
uint16_t z;
|
||||||
} raw;
|
} raw;
|
||||||
struct {
|
struct {
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
float z;
|
float z;
|
||||||
} filtered;
|
} filtered;
|
||||||
struct {
|
struct {
|
||||||
float bias[3];
|
float bias[3];
|
||||||
float scale[3];
|
float scale[3];
|
||||||
float variance[3];
|
float variance[3];
|
||||||
} calibration;
|
} calibration;
|
||||||
struct {
|
struct {
|
||||||
uint16_t xy;
|
uint16_t xy;
|
||||||
uint16_t z;
|
uint16_t z;
|
||||||
} temp;
|
} temp;
|
||||||
} gyro_data;
|
} gyro_data;
|
||||||
|
|
||||||
//! Conains the current estimate of the attitude
|
//! Conains the current estimate of the attitude
|
||||||
struct attitude_solution {
|
struct attitude_solution {
|
||||||
struct {
|
struct {
|
||||||
float q1;
|
float q1;
|
||||||
float q2;
|
float q2;
|
||||||
float q3;
|
float q3;
|
||||||
float q4;
|
float q4;
|
||||||
} quaternion;
|
} quaternion;
|
||||||
} attitude_data;
|
} attitude_data;
|
||||||
|
|
||||||
//! Contains data from the altitude sensor
|
//! Contains data from the altitude sensor
|
||||||
struct altitude_sensor {
|
struct altitude_sensor {
|
||||||
float altitude;
|
float altitude;
|
||||||
bool updated;
|
bool updated;
|
||||||
} altitude_data;
|
} altitude_data;
|
||||||
|
|
||||||
//! Contains data from the GPS (via the SPI link)
|
//! Contains data from the GPS (via the SPI link)
|
||||||
struct gps_sensor {
|
struct gps_sensor {
|
||||||
float NED[3];
|
float NED[3];
|
||||||
float heading;
|
float heading;
|
||||||
float groundspeed;
|
float groundspeed;
|
||||||
float quality;
|
float quality;
|
||||||
bool updated;
|
bool updated;
|
||||||
} gps_data;
|
} gps_data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Function Prototypes */
|
/* Function Prototypes */
|
||||||
void process_spi_request(void);
|
void process_spi_request(void);
|
||||||
void downsample_data(void);
|
void downsample_data(void);
|
||||||
void calibrate_sensors(void);
|
void calibrate_sensors(void);
|
||||||
void reset_values();
|
void reset_values();
|
||||||
void send_calibration(void);
|
void send_calibration(void);
|
||||||
void altitude_callback(AhrsObjHandle obj);
|
void altitude_callback(AhrsObjHandle obj);
|
||||||
void calibration_callback(AhrsObjHandle obj);
|
void calibration_callback(AhrsObjHandle obj);
|
||||||
void gps_callback(AhrsObjHandle obj);
|
void gps_callback(AhrsObjHandle obj);
|
||||||
void settings_callback(AhrsObjHandle obj);
|
void settings_callback(AhrsObjHandle obj);
|
||||||
|
|
||||||
volatile uint32_t last_counter_idle_start = 0;
|
volatile uint32_t last_counter_idle_start = 0;
|
||||||
volatile uint32_t last_counter_idle_end = 0;
|
volatile uint32_t last_counter_idle_end = 0;
|
||||||
volatile uint32_t idle_counts;
|
volatile uint32_t idle_counts;
|
||||||
volatile uint32_t running_counts;
|
volatile uint32_t running_counts;
|
||||||
uint32_t counter_val;
|
uint32_t counter_val;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @addtogroup AHRS_Global_Data AHRS Global Data
|
* @addtogroup AHRS_Global_Data AHRS Global Data
|
||||||
* @{
|
* @{
|
||||||
* Public data. Used by both EKF and the sender
|
* Public data. Used by both EKF and the sender
|
||||||
*/
|
*/
|
||||||
//! Filter coefficients used in decimation. Limited order so filter can't run between samples
|
//! Filter coefficients used in decimation. Limited order so filter can't run between samples
|
||||||
int16_t fir_coeffs[50];
|
int16_t fir_coeffs[50];
|
||||||
|
|
||||||
//! Indicates the communications are requesting a calibration
|
|
||||||
uint8_t calibration_pending = FALSE;
|
//! The oversampling rate, ekf is 2k / this
|
||||||
|
static uint8_t adc_oversampling = 17;
|
||||||
//! The oversampling rate, ekf is 2k / this
|
|
||||||
static uint8_t adc_oversampling = 17;
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
/**
|
*/
|
||||||
* @}
|
|
||||||
*/
|
/**
|
||||||
|
* @brief AHRS Main function
|
||||||
/**
|
*/
|
||||||
* @brief AHRS Main function
|
int main()
|
||||||
*/
|
{
|
||||||
int main()
|
float gyro[3], accel[3], mag[3];
|
||||||
{
|
float vel[3] = { 0, 0, 0 };
|
||||||
float gyro[3], accel[3], mag[3];
|
gps_data.quality = -1;
|
||||||
float vel[3] = { 0, 0, 0 };
|
|
||||||
gps_data.quality = -1;
|
ahrs_algorithm = INSGPS_Algo;
|
||||||
|
|
||||||
ahrs_algorithm = INSGPS_Algo;
|
/* Brings up System using CMSIS functions, enables the LEDs. */
|
||||||
|
PIOS_SYS_Init();
|
||||||
/* Brings up System using CMSIS functions, enables the LEDs. */
|
|
||||||
PIOS_SYS_Init();
|
/* Delay system */
|
||||||
|
PIOS_DELAY_Init();
|
||||||
/* Delay system */
|
|
||||||
PIOS_DELAY_Init();
|
/* Communication system */
|
||||||
|
PIOS_COM_Init();
|
||||||
/* Communication system */
|
|
||||||
PIOS_COM_Init();
|
/* ADC system */
|
||||||
|
AHRS_ADC_Config(adc_oversampling);
|
||||||
/* ADC system */
|
|
||||||
AHRS_ADC_Config(adc_oversampling);
|
/* Setup the Accelerometer FS (Full-Scale) GPIO */
|
||||||
|
PIOS_GPIO_Enable(0);
|
||||||
/* Setup the Accelerometer FS (Full-Scale) GPIO */
|
SET_ACCEL_2G;
|
||||||
PIOS_GPIO_Enable(0);
|
#if defined(PIOS_INCLUDE_HMC5843) && defined(PIOS_INCLUDE_I2C)
|
||||||
SET_ACCEL_2G;
|
/* Magnetic sensor system */
|
||||||
#if defined(PIOS_INCLUDE_HMC5843) && defined(PIOS_INCLUDE_I2C)
|
PIOS_I2C_Init();
|
||||||
/* Magnetic sensor system */
|
PIOS_HMC5843_Init();
|
||||||
PIOS_I2C_Init();
|
// Get 3 ID bytes
|
||||||
PIOS_HMC5843_Init();
|
strcpy((char *)mag_data.id, "ZZZ");
|
||||||
// Get 3 ID bytes
|
PIOS_HMC5843_ReadID(mag_data.id);
|
||||||
strcpy((char *)mag_data.id, "ZZZ");
|
#endif
|
||||||
PIOS_HMC5843_ReadID(mag_data.id);
|
|
||||||
#endif
|
/* SPI link to master */
|
||||||
|
// PIOS_SPI_Init();
|
||||||
/* SPI link to master */
|
|
||||||
// PIOS_SPI_Init();
|
// lfsm_init();
|
||||||
|
reset_values();
|
||||||
// lfsm_init();
|
|
||||||
reset_values();
|
ahrs_state = AHRS_IDLE;
|
||||||
|
AhrsInitComms();
|
||||||
ahrs_state = AHRS_IDLE;
|
ahrs_state = AHRS_IDLE;
|
||||||
AhrsInitComms();
|
while(!AhrsLinkReady()) {
|
||||||
ahrs_state = AHRS_IDLE;
|
AhrsPoll();
|
||||||
while(!AhrsLinkReady()) {
|
while(ahrs_state != AHRS_DATA_READY) ;
|
||||||
AhrsPoll();
|
ahrs_state = AHRS_PROCESSING;
|
||||||
while(ahrs_state != AHRS_DATA_READY) ;
|
downsample_data();
|
||||||
ahrs_state = AHRS_PROCESSING;
|
ahrs_state = AHRS_IDLE;
|
||||||
downsample_data();
|
if((total_conversion_blocks % 10) == 0)
|
||||||
ahrs_state = AHRS_IDLE;
|
PIOS_LED_Toggle(LED1);
|
||||||
if((total_conversion_blocks % 10) == 0)
|
}
|
||||||
PIOS_LED_Toggle(LED1);
|
/* we didn't connect the callbacks before because we have to wait
|
||||||
}
|
for all data to be up to date before doing anything*/
|
||||||
/* we didn't connect the callbacks before because we have to wait
|
AHRSCalibrationConnectCallback(calibration_callback);
|
||||||
for all data to be up to date before doing anything*/
|
GPSPositionConnectCallback(gps_callback);
|
||||||
AHRSCalibrationConnectCallback(calibration_callback);
|
BaroAltitudeConnectCallback(altitude_callback);
|
||||||
GPSPositionConnectCallback(gps_callback);
|
AHRSSettingsConnectCallback(settings_callback);
|
||||||
BaroAltitudeConnectCallback(altitude_callback);
|
|
||||||
AHRSSettingsConnectCallback(settings_callback);
|
calibration_callback(AHRSCalibrationHandle()); //force an update
|
||||||
|
|
||||||
calibration_callback(AHRSCalibrationHandle()); //force an update
|
|
||||||
|
/* Use simple averaging filter for now */
|
||||||
|
for (int i = 0; i < adc_oversampling; i++)
|
||||||
/* Use simple averaging filter for now */
|
fir_coeffs[i] = 1;
|
||||||
for (int i = 0; i < adc_oversampling; i++)
|
fir_coeffs[adc_oversampling] = adc_oversampling;
|
||||||
fir_coeffs[i] = 1;
|
|
||||||
fir_coeffs[adc_oversampling] = adc_oversampling;
|
INSGPSInit();
|
||||||
|
|
||||||
INSGPSInit();
|
#ifdef DUMP_RAW
|
||||||
|
int previous_conversion;
|
||||||
#ifdef DUMP_RAW
|
while (1) {
|
||||||
int previous_conversion;
|
AhrsPoll();
|
||||||
while (1) {
|
int result;
|
||||||
AhrsPoll();
|
uint8_t framing[16] =
|
||||||
int result;
|
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
||||||
uint8_t framing[16] =
|
15 };
|
||||||
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
while (ahrs_state != AHRS_DATA_READY) ;
|
||||||
15 };
|
ahrs_state = AHRS_PROCESSING;
|
||||||
while (ahrs_state != AHRS_DATA_READY) ;
|
|
||||||
ahrs_state = AHRS_PROCESSING;
|
if (total_conversion_blocks != previous_conversion + 1)
|
||||||
|
PIOS_LED_On(LED1); // not keeping up
|
||||||
if (total_conversion_blocks != previous_conversion + 1)
|
else
|
||||||
PIOS_LED_On(LED1); // not keeping up
|
PIOS_LED_Off(LED1);
|
||||||
else
|
previous_conversion = total_conversion_blocks;
|
||||||
PIOS_LED_Off(LED1);
|
|
||||||
previous_conversion = total_conversion_blocks;
|
downsample_data();
|
||||||
|
ahrs_state = AHRS_IDLE;;
|
||||||
downsample_data();
|
|
||||||
ahrs_state = AHRS_IDLE;;
|
// Dump raw buffer
|
||||||
|
result = PIOS_COM_SendBuffer(PIOS_COM_AUX, &framing[0], 16); // framing header
|
||||||
// Dump raw buffer
|
result += PIOS_COM_SendBuffer(PIOS_COM_AUX, (uint8_t *) & total_conversion_blocks, sizeof(total_conversion_blocks)); // dump block number
|
||||||
result = PIOS_COM_SendBuffer(PIOS_COM_AUX, &framing[0], 16); // framing header
|
result +=
|
||||||
result += PIOS_COM_SendBuffer(PIOS_COM_AUX, (uint8_t *) & total_conversion_blocks, sizeof(total_conversion_blocks)); // dump block number
|
PIOS_COM_SendBuffer(PIOS_COM_AUX,
|
||||||
result +=
|
(uint8_t *) & valid_data_buffer[0],
|
||||||
PIOS_COM_SendBuffer(PIOS_COM_AUX,
|
adc_oversampling *
|
||||||
(uint8_t *) & valid_data_buffer[0],
|
ADC_CONTINUOUS_CHANNELS *
|
||||||
adc_oversampling *
|
sizeof(valid_data_buffer[0]));
|
||||||
ADC_CONTINUOUS_CHANNELS *
|
if (result == 0)
|
||||||
sizeof(valid_data_buffer[0]));
|
PIOS_LED_Off(LED1);
|
||||||
if (result == 0)
|
else {
|
||||||
PIOS_LED_Off(LED1);
|
PIOS_LED_On(LED1);
|
||||||
else {
|
}
|
||||||
PIOS_LED_On(LED1);
|
}
|
||||||
}
|
#endif
|
||||||
}
|
|
||||||
#endif
|
timer_start();
|
||||||
|
|
||||||
timer_start();
|
/******************* Main EKF loop ****************************/
|
||||||
|
while(1) {
|
||||||
/******************* Main EKF loop ****************************/
|
AhrsPoll();
|
||||||
while(1) {
|
AhrsStatus2Data status;
|
||||||
AhrsPoll();
|
AhrsStatus2Get(&status);
|
||||||
AhrsStatus2Data status;
|
status.CPULoad = ((float)running_counts /
|
||||||
AhrsStatus2Get(&status);
|
(float)(idle_counts + running_counts)) * 100;
|
||||||
status.CPULoad = ((float)running_counts /
|
status.IdleTimePerCyle = idle_counts / (TIMER_RATE / 10000);
|
||||||
(float)(idle_counts + running_counts)) * 100;
|
status.RunningTimePerCyle = running_counts / (TIMER_RATE / 10000);
|
||||||
status.IdleTimePerCyle = idle_counts / (TIMER_RATE / 10000);
|
status.DroppedUpdates = ekf_too_slow;
|
||||||
status.RunningTimePerCyle = running_counts / (TIMER_RATE / 10000);
|
AhrsStatus2Set(&status);
|
||||||
status.DroppedUpdates = ekf_too_slow;
|
|
||||||
AhrsStatus2Set(&status);
|
// Alive signal
|
||||||
|
if ((total_conversion_blocks % 100) == 0)
|
||||||
// Alive signal
|
PIOS_LED_Toggle(LED1);
|
||||||
if ((total_conversion_blocks % 100) == 0)
|
|
||||||
PIOS_LED_Toggle(LED1);
|
#if defined(PIOS_INCLUDE_HMC5843) && defined(PIOS_INCLUDE_I2C)
|
||||||
|
// Get magnetic readings
|
||||||
if (calibration_pending) {
|
if (PIOS_HMC5843_NewDataAvailable()) {
|
||||||
calibrate_sensors();
|
PIOS_HMC5843_ReadMag(mag_data.raw.axis);
|
||||||
calibration_pending = FALSE;
|
mag_data.scaled.axis[0] = (mag_data.raw.axis[0] * mag_data.calibration.scale[0]) + mag_data.calibration.bias[0];
|
||||||
}
|
mag_data.scaled.axis[1] = (mag_data.raw.axis[1] * mag_data.calibration.scale[1]) + mag_data.calibration.bias[1];
|
||||||
#if defined(PIOS_INCLUDE_HMC5843) && defined(PIOS_INCLUDE_I2C)
|
mag_data.scaled.axis[2] = (mag_data.raw.axis[2] * mag_data.calibration.scale[2]) + mag_data.calibration.bias[2];
|
||||||
// Get magnetic readings
|
mag_data.updated = 1;
|
||||||
if (PIOS_HMC5843_NewDataAvailable()) {
|
}
|
||||||
PIOS_HMC5843_ReadMag(mag_data.raw.axis);
|
|
||||||
mag_data.scaled.axis[0] = (mag_data.raw.axis[0] * mag_data.calibration.scale[0]) + mag_data.calibration.bias[0];
|
#endif
|
||||||
mag_data.scaled.axis[1] = (mag_data.raw.axis[1] * mag_data.calibration.scale[1]) + mag_data.calibration.bias[1];
|
// Delay for valid data
|
||||||
mag_data.scaled.axis[2] = (mag_data.raw.axis[2] * mag_data.calibration.scale[2]) + mag_data.calibration.bias[2];
|
|
||||||
mag_data.updated = 1;
|
counter_val = timer_count();
|
||||||
}
|
running_counts = counter_val - last_counter_idle_end;
|
||||||
|
last_counter_idle_start = counter_val;
|
||||||
#endif
|
|
||||||
// Delay for valid data
|
while (ahrs_state != AHRS_DATA_READY) ;
|
||||||
|
|
||||||
counter_val = timer_count();
|
counter_val = timer_count();
|
||||||
running_counts = counter_val - last_counter_idle_end;
|
idle_counts = counter_val - last_counter_idle_start;
|
||||||
last_counter_idle_start = counter_val;
|
last_counter_idle_end = counter_val;
|
||||||
|
|
||||||
while (ahrs_state != AHRS_DATA_READY) ;
|
ahrs_state = AHRS_PROCESSING;
|
||||||
|
|
||||||
counter_val = timer_count();
|
downsample_data();
|
||||||
idle_counts = counter_val - last_counter_idle_start;
|
|
||||||
last_counter_idle_end = counter_val;
|
/******************** INS ALGORITHM **************************/
|
||||||
|
if (ahrs_algorithm == INSGPS_Algo) {
|
||||||
ahrs_state = AHRS_PROCESSING;
|
|
||||||
|
// format data for INS algo
|
||||||
downsample_data();
|
gyro[0] = gyro_data.filtered.x;
|
||||||
|
gyro[1] = gyro_data.filtered.y;
|
||||||
/******************** INS ALGORITHM **************************/
|
gyro[2] = gyro_data.filtered.z;
|
||||||
if (ahrs_algorithm == INSGPS_Algo) {
|
accel[0] = accel_data.filtered.x,
|
||||||
|
accel[1] = accel_data.filtered.y,
|
||||||
// format data for INS algo
|
accel[2] = accel_data.filtered.z,
|
||||||
gyro[0] = gyro_data.filtered.x;
|
// Note: The magnetometer driver returns registers X,Y,Z from the chip which are
|
||||||
gyro[1] = gyro_data.filtered.y;
|
// (left, backward, up). Remapping to (forward, right, down).
|
||||||
gyro[2] = gyro_data.filtered.z;
|
mag[0] = -mag_data.scaled.axis[1];
|
||||||
accel[0] = accel_data.filtered.x,
|
mag[1] = -mag_data.scaled.axis[0];
|
||||||
accel[1] = accel_data.filtered.y,
|
mag[2] = -mag_data.scaled.axis[2];
|
||||||
accel[2] = accel_data.filtered.z,
|
|
||||||
// Note: The magnetometer driver returns registers X,Y,Z from the chip which are
|
INSStatePrediction(gyro, accel, 1 / (float)EKF_RATE);
|
||||||
// (left, backward, up). Remapping to (forward, right, down).
|
process_spi_request(); // get message out quickly
|
||||||
mag[0] = -mag_data.scaled.axis[1];
|
INSCovariancePrediction(1 / (float)EKF_RATE);
|
||||||
mag[1] = -mag_data.scaled.axis[0];
|
|
||||||
mag[2] = -mag_data.scaled.axis[2];
|
if (gps_data.updated && gps_data.quality == 1) {
|
||||||
|
// Compute velocity from Heading and groundspeed
|
||||||
INSStatePrediction(gyro, accel, 1 / (float)EKF_RATE);
|
vel[0] =
|
||||||
process_spi_request(); // get message out quickly
|
gps_data.groundspeed *
|
||||||
INSCovariancePrediction(1 / (float)EKF_RATE);
|
cos(gps_data.heading * M_PI / 180);
|
||||||
|
vel[1] =
|
||||||
if (gps_data.updated && gps_data.quality == 1) {
|
gps_data.groundspeed *
|
||||||
// Compute velocity from Heading and groundspeed
|
sin(gps_data.heading * M_PI / 180);
|
||||||
vel[0] =
|
|
||||||
gps_data.groundspeed *
|
INSSetPosVelVar(0.004);
|
||||||
cos(gps_data.heading * M_PI / 180);
|
if (gps_data.updated) {
|
||||||
vel[1] =
|
//TOOD: add check for altitude updates
|
||||||
gps_data.groundspeed *
|
FullCorrection(mag, gps_data.NED,
|
||||||
sin(gps_data.heading * M_PI / 180);
|
vel,
|
||||||
|
altitude_data.
|
||||||
INSSetPosVelVar(0.004);
|
altitude);
|
||||||
if (gps_data.updated) {
|
gps_data.updated = 0;
|
||||||
//TOOD: add check for altitude updates
|
} else {
|
||||||
FullCorrection(mag, gps_data.NED,
|
GpsBaroCorrection(gps_data.NED,
|
||||||
vel,
|
vel,
|
||||||
altitude_data.
|
altitude_data.
|
||||||
altitude);
|
altitude);
|
||||||
gps_data.updated = 0;
|
}
|
||||||
} else {
|
|
||||||
GpsBaroCorrection(gps_data.NED,
|
gps_data.updated = false;
|
||||||
vel,
|
mag_data.updated = 0;
|
||||||
altitude_data.
|
} else if (gps_data.quality != -1
|
||||||
altitude);
|
&& mag_data.updated == 1) {
|
||||||
}
|
float mag_var[3] = {mag_data.calibration.variance[1], mag_data.calibration.variance[0], mag_data.calibration.variance[2]};
|
||||||
|
INSSetMagVar(mag_var);
|
||||||
gps_data.updated = false;
|
MagCorrection(mag); // only trust mags if outdoors
|
||||||
mag_data.updated = 0;
|
mag_data.updated = 0;
|
||||||
} else if (gps_data.quality != -1
|
} else {
|
||||||
&& mag_data.updated == 1) {
|
// Indoors, update with zero position and velocity and high covariance
|
||||||
float mag_var[3] = {mag_data.calibration.variance[1], mag_data.calibration.variance[0], mag_data.calibration.variance[2]};
|
INSSetPosVelVar(0.1);
|
||||||
INSSetMagVar(mag_var);
|
vel[0] = 0;
|
||||||
MagCorrection(mag); // only trust mags if outdoors
|
vel[1] = 0;
|
||||||
mag_data.updated = 0;
|
vel[2] = 0;
|
||||||
} else {
|
|
||||||
// Indoors, update with zero position and velocity and high covariance
|
if(mag_data.updated == 1) {
|
||||||
INSSetPosVelVar(0.1);
|
float mag_var[3] = {10,10,10};
|
||||||
vel[0] = 0;
|
INSSetMagVar(mag_var);
|
||||||
vel[1] = 0;
|
MagVelBaroCorrection(mag,vel,altitude_data.altitude); // only trust mags if outdoors
|
||||||
vel[2] = 0;
|
mag_data.updated = 0;
|
||||||
|
} else {
|
||||||
if(mag_data.updated == 1) {
|
VelBaroCorrection(vel, altitude_data.altitude);
|
||||||
float mag_var[3] = {10,10,10};
|
}
|
||||||
INSSetMagVar(mag_var);
|
}
|
||||||
MagVelBaroCorrection(mag,vel,altitude_data.altitude); // only trust mags if outdoors
|
|
||||||
mag_data.updated = 0;
|
attitude_data.quaternion.q1 = Nav.q[0];
|
||||||
} else {
|
attitude_data.quaternion.q2 = Nav.q[1];
|
||||||
VelBaroCorrection(vel, altitude_data.altitude);
|
attitude_data.quaternion.q3 = Nav.q[2];
|
||||||
}
|
attitude_data.quaternion.q4 = Nav.q[3];
|
||||||
}
|
} else if (ahrs_algorithm == SIMPLE_Algo) {
|
||||||
|
float q[4];
|
||||||
attitude_data.quaternion.q1 = Nav.q[0];
|
float rpy[3];
|
||||||
attitude_data.quaternion.q2 = Nav.q[1];
|
/***************** SIMPLE ATTITUDE FROM NORTH AND ACCEL ************/
|
||||||
attitude_data.quaternion.q3 = Nav.q[2];
|
/* Very simple computation of the heading and attitude from accel. */
|
||||||
attitude_data.quaternion.q4 = Nav.q[3];
|
rpy[2] =
|
||||||
} else if (ahrs_algorithm == SIMPLE_Algo) {
|
atan2((mag_data.raw.axis[0]),
|
||||||
float q[4];
|
(-1 * mag_data.raw.axis[1])) * 180 /
|
||||||
float rpy[3];
|
M_PI;
|
||||||
/***************** SIMPLE ATTITUDE FROM NORTH AND ACCEL ************/
|
rpy[1] =
|
||||||
/* Very simple computation of the heading and attitude from accel. */
|
atan2(accel_data.filtered.x,
|
||||||
rpy[2] =
|
accel_data.filtered.z) * 180 / M_PI;
|
||||||
atan2((mag_data.raw.axis[0]),
|
rpy[0] =
|
||||||
(-1 * mag_data.raw.axis[1])) * 180 /
|
atan2(accel_data.filtered.y,
|
||||||
M_PI;
|
accel_data.filtered.z) * 180 / M_PI;
|
||||||
rpy[1] =
|
|
||||||
atan2(accel_data.filtered.x,
|
RPY2Quaternion(rpy, q);
|
||||||
accel_data.filtered.z) * 180 / M_PI;
|
attitude_data.quaternion.q1 = q[0];
|
||||||
rpy[0] =
|
attitude_data.quaternion.q2 = q[1];
|
||||||
atan2(accel_data.filtered.y,
|
attitude_data.quaternion.q3 = q[2];
|
||||||
accel_data.filtered.z) * 180 / M_PI;
|
attitude_data.quaternion.q4 = q[3];
|
||||||
|
process_spi_request();
|
||||||
RPY2Quaternion(rpy, q);
|
|
||||||
attitude_data.quaternion.q1 = q[0];
|
}
|
||||||
attitude_data.quaternion.q2 = q[1];
|
|
||||||
attitude_data.quaternion.q3 = q[2];
|
ahrs_state = AHRS_IDLE;
|
||||||
attitude_data.quaternion.q4 = q[3];
|
|
||||||
process_spi_request();
|
#ifdef DUMP_FRIENDLY
|
||||||
|
PIOS_COM_SendFormattedStringNonBlocking(PIOS_COM_AUX, "b: %d\r\n",
|
||||||
}
|
total_conversion_blocks);
|
||||||
|
PIOS_COM_SendFormattedStringNonBlocking(PIOS_COM_AUX,"a: %d %d %d\r\n",
|
||||||
ahrs_state = AHRS_IDLE;
|
(int16_t) (accel_data.filtered.x * 1000),
|
||||||
|
(int16_t) (accel_data.filtered.y * 1000),
|
||||||
#ifdef DUMP_FRIENDLY
|
(int16_t) (accel_data.filtered.z * 1000));
|
||||||
PIOS_COM_SendFormattedStringNonBlocking(PIOS_COM_AUX, "b: %d\r\n",
|
PIOS_COM_SendFormattedStringNonBlocking(PIOS_COM_AUX, "g: %d %d %d\r\n",
|
||||||
total_conversion_blocks);
|
(int16_t) (gyro_data.filtered.x * 1000),
|
||||||
PIOS_COM_SendFormattedStringNonBlocking(PIOS_COM_AUX,"a: %d %d %d\r\n",
|
(int16_t) (gyro_data.filtered.y * 1000),
|
||||||
(int16_t) (accel_data.filtered.x * 1000),
|
(int16_t) (gyro_data.filtered.z * 1000));
|
||||||
(int16_t) (accel_data.filtered.y * 1000),
|
PIOS_COM_SendFormattedStringNonBlocking(PIOS_COM_AUX,"m: %d %d %d\r\n",
|
||||||
(int16_t) (accel_data.filtered.z * 1000));
|
mag_data.raw.axis[0],
|
||||||
PIOS_COM_SendFormattedStringNonBlocking(PIOS_COM_AUX, "g: %d %d %d\r\n",
|
mag_data.raw.axis[1],
|
||||||
(int16_t) (gyro_data.filtered.x * 1000),
|
mag_data.raw.axis[2]);
|
||||||
(int16_t) (gyro_data.filtered.y * 1000),
|
PIOS_COM_SendFormattedStringNonBlocking(PIOS_COM_AUX,
|
||||||
(int16_t) (gyro_data.filtered.z * 1000));
|
"q: %d %d %d %d\r\n",
|
||||||
PIOS_COM_SendFormattedStringNonBlocking(PIOS_COM_AUX,"m: %d %d %d\r\n",
|
(int16_t) (Nav.q[0] * 1000),
|
||||||
mag_data.raw.axis[0],
|
(int16_t) (Nav.q[1] * 1000),
|
||||||
mag_data.raw.axis[1],
|
(int16_t) (Nav.q[2] * 1000),
|
||||||
mag_data.raw.axis[2]);
|
(int16_t) (Nav.q[3] * 1000));
|
||||||
PIOS_COM_SendFormattedStringNonBlocking(PIOS_COM_AUX,
|
#endif
|
||||||
"q: %d %d %d %d\r\n",
|
#ifdef DUMP_EKF
|
||||||
(int16_t) (Nav.q[0] * 1000),
|
uint8_t framing[16] =
|
||||||
(int16_t) (Nav.q[1] * 1000),
|
{ 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,
|
||||||
(int16_t) (Nav.q[2] * 1000),
|
0 };
|
||||||
(int16_t) (Nav.q[3] * 1000));
|
extern float F[NUMX][NUMX], G[NUMX][NUMW], H[NUMV][NUMX]; // linearized system matrices
|
||||||
#endif
|
extern float P[NUMX][NUMX], X[NUMX]; // covariance matrix and state vector
|
||||||
#ifdef DUMP_EKF
|
extern float Q[NUMW], R[NUMV]; // input noise and measurement noise variances
|
||||||
uint8_t framing[16] =
|
extern float K[NUMX][NUMV]; // feedback gain matrix
|
||||||
{ 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,
|
|
||||||
0 };
|
// Dump raw buffer
|
||||||
extern float F[NUMX][NUMX], G[NUMX][NUMW], H[NUMV][NUMX]; // linearized system matrices
|
int8_t result;
|
||||||
extern float P[NUMX][NUMX], X[NUMX]; // covariance matrix and state vector
|
result = PIOS_COM_SendBuffer(PIOS_COM_AUX, &framing[0], 16); // framing header
|
||||||
extern float Q[NUMW], R[NUMV]; // input noise and measurement noise variances
|
result += PIOS_COM_SendBuffer(PIOS_COM_AUX, (uint8_t *) & total_conversion_blocks, sizeof(total_conversion_blocks)); // dump block number
|
||||||
extern float K[NUMX][NUMV]; // feedback gain matrix
|
result +=
|
||||||
|
PIOS_COM_SendBuffer(PIOS_COM_AUX,
|
||||||
// Dump raw buffer
|
(uint8_t *) & mag_data,
|
||||||
int8_t result;
|
sizeof(mag_data));
|
||||||
result = PIOS_COM_SendBuffer(PIOS_COM_AUX, &framing[0], 16); // framing header
|
result +=
|
||||||
result += PIOS_COM_SendBuffer(PIOS_COM_AUX, (uint8_t *) & total_conversion_blocks, sizeof(total_conversion_blocks)); // dump block number
|
PIOS_COM_SendBuffer(PIOS_COM_AUX,
|
||||||
result +=
|
(uint8_t *) & gps_data,
|
||||||
PIOS_COM_SendBuffer(PIOS_COM_AUX,
|
sizeof(gps_data));
|
||||||
(uint8_t *) & mag_data,
|
result +=
|
||||||
sizeof(mag_data));
|
PIOS_COM_SendBuffer(PIOS_COM_AUX,
|
||||||
result +=
|
(uint8_t *) & accel_data,
|
||||||
PIOS_COM_SendBuffer(PIOS_COM_AUX,
|
sizeof(accel_data));
|
||||||
(uint8_t *) & gps_data,
|
result +=
|
||||||
sizeof(gps_data));
|
PIOS_COM_SendBuffer(PIOS_COM_AUX,
|
||||||
result +=
|
(uint8_t *) & gyro_data,
|
||||||
PIOS_COM_SendBuffer(PIOS_COM_AUX,
|
sizeof(gyro_data));
|
||||||
(uint8_t *) & accel_data,
|
result +=
|
||||||
sizeof(accel_data));
|
PIOS_COM_SendBuffer(PIOS_COM_AUX, (uint8_t *) & Q,
|
||||||
result +=
|
sizeof(float) * NUMX * NUMX);
|
||||||
PIOS_COM_SendBuffer(PIOS_COM_AUX,
|
result +=
|
||||||
(uint8_t *) & gyro_data,
|
PIOS_COM_SendBuffer(PIOS_COM_AUX, (uint8_t *) & K,
|
||||||
sizeof(gyro_data));
|
sizeof(float) * NUMX * NUMV);
|
||||||
result +=
|
result +=
|
||||||
PIOS_COM_SendBuffer(PIOS_COM_AUX, (uint8_t *) & Q,
|
PIOS_COM_SendBuffer(PIOS_COM_AUX, (uint8_t *) & X,
|
||||||
sizeof(float) * NUMX * NUMX);
|
sizeof(float) * NUMX * NUMX);
|
||||||
result +=
|
|
||||||
PIOS_COM_SendBuffer(PIOS_COM_AUX, (uint8_t *) & K,
|
if (result == 0)
|
||||||
sizeof(float) * NUMX * NUMV);
|
PIOS_LED_Off(LED1);
|
||||||
result +=
|
else {
|
||||||
PIOS_COM_SendBuffer(PIOS_COM_AUX, (uint8_t *) & X,
|
PIOS_LED_On(LED1);
|
||||||
sizeof(float) * NUMX * NUMX);
|
}
|
||||||
|
#endif
|
||||||
if (result == 0)
|
|
||||||
PIOS_LED_Off(LED1);
|
}
|
||||||
else {
|
|
||||||
PIOS_LED_On(LED1);
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
/**
|
||||||
}
|
* @brief Downsample the analog data
|
||||||
|
* @return none
|
||||||
return 0;
|
*
|
||||||
}
|
* Tried to make as much of the filtering fixed point when possible. Need to account
|
||||||
|
* for offset for each sample before the multiplication if filter not a boxcar. Could
|
||||||
/**
|
* precompute fixed offset as sum[fir_coeffs[i]] * ACCEL_OFFSET. Puts data into global
|
||||||
* @brief Downsample the analog data
|
* data structures @ref accel_data and @ref gyro_data.
|
||||||
* @return none
|
*
|
||||||
*
|
* The accel_data values are converted into a coordinate system where X is forwards along
|
||||||
* Tried to make as much of the filtering fixed point when possible. Need to account
|
* the fuselage, Y is along right the wing, and Z is down.
|
||||||
* for offset for each sample before the multiplication if filter not a boxcar. Could
|
*/
|
||||||
* precompute fixed offset as sum[fir_coeffs[i]] * ACCEL_OFFSET. Puts data into global
|
void downsample_data()
|
||||||
* data structures @ref accel_data and @ref gyro_data.
|
{
|
||||||
*
|
uint16_t i;
|
||||||
* The accel_data values are converted into a coordinate system where X is forwards along
|
|
||||||
* the fuselage, Y is along right the wing, and Z is down.
|
// Get the Y data. Third byte in. Convert to m/s
|
||||||
*/
|
accel_data.filtered.y = 0;
|
||||||
void downsample_data()
|
for (i = 0; i < adc_oversampling; i++)
|
||||||
{
|
accel_data.filtered.y += valid_data_buffer[0 + i * PIOS_ADC_NUM_PINS] * fir_coeffs[i];
|
||||||
uint16_t i;
|
accel_data.filtered.y /= (float) fir_coeffs[adc_oversampling];
|
||||||
|
accel_data.filtered.y = (accel_data.filtered.y * accel_data.calibration.scale[1]) + accel_data.calibration.bias[1];
|
||||||
// Get the Y data. Third byte in. Convert to m/s
|
|
||||||
accel_data.filtered.y = 0;
|
// Get the X data which projects forward/backwards. Fifth byte in. Convert to m/s
|
||||||
for (i = 0; i < adc_oversampling; i++)
|
accel_data.filtered.x = 0;
|
||||||
accel_data.filtered.y += valid_data_buffer[0 + i * PIOS_ADC_NUM_PINS] * fir_coeffs[i];
|
for (i = 0; i < adc_oversampling; i++)
|
||||||
accel_data.filtered.y /= (float) fir_coeffs[adc_oversampling];
|
accel_data.filtered.x += valid_data_buffer[2 + i * PIOS_ADC_NUM_PINS] * fir_coeffs[i];
|
||||||
accel_data.filtered.y = (accel_data.filtered.y * accel_data.calibration.scale[1]) + accel_data.calibration.bias[1];
|
accel_data.filtered.x /= (float) fir_coeffs[adc_oversampling];
|
||||||
|
accel_data.filtered.x = (accel_data.filtered.x * accel_data.calibration.scale[0]) + accel_data.calibration.bias[0];
|
||||||
// Get the X data which projects forward/backwards. Fifth byte in. Convert to m/s
|
|
||||||
accel_data.filtered.x = 0;
|
// Get the Z data. Third byte in. Convert to m/s
|
||||||
for (i = 0; i < adc_oversampling; i++)
|
accel_data.filtered.z = 0;
|
||||||
accel_data.filtered.x += valid_data_buffer[2 + i * PIOS_ADC_NUM_PINS] * fir_coeffs[i];
|
for (i = 0; i < adc_oversampling; i++)
|
||||||
accel_data.filtered.x /= (float) fir_coeffs[adc_oversampling];
|
accel_data.filtered.z += valid_data_buffer[4 + i * PIOS_ADC_NUM_PINS] * fir_coeffs[i];
|
||||||
accel_data.filtered.x = (accel_data.filtered.x * accel_data.calibration.scale[0]) + accel_data.calibration.bias[0];
|
accel_data.filtered.z /= (float) fir_coeffs[adc_oversampling];
|
||||||
|
accel_data.filtered.z = (accel_data.filtered.z * accel_data.calibration.scale[2]) + accel_data.calibration.bias[2];
|
||||||
// Get the Z data. Third byte in. Convert to m/s
|
|
||||||
accel_data.filtered.z = 0;
|
// Get the X gyro data. Seventh byte in. Convert to deg/s.
|
||||||
for (i = 0; i < adc_oversampling; i++)
|
gyro_data.filtered.x = 0;
|
||||||
accel_data.filtered.z += valid_data_buffer[4 + i * PIOS_ADC_NUM_PINS] * fir_coeffs[i];
|
for (i = 0; i < adc_oversampling; i++)
|
||||||
accel_data.filtered.z /= (float) fir_coeffs[adc_oversampling];
|
gyro_data.filtered.x += valid_data_buffer[1 + i * PIOS_ADC_NUM_PINS] * fir_coeffs[i];
|
||||||
accel_data.filtered.z = (accel_data.filtered.z * accel_data.calibration.scale[2]) + accel_data.calibration.bias[2];
|
gyro_data.filtered.x /= fir_coeffs[adc_oversampling];
|
||||||
|
gyro_data.filtered.x = (gyro_data.filtered.x * gyro_data.calibration.scale[0]) + gyro_data.calibration.bias[0];
|
||||||
// Get the X gyro data. Seventh byte in. Convert to deg/s.
|
|
||||||
gyro_data.filtered.x = 0;
|
// Get the Y gyro data. Second byte in. Convert to deg/s.
|
||||||
for (i = 0; i < adc_oversampling; i++)
|
gyro_data.filtered.y = 0;
|
||||||
gyro_data.filtered.x += valid_data_buffer[1 + i * PIOS_ADC_NUM_PINS] * fir_coeffs[i];
|
for (i = 0; i < adc_oversampling; i++)
|
||||||
gyro_data.filtered.x /= fir_coeffs[adc_oversampling];
|
gyro_data.filtered.y += valid_data_buffer[3 + i * PIOS_ADC_NUM_PINS] * fir_coeffs[i];
|
||||||
gyro_data.filtered.x = (gyro_data.filtered.x * gyro_data.calibration.scale[0]) + gyro_data.calibration.bias[0];
|
gyro_data.filtered.y /= fir_coeffs[adc_oversampling];
|
||||||
|
gyro_data.filtered.y = (gyro_data.filtered.y * gyro_data.calibration.scale[1]) + gyro_data.calibration.bias[1];
|
||||||
// Get the Y gyro data. Second byte in. Convert to deg/s.
|
|
||||||
gyro_data.filtered.y = 0;
|
// Get the Z gyro data. Fifth byte in. Convert to deg/s.
|
||||||
for (i = 0; i < adc_oversampling; i++)
|
gyro_data.filtered.z = 0;
|
||||||
gyro_data.filtered.y += valid_data_buffer[3 + i * PIOS_ADC_NUM_PINS] * fir_coeffs[i];
|
for (i = 0; i < adc_oversampling; i++)
|
||||||
gyro_data.filtered.y /= fir_coeffs[adc_oversampling];
|
gyro_data.filtered.z += valid_data_buffer[5 + i * PIOS_ADC_NUM_PINS] * fir_coeffs[i];
|
||||||
gyro_data.filtered.y = (gyro_data.filtered.y * gyro_data.calibration.scale[1]) + gyro_data.calibration.bias[1];
|
gyro_data.filtered.z /= fir_coeffs[adc_oversampling];
|
||||||
|
gyro_data.filtered.z = (gyro_data.filtered.z * gyro_data.calibration.scale[2]) + gyro_data.calibration.bias[2];
|
||||||
// Get the Z gyro data. Fifth byte in. Convert to deg/s.
|
|
||||||
gyro_data.filtered.z = 0;
|
AttitudeRawData raw;
|
||||||
for (i = 0; i < adc_oversampling; i++)
|
|
||||||
gyro_data.filtered.z += valid_data_buffer[5 + i * PIOS_ADC_NUM_PINS] * fir_coeffs[i];
|
raw.gyros[0] = valid_data_buffer[1];
|
||||||
gyro_data.filtered.z /= fir_coeffs[adc_oversampling];
|
raw.gyros[1] = valid_data_buffer[3];
|
||||||
gyro_data.filtered.z = (gyro_data.filtered.z * gyro_data.calibration.scale[2]) + gyro_data.calibration.bias[2];
|
raw.gyros[2] = valid_data_buffer[5];
|
||||||
|
|
||||||
AttitudeRawData raw;
|
raw.gyros_filtered[0] = gyro_data.filtered.x;
|
||||||
|
raw.gyros_filtered[1] = gyro_data.filtered.y;
|
||||||
raw.gyros[0] = valid_data_buffer[1];
|
raw.gyros_filtered[2] = gyro_data.filtered.z;
|
||||||
raw.gyros[1] = valid_data_buffer[3];
|
|
||||||
raw.gyros[2] = valid_data_buffer[5];
|
raw.accels[0] = valid_data_buffer[2];
|
||||||
|
raw.accels[1] = valid_data_buffer[0];
|
||||||
raw.gyros_filtered[0] = gyro_data.filtered.x;
|
raw.accels[2] = valid_data_buffer[4];
|
||||||
raw.gyros_filtered[1] = gyro_data.filtered.y;
|
|
||||||
raw.gyros_filtered[2] = gyro_data.filtered.z;
|
raw.accels_filtered[0] = accel_data.filtered.x;
|
||||||
|
raw.accels_filtered[1] = accel_data.filtered.y;
|
||||||
raw.accels[0] = valid_data_buffer[2];
|
raw.accels_filtered[2] = accel_data.filtered.z;
|
||||||
raw.accels[1] = valid_data_buffer[0];
|
|
||||||
raw.accels[2] = valid_data_buffer[4];
|
raw.magnetometers[0] = mag_data.scaled.axis[0];
|
||||||
|
raw.magnetometers[1] = mag_data.scaled.axis[1];
|
||||||
raw.accels_filtered[0] = accel_data.filtered.x;
|
raw.magnetometers[2] = mag_data.scaled.axis[2];
|
||||||
raw.accels_filtered[1] = accel_data.filtered.y;
|
|
||||||
raw.accels_filtered[2] = accel_data.filtered.z;
|
AttitudeRawSet(&raw);
|
||||||
|
}
|
||||||
raw.magnetometers[0] = mag_data.scaled.axis[0];
|
|
||||||
raw.magnetometers[1] = mag_data.scaled.axis[1];
|
/**
|
||||||
raw.magnetometers[2] = mag_data.scaled.axis[2];
|
* @brief Assumes board is not moving computes biases and variances of sensors
|
||||||
|
* @returns None
|
||||||
AttitudeRawSet(&raw);
|
*
|
||||||
}
|
* All data is stored in global structures. This function should be called from OP when
|
||||||
|
* aircraft is in stable state and then the data stored to SD card.
|
||||||
/**
|
*
|
||||||
* @brief Assumes board is not moving computes biases and variances of sensors
|
* After this function the bias for each sensor will be the mean value. This doesn't make
|
||||||
* @returns None
|
* sense for the z accel so make sure 6 point calibration is also run and those values set
|
||||||
*
|
* after these read.
|
||||||
* All data is stored in global structures. This function should be called from OP when
|
*/
|
||||||
* aircraft is in stable state and then the data stored to SD card.
|
#define NBIAS 100
|
||||||
*
|
#define NVAR 500
|
||||||
* After this function the bias for each sensor will be the mean value. This doesn't make
|
void calibrate_sensors()
|
||||||
* sense for the z accel so make sure 6 point calibration is also run and those values set
|
{
|
||||||
* after these read.
|
int i,j;
|
||||||
*/
|
float accel_bias[3] = {0, 0, 0};
|
||||||
#define NBIAS 100
|
float gyro_bias[3] = {0, 0, 0};
|
||||||
#define NVAR 500
|
float mag_bias[3] = {0, 0, 0};
|
||||||
void calibrate_sensors()
|
|
||||||
{
|
|
||||||
int i,j;
|
for (i = 0, j = 0; i < NBIAS; i++) {
|
||||||
float accel_bias[3] = {0, 0, 0};
|
while (ahrs_state != AHRS_DATA_READY) ;
|
||||||
float gyro_bias[3] = {0, 0, 0};
|
ahrs_state = AHRS_PROCESSING;
|
||||||
float mag_bias[3] = {0, 0, 0};
|
downsample_data();
|
||||||
|
gyro_bias[0] += gyro_data.filtered.x / NBIAS;
|
||||||
|
gyro_bias[1] += gyro_data.filtered.y / NBIAS;
|
||||||
for (i = 0, j = 0; i < NBIAS; i++) {
|
gyro_bias[2] += gyro_data.filtered.z / NBIAS;
|
||||||
while (ahrs_state != AHRS_DATA_READY) ;
|
accel_bias[0] += accel_data.filtered.x / NBIAS;
|
||||||
ahrs_state = AHRS_PROCESSING;
|
accel_bias[1] += accel_data.filtered.y / NBIAS;
|
||||||
downsample_data();
|
accel_bias[2] += accel_data.filtered.z / NBIAS;
|
||||||
gyro_bias[0] += gyro_data.filtered.x / NBIAS;
|
ahrs_state = AHRS_IDLE;
|
||||||
gyro_bias[1] += gyro_data.filtered.y / NBIAS;
|
|
||||||
gyro_bias[2] += gyro_data.filtered.z / NBIAS;
|
#if defined(PIOS_INCLUDE_HMC5843) && defined(PIOS_INCLUDE_I2C)
|
||||||
accel_bias[0] += accel_data.filtered.x / NBIAS;
|
if(PIOS_HMC5843_NewDataAvailable()) {
|
||||||
accel_bias[1] += accel_data.filtered.y / NBIAS;
|
j ++;
|
||||||
accel_bias[2] += accel_data.filtered.z / NBIAS;
|
PIOS_HMC5843_ReadMag(mag_data.raw.axis);
|
||||||
ahrs_state = AHRS_IDLE;
|
mag_data.scaled.axis[0] = (mag_data.raw.axis[0] * mag_data.calibration.scale[0]) + mag_data.calibration.bias[0];
|
||||||
|
mag_data.scaled.axis[1] = (mag_data.raw.axis[1] * mag_data.calibration.scale[1]) + mag_data.calibration.bias[1];
|
||||||
#if defined(PIOS_INCLUDE_HMC5843) && defined(PIOS_INCLUDE_I2C)
|
mag_data.scaled.axis[2] = (mag_data.raw.axis[2] * mag_data.calibration.scale[2]) + mag_data.calibration.bias[2];
|
||||||
if(PIOS_HMC5843_NewDataAvailable()) {
|
mag_bias[0] += mag_data.scaled.axis[0];
|
||||||
j ++;
|
mag_bias[1] += mag_data.scaled.axis[1];
|
||||||
PIOS_HMC5843_ReadMag(mag_data.raw.axis);
|
mag_bias[2] += mag_data.scaled.axis[2];
|
||||||
mag_data.scaled.axis[0] = (mag_data.raw.axis[0] * mag_data.calibration.scale[0]) + mag_data.calibration.bias[0];
|
}
|
||||||
mag_data.scaled.axis[1] = (mag_data.raw.axis[1] * mag_data.calibration.scale[1]) + mag_data.calibration.bias[1];
|
#endif
|
||||||
mag_data.scaled.axis[2] = (mag_data.raw.axis[2] * mag_data.calibration.scale[2]) + mag_data.calibration.bias[2];
|
|
||||||
mag_bias[0] += mag_data.scaled.axis[0];
|
}
|
||||||
mag_bias[1] += mag_data.scaled.axis[1];
|
mag_bias[0] /= j;
|
||||||
mag_bias[2] += mag_data.scaled.axis[2];
|
mag_bias[1] /= j;
|
||||||
}
|
mag_bias[2] /= j;
|
||||||
#endif
|
|
||||||
|
gyro_data.calibration.variance[0] = 0;
|
||||||
}
|
gyro_data.calibration.variance[1] = 0;
|
||||||
mag_bias[0] /= j;
|
gyro_data.calibration.variance[2] = 0;
|
||||||
mag_bias[1] /= j;
|
mag_data.calibration.variance[0] = 0;
|
||||||
mag_bias[2] /= j;
|
mag_data.calibration.variance[1] = 0;
|
||||||
|
mag_data.calibration.variance[2] = 0;
|
||||||
gyro_data.calibration.variance[0] = 0;
|
accel_data.calibration.variance[0] = 0;
|
||||||
gyro_data.calibration.variance[1] = 0;
|
accel_data.calibration.variance[1] = 0;
|
||||||
gyro_data.calibration.variance[2] = 0;
|
accel_data.calibration.variance[2] = 0;
|
||||||
mag_data.calibration.variance[0] = 0;
|
|
||||||
mag_data.calibration.variance[1] = 0;
|
for (i = 0, j = 0; j < NVAR; j++) {
|
||||||
mag_data.calibration.variance[2] = 0;
|
while (ahrs_state != AHRS_DATA_READY) ;
|
||||||
accel_data.calibration.variance[0] = 0;
|
ahrs_state = AHRS_PROCESSING;
|
||||||
accel_data.calibration.variance[1] = 0;
|
downsample_data();
|
||||||
accel_data.calibration.variance[2] = 0;
|
gyro_data.calibration.variance[0] += pow(gyro_data.filtered.x-gyro_bias[0],2) / NVAR;
|
||||||
|
gyro_data.calibration.variance[1] += pow(gyro_data.filtered.y-gyro_bias[1],2) / NVAR;
|
||||||
for (i = 0, j = 0; j < NVAR; j++) {
|
gyro_data.calibration.variance[2] += pow(gyro_data.filtered.z-gyro_bias[2],2) / NVAR;
|
||||||
while (ahrs_state != AHRS_DATA_READY) ;
|
accel_data.calibration.variance[0] += pow(accel_data.filtered.x-accel_bias[0],2) / NVAR;
|
||||||
ahrs_state = AHRS_PROCESSING;
|
accel_data.calibration.variance[1] += pow(accel_data.filtered.y-accel_bias[1],2) / NVAR;
|
||||||
downsample_data();
|
accel_data.calibration.variance[2] += pow(accel_data.filtered.z-accel_bias[2],2) / NVAR;
|
||||||
gyro_data.calibration.variance[0] += pow(gyro_data.filtered.x-gyro_bias[0],2) / NVAR;
|
ahrs_state = AHRS_IDLE;
|
||||||
gyro_data.calibration.variance[1] += pow(gyro_data.filtered.y-gyro_bias[1],2) / NVAR;
|
#if defined(PIOS_INCLUDE_HMC5843) && defined(PIOS_INCLUDE_I2C)
|
||||||
gyro_data.calibration.variance[2] += pow(gyro_data.filtered.z-gyro_bias[2],2) / NVAR;
|
if(PIOS_HMC5843_NewDataAvailable()) {
|
||||||
accel_data.calibration.variance[0] += pow(accel_data.filtered.x-accel_bias[0],2) / NVAR;
|
j ++;
|
||||||
accel_data.calibration.variance[1] += pow(accel_data.filtered.y-accel_bias[1],2) / NVAR;
|
PIOS_HMC5843_ReadMag(mag_data.raw.axis);
|
||||||
accel_data.calibration.variance[2] += pow(accel_data.filtered.z-accel_bias[2],2) / NVAR;
|
mag_data.scaled.axis[0] = (mag_data.raw.axis[0] * mag_data.calibration.scale[0]) + mag_data.calibration.bias[0];
|
||||||
ahrs_state = AHRS_IDLE;
|
mag_data.scaled.axis[1] = (mag_data.raw.axis[1] * mag_data.calibration.scale[1]) + mag_data.calibration.bias[1];
|
||||||
#if defined(PIOS_INCLUDE_HMC5843) && defined(PIOS_INCLUDE_I2C)
|
mag_data.scaled.axis[2] = (mag_data.raw.axis[2] * mag_data.calibration.scale[2]) + mag_data.calibration.bias[2];
|
||||||
if(PIOS_HMC5843_NewDataAvailable()) {
|
mag_data.calibration.variance[0] += pow(mag_data.scaled.axis[0]-mag_bias[0],2);
|
||||||
j ++;
|
mag_data.calibration.variance[1] += pow(mag_data.scaled.axis[1]-mag_bias[1],2);
|
||||||
PIOS_HMC5843_ReadMag(mag_data.raw.axis);
|
mag_data.calibration.variance[2] += pow(mag_data.scaled.axis[2]-mag_bias[2],2);
|
||||||
mag_data.scaled.axis[0] = (mag_data.raw.axis[0] * mag_data.calibration.scale[0]) + mag_data.calibration.bias[0];
|
}
|
||||||
mag_data.scaled.axis[1] = (mag_data.raw.axis[1] * mag_data.calibration.scale[1]) + mag_data.calibration.bias[1];
|
#endif
|
||||||
mag_data.scaled.axis[2] = (mag_data.raw.axis[2] * mag_data.calibration.scale[2]) + mag_data.calibration.bias[2];
|
|
||||||
mag_data.calibration.variance[0] += pow(mag_data.scaled.axis[0]-mag_bias[0],2);
|
}
|
||||||
mag_data.calibration.variance[1] += pow(mag_data.scaled.axis[1]-mag_bias[1],2);
|
|
||||||
mag_data.calibration.variance[2] += pow(mag_data.scaled.axis[2]-mag_bias[2],2);
|
mag_data.calibration.variance[0] /= j;
|
||||||
}
|
mag_data.calibration.variance[1] /= j;
|
||||||
#endif
|
mag_data.calibration.variance[2] /= j;
|
||||||
|
|
||||||
}
|
gyro_data.calibration.bias[0] -= gyro_bias[0];
|
||||||
|
gyro_data.calibration.bias[1] -= gyro_bias[1];
|
||||||
mag_data.calibration.variance[0] /= j;
|
gyro_data.calibration.bias[2] -= gyro_bias[2];
|
||||||
mag_data.calibration.variance[1] /= j;
|
}
|
||||||
mag_data.calibration.variance[2] /= j;
|
|
||||||
|
/**
|
||||||
gyro_data.calibration.bias[0] -= gyro_bias[0];
|
* @brief Populate fields with initial values
|
||||||
gyro_data.calibration.bias[1] -= gyro_bias[1];
|
*/
|
||||||
gyro_data.calibration.bias[2] -= gyro_bias[2];
|
void reset_values() {
|
||||||
AHRSCalibrationData cal;
|
accel_data.calibration.scale[0] = 0.012;
|
||||||
AHRSCalibrationGet(&cal);
|
accel_data.calibration.scale[1] = 0.012;
|
||||||
cal.measure_var = AHRSCALIBRATION_MEASURE_VAR_SET;
|
accel_data.calibration.scale[2] = -0.012;
|
||||||
AHRSCalibrationSet(&cal);
|
accel_data.calibration.bias[0] = 24;
|
||||||
}
|
accel_data.calibration.bias[1] = 24;
|
||||||
|
accel_data.calibration.bias[2] = -24;
|
||||||
/**
|
accel_data.calibration.variance[0] = 1e-4;
|
||||||
* @brief Populate fields with initial values
|
accel_data.calibration.variance[1] = 1e-4;
|
||||||
*/
|
accel_data.calibration.variance[2] = 1e-4;
|
||||||
void reset_values() {
|
gyro_data.calibration.scale[0] = -0.014;
|
||||||
accel_data.calibration.scale[0] = 0.012;
|
gyro_data.calibration.scale[1] = 0.014;
|
||||||
accel_data.calibration.scale[1] = 0.012;
|
gyro_data.calibration.scale[2] = -0.014;
|
||||||
accel_data.calibration.scale[2] = -0.012;
|
gyro_data.calibration.bias[0] = -24;
|
||||||
accel_data.calibration.bias[0] = 24;
|
gyro_data.calibration.bias[1] = -24;
|
||||||
accel_data.calibration.bias[1] = 24;
|
gyro_data.calibration.bias[2] = -24;
|
||||||
accel_data.calibration.bias[2] = -24;
|
gyro_data.calibration.variance[0] = 1;
|
||||||
accel_data.calibration.variance[0] = 1e-4;
|
gyro_data.calibration.variance[1] = 1;
|
||||||
accel_data.calibration.variance[1] = 1e-4;
|
gyro_data.calibration.variance[2] = 1;
|
||||||
accel_data.calibration.variance[2] = 1e-4;
|
mag_data.calibration.scale[0] = 1;
|
||||||
gyro_data.calibration.scale[0] = -0.014;
|
mag_data.calibration.scale[1] = 1;
|
||||||
gyro_data.calibration.scale[1] = 0.014;
|
mag_data.calibration.scale[2] = 1;
|
||||||
gyro_data.calibration.scale[2] = -0.014;
|
mag_data.calibration.bias[0] = 0;
|
||||||
gyro_data.calibration.bias[0] = -24;
|
mag_data.calibration.bias[1] = 0;
|
||||||
gyro_data.calibration.bias[1] = -24;
|
mag_data.calibration.bias[2] = 0;
|
||||||
gyro_data.calibration.bias[2] = -24;
|
mag_data.calibration.variance[0] = 1;
|
||||||
gyro_data.calibration.variance[0] = 1;
|
mag_data.calibration.variance[1] = 1;
|
||||||
gyro_data.calibration.variance[1] = 1;
|
mag_data.calibration.variance[2] = 1;
|
||||||
gyro_data.calibration.variance[2] = 1;
|
}
|
||||||
mag_data.calibration.scale[0] = 1;
|
|
||||||
mag_data.calibration.scale[1] = 1;
|
|
||||||
mag_data.calibration.scale[2] = 1;
|
void process_spi_request(void)
|
||||||
mag_data.calibration.bias[0] = 0;
|
{
|
||||||
mag_data.calibration.bias[1] = 0;
|
AttitudeActualData attitude;
|
||||||
mag_data.calibration.bias[2] = 0;
|
attitude.q1 = attitude_data.quaternion.q1;
|
||||||
mag_data.calibration.variance[0] = 1;
|
attitude.q2 = attitude_data.quaternion.q2;
|
||||||
mag_data.calibration.variance[1] = 1;
|
attitude.q3 = attitude_data.quaternion.q3;
|
||||||
mag_data.calibration.variance[2] = 1;
|
attitude.q4 = attitude_data.quaternion.q4;
|
||||||
}
|
float rpy[3];
|
||||||
|
Quaternion2RPY(&attitude_data.quaternion.q1, rpy);
|
||||||
|
attitude.Roll = rpy[0];
|
||||||
void process_spi_request(void)
|
attitude.Pitch = rpy[1];
|
||||||
{
|
attitude.Yaw = rpy[2];
|
||||||
AttitudeActualData attitude;
|
AttitudeActualSet(&attitude);
|
||||||
attitude.q1 = attitude_data.quaternion.q1;
|
}
|
||||||
attitude.q2 = attitude_data.quaternion.q2;
|
|
||||||
attitude.q3 = attitude_data.quaternion.q3;
|
void send_calibration(void)
|
||||||
attitude.q4 = attitude_data.quaternion.q4;
|
{
|
||||||
float rpy[3];
|
AHRSCalibrationData cal;
|
||||||
Quaternion2RPY(&attitude_data.quaternion.q1, rpy);
|
AHRSCalibrationGet(&cal);
|
||||||
attitude.Roll = rpy[0];
|
for(int ct=0; ct<3; ct++)
|
||||||
attitude.Pitch = rpy[1];
|
{
|
||||||
attitude.Yaw = rpy[2];
|
cal.accel_var[ct] = accel_data.calibration.variance[ct];
|
||||||
AttitudeActualSet(&attitude);
|
cal.gyro_bias[ct] = gyro_data.calibration.bias[ct];
|
||||||
}
|
cal.gyro_var[ct] = gyro_data.calibration.variance[ct];
|
||||||
|
cal.mag_var[ct] = mag_data.calibration.variance[ct];
|
||||||
void send_calibration(void)
|
}
|
||||||
{
|
cal.measure_var = AHRSCALIBRATION_MEASURE_VAR_SET;
|
||||||
AHRSCalibrationData cal;
|
AHRSCalibrationSet(&cal);
|
||||||
AHRSCalibrationGet(&cal);
|
}
|
||||||
for(int ct=0; ct<3; ct++)
|
|
||||||
{
|
/**
|
||||||
cal.accel_var[ct] = accel_data.calibration.variance[ct];
|
* @brief AHRS calibration callback
|
||||||
cal.gyro_bias[ct] = gyro_data.calibration.bias[ct];
|
*
|
||||||
cal.gyro_var[ct] = gyro_data.calibration.variance[ct];
|
* Called when the OP board sets the calibration
|
||||||
cal.mag_var[ct] = mag_data.calibration.variance[ct];
|
*/
|
||||||
}
|
void calibration_callback(AhrsObjHandle obj)
|
||||||
cal.measure_var = AHRSCALIBRATION_MEASURE_VAR_SET;
|
{
|
||||||
AHRSCalibrationSet(&cal);
|
AHRSCalibrationData cal;
|
||||||
}
|
AHRSCalibrationGet(&cal);
|
||||||
|
if(cal.measure_var == AHRSCALIBRATION_MEASURE_VAR_SET){
|
||||||
/**
|
for(int ct=0; ct<3; ct++)
|
||||||
* @brief AHRS calibration callback
|
{
|
||||||
*
|
accel_data.calibration.scale[ct] = cal.accel_scale[ct];
|
||||||
* Called when the OP board sets the calibration
|
accel_data.calibration.bias[ct] = cal.accel_bias[ct];
|
||||||
*/
|
accel_data.calibration.variance[ct] = cal.accel_var[ct];
|
||||||
void calibration_callback(AhrsObjHandle obj)
|
gyro_data.calibration.scale[ct] = cal.gyro_scale[ct];
|
||||||
{
|
gyro_data.calibration.bias[ct] = cal.gyro_bias[ct];
|
||||||
AHRSCalibrationData cal;
|
gyro_data.calibration.variance[ct] = cal.gyro_var[ct];
|
||||||
AHRSCalibrationGet(&cal);
|
mag_data.calibration.bias[ct] = cal.mag_bias[ct];
|
||||||
if(cal.measure_var == AHRSCALIBRATION_MEASURE_VAR_SET){
|
mag_data.calibration.scale[ct] = cal.mag_scale[ct];
|
||||||
for(int ct=0; ct<3; ct++)
|
mag_data.calibration.variance[ct] = cal.mag_var[ct];
|
||||||
{
|
}
|
||||||
accel_data.calibration.scale[ct] = cal.accel_scale[ct];
|
}else if(cal.measure_var == AHRSCALIBRATION_MEASURE_VAR_MEASURE){
|
||||||
accel_data.calibration.bias[ct] = cal.accel_bias[ct];
|
calibrate_sensors();
|
||||||
accel_data.calibration.variance[ct] = cal.accel_var[ct];
|
AHRSCalibrationData cal;
|
||||||
gyro_data.calibration.scale[ct] = cal.gyro_scale[ct];
|
AHRSCalibrationGet(&cal);
|
||||||
gyro_data.calibration.bias[ct] = cal.gyro_bias[ct];
|
cal.measure_var = AHRSCALIBRATION_MEASURE_VAR_SET;
|
||||||
gyro_data.calibration.variance[ct] = cal.gyro_var[ct];
|
AHRSCalibrationSet(&cal);
|
||||||
mag_data.calibration.bias[ct] = cal.mag_bias[ct];
|
|
||||||
mag_data.calibration.scale[ct] = cal.mag_scale[ct];
|
}else if(cal.measure_var == AHRSCALIBRATION_MEASURE_VAR_ECHO){
|
||||||
mag_data.calibration.variance[ct] = cal.mag_var[ct];
|
send_calibration();
|
||||||
}
|
}
|
||||||
}else if(cal.measure_var == AHRSCALIBRATION_MEASURE_VAR_MEASURE){
|
}
|
||||||
calibration_pending = true;
|
|
||||||
}else if(cal.measure_var == AHRSCALIBRATION_MEASURE_VAR_ECHO){
|
void gps_callback(AhrsObjHandle obj)
|
||||||
send_calibration();
|
{
|
||||||
}
|
GPSPositionData pos;
|
||||||
}
|
GPSPositionGet(&pos);
|
||||||
|
HomeLocationData home;
|
||||||
void gps_callback(AhrsObjHandle obj)
|
HomeLocationGet(&home);
|
||||||
{
|
|
||||||
GPSPositionData pos;
|
if(home.Set == HOMELOCATION_SET_FALSE || home.Indoor == HOMELOCATION_INDOOR_TRUE) {
|
||||||
GPSPositionGet(&pos);
|
gps_data.NED[0] = 0;
|
||||||
HomeLocationData home;
|
gps_data.NED[1] = 0;
|
||||||
HomeLocationGet(&home);
|
gps_data.NED[2] = 0;
|
||||||
|
gps_data.groundspeed = 0;
|
||||||
if(home.Set == HOMELOCATION_SET_FALSE || home.Indoor == HOMELOCATION_INDOOR_TRUE) {
|
gps_data.heading = 0;
|
||||||
gps_data.NED[0] = 0;
|
gps_data.quality = -1; // indicates indoor mode, high variance zeros update
|
||||||
gps_data.NED[1] = 0;
|
gps_data.updated = true;
|
||||||
gps_data.NED[2] = 0;
|
return;
|
||||||
gps_data.groundspeed = 0;
|
}
|
||||||
gps_data.heading = 0;
|
|
||||||
gps_data.quality = -1; // indicates indoor mode, high variance zeros update
|
if(pos.Status != GPSPOSITION_STATUS_FIX3D) //FIXME: Will this work? the old ahrs_comms does it differently.
|
||||||
gps_data.updated = true;
|
{
|
||||||
return;
|
gps_data.quality = 0;
|
||||||
}
|
gps_data.updated = true;
|
||||||
|
return;
|
||||||
if(pos.Status != GPSPOSITION_STATUS_FIX3D) //FIXME: Will this work? the old ahrs_comms does it differently.
|
}
|
||||||
{
|
|
||||||
gps_data.quality = 0;
|
double LLA[3] = {(double) pos.Latitude / 1e7, (double) pos.Longitude / 1e7, (double) (pos.GeoidSeparation + pos.Altitude)};
|
||||||
gps_data.updated = true;
|
// convert from cm back to meters
|
||||||
return;
|
double ECEF[3] = {(double) (home.ECEF[0] / 100), (double) (home.ECEF[1] / 100), (double) (home.ECEF[2] / 100)};
|
||||||
}
|
LLA2Base(LLA, ECEF, (float (*)[3]) home.RNE, gps_data.NED);
|
||||||
|
|
||||||
double LLA[3] = {(double) pos.Latitude / 1e7, (double) pos.Longitude / 1e7, (double) (pos.GeoidSeparation + pos.Altitude)};
|
gps_data.heading = pos.Heading;
|
||||||
// convert from cm back to meters
|
gps_data.groundspeed = pos.Groundspeed;
|
||||||
double ECEF[3] = {(double) (home.ECEF[0] / 100), (double) (home.ECEF[1] / 100), (double) (home.ECEF[2] / 100)};
|
gps_data.quality = 1;
|
||||||
LLA2Base(LLA, ECEF, (float (*)[3]) home.RNE, gps_data.NED);
|
gps_data.updated = true;
|
||||||
|
}
|
||||||
gps_data.heading = pos.Heading;
|
|
||||||
gps_data.groundspeed = pos.Groundspeed;
|
void altitude_callback(AhrsObjHandle obj)
|
||||||
gps_data.quality = 1;
|
{
|
||||||
gps_data.updated = true;
|
BaroAltitudeData alt;
|
||||||
}
|
BaroAltitudeGet(&alt);
|
||||||
|
altitude_data.altitude = alt.Altitude;
|
||||||
void altitude_callback(AhrsObjHandle obj)
|
altitude_data.updated = true;
|
||||||
{
|
}
|
||||||
BaroAltitudeData alt;
|
|
||||||
BaroAltitudeGet(&alt);
|
void settings_callback(AhrsObjHandle obj)
|
||||||
altitude_data.altitude = alt.Altitude;
|
{
|
||||||
altitude_data.updated = true;
|
AHRSSettingsData settings;
|
||||||
}
|
AHRSSettingsGet(&settings);
|
||||||
|
|
||||||
void settings_callback(AhrsObjHandle obj)
|
if(settings.Algorithm == AHRSSETTINGS_ALGORITHM_INSGPS)
|
||||||
{
|
{
|
||||||
AHRSSettingsData settings;
|
ahrs_algorithm = INSGPS_Algo;
|
||||||
AHRSSettingsGet(&settings);
|
}else
|
||||||
|
{
|
||||||
if(settings.Algorithm == AHRSSETTINGS_ALGORITHM_INSGPS)
|
ahrs_algorithm = SIMPLE_Algo;
|
||||||
{
|
}
|
||||||
ahrs_algorithm = INSGPS_Algo;
|
}
|
||||||
}else
|
|
||||||
{
|
|
||||||
ahrs_algorithm = SIMPLE_Algo;
|
|
||||||
}
|
/**
|
||||||
}
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user