[ardrone2] Magneto axis correction and calibration

This commit is contained in:
fvantienen
2013-08-26 14:24:42 +02:00
parent 3bf713a831
commit b895ded49c
4 changed files with 65 additions and 22 deletions
+17 -18
View File
@@ -22,18 +22,16 @@
<subsystem name="actuators" type="ardrone2" />
<subsystem name="imu" type="ardrone2" />
<subsystem name="gps" type="sirf" />
<subsystem name="gps" type="ublox" />
<subsystem name="stabilization" type="int_quat" />
<subsystem name="ahrs" type="int_cmpl_quat" />
<subsystem name="ins" />
</firmware>
<!--
<modules main_freq="512" >
<load name="gps_ubx_ucenter.xml" />
</modules>
-->
<commands>
<axis name="PITCH" failsafe_value="0" />
@@ -71,16 +69,16 @@
</command_laws>
<section name="IMU" prefix="IMU_">
<define name="ACCEL_X_NEUTRAL" value="2072" />
<define name="ACCEL_Y_NEUTRAL" value="2040" />
<define name="ACCEL_Z_NEUTRAL" value="2047" />
<define name="ACCEL_X_NEUTRAL" value="2056" />
<define name="ACCEL_Y_NEUTRAL" value="2060" />
<define name="ACCEL_Z_NEUTRAL" value="2052" />
<define name="ACCEL_X_SENS" value="19.1079036954" integer="16" />
<define name="ACCEL_Y_SENS" value="19.5393623518" integer="16" />
<define name="ACCEL_Z_SENS" value="19.6539180847" integer="16" />
<define name="ACCEL_X_SIGN" value="1" />
<define name="ACCEL_Y_SIGN" value="-1" />
<define name="ACCEL_Z_SIGN" value="-1" />
<define name="ACCEL_Y_SIGN" value="1" />
<define name="ACCEL_Z_SIGN" value="1" />
<define name="GYRO_P_SENS_NUM" value="4359" />
<define name="GYRO_P_SENS_DEN" value="1000" />
@@ -90,19 +88,19 @@
<define name="GYRO_R_SENS_DEN" value="1000" />
<define name="GYRO_P_SIGN" value="1" />
<define name="GYRO_Q_SIGN" value="-1" />
<define name="GYRO_R_SIGN" value="-1" />
<define name="GYRO_Q_SIGN" value="1" />
<define name="GYRO_R_SIGN" value="1" />
<define name="MAG_X_NEUTRAL" value="118" />
<define name="MAG_Y_NEUTRAL" value="-65" />
<define name="MAG_Z_NEUTRAL" value="110" />
<define name="MAG_X_SENS" value="14.6416865144" integer="16" />
<define name="MAG_Y_SENS" value="14.5167340835" integer="16" />
<define name="MAG_Z_SENS" value="15.1670335124" integer="16" />
<define name="MAG_X_NEUTRAL" value="-9"/>
<define name="MAG_Y_NEUTRAL" value="1"/>
<define name="MAG_Z_NEUTRAL" value="97"/>
<define name="MAG_X_SENS" value="15.5831909917" integer="16"/>
<define name="MAG_Y_SENS" value="15.518618593" integer="16"/>
<define name="MAG_Z_SENS" value="16.1875786042" integer="16"/>
<define name="MAG_X_SIGN" value="-1" />
<define name="MAG_X_SIGN" value="1" />
<define name="MAG_Y_SIGN" value="1" />
<define name="MAG_Z_SIGN" value="-1" />
<define name="MAG_Z_SIGN" value="1" />
<!-- roll -->
<define name="BODY_TO_IMU_PHI" value="0." unit="deg" />
@@ -232,6 +230,7 @@
</section>
<section name="BAT">
<define name="MILLIAMP_AT_FULL_THROTTLE" value="7500"/>
<define name="CATASTROPHIC_BAT_LEVEL" value="9.3" unit="V" />
<define name="CRITIC_BAT_LEVEL" value="9.6" unit="V" />
<define name="LOW_BAT_LEVEL" value="9.7" unit="V" />
@@ -36,9 +36,35 @@
#include <unistd.h>
#include <math.h>
#include "i2c-dev.h"
#include "subsystems/commands.h"
#include "generated/airframe.h"
struct Electrical electrical;
#if defined ADC_CHANNEL_VSUPPLY || defined ADC_CHANNEL_CURRENT || defined MILLIAMP_AT_FULL_THROTTLE
static struct {
#ifdef ADC_CHANNEL_VSUPPLY
struct adc_buf vsupply_adc_buf;
#endif
#ifdef ADC_CHANNEL_CURRENT
struct adc_buf current_adc_buf;
#endif
#ifdef MILLIAMP_AT_FULL_THROTTLE
float nonlin_factor;
#endif
} electrical_priv;
#endif
#if defined COMMAND_THROTTLE
#define COMMAND_CURRENT_ESTIMATION COMMAND_THROTTLE
#elif defined COMMAND_THRUST
#define COMMAND_CURRENT_ESTIMATION COMMAND_THRUST
#endif
#ifndef CURRENT_ESTIMATION_NONLINEARITY
#define CURRENT_ESTIMATION_NONLINEARITY 1.2
#endif
int fd;
void electrical_init(void) {
@@ -51,6 +77,7 @@ void electrical_init(void) {
}
electrical_setup();
electrical_priv.nonlin_factor = CURRENT_ESTIMATION_NONLINEARITY;
}
void electrical_setup(void) {
@@ -94,4 +121,21 @@ void electrical_periodic(void) {
//9.0V=662, 9.5V=698, 10.0V=737,10.5V=774, 11.0V=811, 11.5V=848, 12.0V=886, 12.5V=923
//leading to our 0.13595166 magic number for decivolts conversion
electrical.vsupply = raw_voltage*0.13595166;
/*
* Superellipse: abs(x/a)^n + abs(y/b)^n = 1
* with a = 1
* b = mA at full throttle
* n = 1.2 This defines nonlinearity (1 = linear)
* x = throttle
* y = current
*
* define CURRENT_ESTIMATION_NONLINEARITY in your airframe file to change the default nonlinearity factor of 1.2
*/
float b = (float)MILLIAMP_AT_FULL_THROTTLE;
float x = ((float)commands[COMMAND_CURRENT_ESTIMATION]) / ((float)MAX_PPRZ);
/* electrical.current y = ( b^n - (b* x/a)^n )^1/n
* a=1, n = electrical_priv.nonlin_factor
*/
electrical.current = b - pow((pow(b,electrical_priv.nonlin_factor)-pow((b*x),electrical_priv.nonlin_factor)), (1./electrical_priv.nonlin_factor));
}
+1 -1
View File
@@ -81,8 +81,8 @@ typedef struct
int32_t pressure;
uint16_t temperature_pressure;
int16_t mx;
int16_t my;
int16_t mx;
int16_t mz;
uint16_t chksum;
@@ -39,9 +39,9 @@ static inline void imu_ardrone2_event ( void (* _gyro_handler)(void), void (* _a
//checks if the navboard has a new dataset ready
if (navdata_imu_available == TRUE) {
navdata_imu_available = FALSE;
RATES_ASSIGN(imu.gyro_unscaled, navdata->vx, navdata->vy, navdata->vz);
VECT3_ASSIGN(imu.accel_unscaled, navdata->ax, navdata->ay, navdata->az);
VECT3_ASSIGN(imu.mag_unscaled, navdata->mx, navdata->my, navdata->mz);
RATES_ASSIGN(imu.gyro_unscaled, navdata->vx, -navdata->vy, -navdata->vz);
VECT3_ASSIGN(imu.accel_unscaled, navdata->ax, 4096-navdata->ay, 4096-navdata->az);
VECT3_ASSIGN(imu.mag_unscaled, -navdata->mx, -navdata->my, -navdata->mz);
_gyro_handler();
_accel_handler();