54 #include "physical_constants.h"
61 #include "attitudeactual.h"
62 #include "attitudesettings.h"
63 #include "baroaltitude.h"
64 #include "flightstatus.h"
65 #include "gpsposition.h"
67 #include "gpsvelocity.h"
69 #include "gyrosbias.h"
70 #include "homelocation.h"
71 #include "sensorsettings.h"
72 #include "inssettings.h"
74 #include "magnetometer.h"
76 #include "nedposition.h"
77 #include "positionactual.h"
78 #include "stateestimation.h"
79 #include "systemalarms.h"
80 #include "velocityactual.h"
83 #define STACK_SIZE_BYTES 2504
84 #define TASK_PRIORITY PIOS_THREAD_PRIO_HIGH
85 #define FAILSAFE_TIMEOUT_MS 10
156 static const float zeros[3] = {0.0f, 0.0f, 0.0f};
192 static int32_t
getNED(GPSPositionData * gpsPosition,
float * NED);
228 if (AttitudeActualInitialize() == -1 \
229 || AttitudeSettingsInitialize() == -1 \
230 || SensorSettingsInitialize() == -1 \
231 || INSSettingsInitialize() == -1 \
232 || INSStateInitialize() == -1 \
233 || NedAccelInitialize() == -1 \
234 || NEDPositionInitialize() == -1 \
235 || PositionActualInitialize() == -1 \
236 || StateEstimationInitialize() == -1 \
237 || VelocityActualInitialize() == -1) {
243 if (HomeLocationInitialize() == -1) {
271 AttitudeActualData attitude;
272 AttitudeActualGet(&attitude);
277 AttitudeActualSet(&attitude);
280 GyrosBiasData gyrosBias;
281 GyrosBiasGet(&gyrosBias);
285 GyrosBiasSet(&gyrosBias);
287 GyrosConnectQueue(gyroQueue);
288 AccelsConnectQueue(accelQueue);
289 if (MagnetometerHandle())
290 MagnetometerConnectQueue(magQueue);
291 if (BaroAltitudeHandle())
292 BaroAltitudeConnectQueue(baroQueue);
293 if (GPSPositionHandle())
294 GPSPositionConnectQueue(gpsQueue);
295 if (GPSVelocityHandle())
296 GPSVelocityConnectQueue(gpsVelQueue);
315 bool first_run =
true;
316 uint32_t last_algorithm;
317 bool last_complementary;
324 last_algorithm = 0xfffffff;
325 last_complementary =
false;
335 int32_t ret_val = -1;
364 SensorSettingsData sensorSettings;
365 SensorSettingsGet(&sensorSettings);
368 GyrosBiasData gyrosBias;
372 GyrosBiasSet(&gyrosBias);
379 FlightStatusArmedGet(&armed);
384 if (armed == FLIGHTSTATUS_ARMED_DISARMED) {
393 T[0] = alt+6.378137E6f;
394 T[1] = cosf(lat)*(alt+6.378137E6f);
415 bool ins = (
stateEstimation.AttitudeFilter == STATEESTIMATION_ATTITUDEFILTER_INSOUTDOOR) ||
416 (
stateEstimation.AttitudeFilter == STATEESTIMATION_ATTITUDEFILTER_INSINDOOR) ||
417 (
stateEstimation.NavigationFilter == STATEESTIMATION_NAVIGATIONFILTER_INS);
420 bool outdoor = (
stateEstimation.AttitudeFilter == STATEESTIMATION_ATTITUDEFILTER_INSOUTDOOR) ||
421 (
stateEstimation.NavigationFilter == STATEESTIMATION_NAVIGATIONFILTER_INS);
424 bool complementary = (
stateEstimation.AttitudeFilter == STATEESTIMATION_ATTITUDEFILTER_COMPLEMENTARY) ||
425 (
stateEstimation.AttitudeFilter == STATEESTIMATION_ATTITUDEFILTER_COMPLEMENTARYVELCOMPASS);
432 first_run || complementary != last_complementary,
435 stateEstimation.AttitudeFilter == STATEESTIMATION_ATTITUDEFILTER_COMPLEMENTARYVELCOMPASS);
441 stateEstimation.NavigationFilter == STATEESTIMATION_NAVIGATIONFILTER_RAW,
442 stateEstimation.AttitudeFilter == STATEESTIMATION_ATTITUDEFILTER_COMPLEMENTARYVELCOMPASS);
445 last_complementary = complementary;
450 case STATEESTIMATION_ATTITUDEFILTER_COMPLEMENTARY:
451 case STATEESTIMATION_ATTITUDEFILTER_COMPLEMENTARYVELCOMPASS:
454 case STATEESTIMATION_ATTITUDEFILTER_INSOUTDOOR:
455 case STATEESTIMATION_ATTITUDEFILTER_INSINDOOR:
462 case STATEESTIMATION_NAVIGATIONFILTER_INS:
467 case STATEESTIMATION_NAVIGATIONFILTER_RAW:
470 case STATEESTIMATION_NAVIGATIONFILTER_NONE:
506 if (gyroTimeout || accelTimeout) {
508 if (!AttitudeActualReadOnly()) {
511 else if (accelTimeout)
519 AccelsGet(&accelsData);
523 MagnetometerData magData;
533 MagnetometerGet(&magData);
551 float theta = atan2f(accelsData.x, -accelsData.z);
552 RPY_D[1] = theta * RAD2DEG;
553 RPY_D[0] = atan2f(-accelsData.y, -accelsData.z / cosf(theta)) * RAD2DEG;
556 float RPY_R[3] = {RPY_D[0] * DEG2RAD, RPY_D[1] * DEG2RAD, 0};
558 float mag_body_frame[3] = {magData.x, magData.y, magData.z};
559 float mag_earth_frame[3];
561 rot_mult(Rbe, mag_body_frame, mag_earth_frame,
true);
564 RPY_D[2] = atan2f(-mag_earth_frame[1], mag_earth_frame[0]) * RAD2DEG;
575 BaroAltitudeAltitudeGet(&baro);
581 FlightStatusData flightStatus;
582 FlightStatusGet(&flightStatus);
593 (ms_since_reset > 1000) ?
597 (ms_since_reset < 7000) &&
598 (ms_since_reset > 1000)) {
605 }
else if ((
attitudeSettings.ZeroDuringArming == ATTITUDESETTINGS_ZERODURINGARMING_TRUE) &&
606 (flightStatus.Armed == FLIGHTSTATUS_ARMED_ARMING)) {
634 BaroAltitudeAltitudeGet(&baro);
656 BaroAltitudeAltitudeGet(&baro);
660 GyrosGet(&gyrosData);
680 CrossProduct((
const float *) accels_filtered, (
const float *) grot_filtered, accel_err);
684 grot_mag = sqrtf(grot_filtered[0]*grot_filtered[0] + grot_filtered[1]*grot_filtered[1] + grot_filtered[2]*grot_filtered[2]);
690 accel_mag = accels_filtered[0]*accels_filtered[0] + accels_filtered[1]*accels_filtered[1] + accels_filtered[2]*accels_filtered[2];
691 accel_mag = sqrtf(accel_mag);
692 if (grot_mag > 1.0e-3
f && accel_mag > 1.0e-3
f) {
693 accel_err[0] /= (accel_mag * grot_mag);
694 accel_err[1] /= (accel_mag * grot_mag);
695 accel_err[2] /= (accel_mag * grot_mag);
704 MagnetometerData
mag;
705 MagnetometerGet(&mag);
719 bmag = sqrtf(brot[0] * brot[0] + brot[1] * brot[1] + brot[2] * brot[2]);
724 const float Be[3] = {1.0f, 0.0f, 0.0f};
728 float mag_len = sqrtf(mag.x * mag.x + mag.y * mag.y + mag.z * mag.z);
734 if (bmag < 1 || mag_len < 1)
735 mag_err[0] = mag_err[1] = mag_err[2] = 0;
737 CrossProduct((
const float *) &mag.x, (
const float *) brot, mag_err);
739 if (mag_err[2] != mag_err[2])
744 }
else if (vel_compass) {
745 GPSPositionData GpsPosition;
746 GPSPositionGet(&GpsPosition);
748 if ((GpsPosition.Status == GPSPOSITION_STATUS_FIX3D) &&
749 (GpsPosition.Groundspeed > 3.0f)) {
770 GyrosBiasData gyrosBias;
771 GyrosBiasGet(&gyrosBias);
772 gyrosBias.x -= accel_err[0] * accKi * dT;
773 gyrosBias.y -= accel_err[1] * accKi * dT;
774 gyrosBias.z -= mag_err[2] * mgKi * dT;
775 GyrosBiasSet(&gyrosBias);
778 gyrosData.x += accel_err[0] * accKp;
779 gyrosData.y += accel_err[1] * accKp;
780 gyrosData.z += accel_err[2] * accKp + mag_err[2] * mgKp;
785 qdot[0] = (-
cf_q[1] * gyrosData.x -
cf_q[2] * gyrosData.y -
cf_q[3] * gyrosData.z) * dT * DEG2RAD / 2;
786 qdot[1] = (
cf_q[0] * gyrosData.x -
cf_q[3] * gyrosData.y +
cf_q[2] * gyrosData.z) * dT * DEG2RAD / 2;
787 qdot[2] = (
cf_q[3] * gyrosData.x +
cf_q[0] * gyrosData.y -
cf_q[1] * gyrosData.z) * dT * DEG2RAD / 2;
788 qdot[3] = (-
cf_q[2] * gyrosData.x +
cf_q[1] * gyrosData.y +
cf_q[0] * gyrosData.z) * dT * DEG2RAD / 2;
806 cf_q[0] = cf_q[0] / qmag;
807 cf_q[1] = cf_q[1] / qmag;
808 cf_q[2] = cf_q[2] / qmag;
809 cf_q[3] = cf_q[3] / qmag;
821 static bool got_baro_pt =
false;
830 BaroAltitudeAltitudeGet(&baro);
836 }
else if (!got_baro_pt) {
845 if (!secondary && !raw_gps) {
867 rot_mult(Rbe, accels, accel_ned,
true);
868 accel_ned[2] += GRAVITY;
870 NedAccelData nedAccel;
871 nedAccel.North = accel_ned[0];
872 nedAccel.East = accel_ned[1];
873 nedAccel.Down = accel_ned[2];
874 NedAccelSet(&nedAccel);
903 float velocity_increase;
932 GPSPositionData gpsPosition;
933 GPSPositionGet(&gpsPosition);
935 if (gpsPosition.Satellites < 6)
937 else if (gpsPosition.PDOP > 4.0f)
942 getNED(&gpsPosition, NED);
944 NEDPositionData nedPosition;
945 nedPosition.North = NED[0];
946 nedPosition.East = NED[1];
947 nedPosition.Down = NED[2];
948 NEDPositionSet(&nedPosition);
950 PositionActualData positionActual;
951 positionActual.North = NED[0];
952 positionActual.East = NED[1];
954 PositionActualSet(&positionActual);
961 GPSVelocityData gpsVelocity;
962 GPSVelocityGet(&gpsVelocity);
964 VelocityActualData velocityActual;
965 velocityActual.North = gpsVelocity.North;
966 velocityActual.East = gpsVelocity.East;
968 VelocityActualSet(&velocityActual);
991 AttitudeActualData attitude;
994 AttitudeActualSet(&attitude);
1009 GyrosBiasData gyrosBias;
1013 GyrosBiasSet(&gyrosBias);
1047 GyrosBiasData gyrosBias;
1048 GyrosBiasGet(&gyrosBias);
1069 GyrosData gyrosData;
1071 MagnetometerData magData;
1072 GPSVelocityData gpsVelData;
1073 GyrosBiasData gyrosBias;
1076 static BaroAltitudeData baroData;
1077 static GPSPositionData gpsData;
1079 static bool mag_updated =
false;
1080 static bool baro_updated;
1081 static bool gps_updated;
1082 static bool gps_vel_updated;
1084 static float baro_offset = 0;
1086 static uint32_t ins_last_time = 0;
1087 static uint32_t ins_init_time = 0;
1089 static enum {INS_INIT, INS_WARMUP, INS_RUNNING} ins_state;
1091 float NED[3] = {0.0f, 0.0f, 0.0f};
1092 float vel[3] = {0.0f, 0.0f, 0.0f};
1102 ins_state = INS_INIT;
1104 mag_updated =
false;
1105 baro_updated =
false;
1106 gps_updated =
false;
1107 gps_vel_updated =
false;
1119 gps_vel_updated = gps_vel_updated || (
PIOS_Queue_Receive(gpsVelQueue, &ev, 0) && outdoor_mode);
1129 GyrosGet(&gyrosData);
1130 AccelsGet(&accelsData);
1131 GyrosBiasGet(&gyrosBias);
1135 BaroAltitudeGet(&baroData);
1138 MagnetometerGet(&magData);
1141 GPSPositionGet(&gpsData);
1143 if (gps_vel_updated)
1144 GPSVelocityGet(&gpsVelData);
1154 bool gps_init_usable = gps_updated && (gpsData.Satellites >= 7) && (gpsData.PDOP <= 3.5f) && (
homeLocation.Set == HOMELOCATION_SET_TRUE);
1157 if (ins_state == INS_INIT) {
1158 if (!gps_init_usable && outdoor_mode)
1160 else if (!mag_updated)
1162 else if (!baro_updated)
1167 }
else if (outdoor_mode && (gpsData.Satellites < 6 || gpsData.PDOP > 4.0f)) {
1168 if (gpsData.Satellites < 6)
1170 else if (gpsData.PDOP > 4.0f)
1180 if (ins_state == INS_INIT &&
1181 mag_updated && baro_updated &&
1182 (gps_init_usable || !outdoor_mode)) {
1194 float gyro_bias[3] = {gyrosBias.x * DEG2RAD, gyrosBias.y * DEG2RAD, gyrosBias.z * DEG2RAD};
1198 BaroAltitudeGet(&baroData);
1201 RPY[0] = atan2f(-accelsData.y, -accelsData.z) * RAD2DEG;
1202 RPY[1] = atan2f(accelsData.x, -accelsData.z) * RAD2DEG;
1203 RPY[2] = atan2f(-magData.y, magData.x) * RAD2DEG;
1207 if (!outdoor_mode) {
1208 float pos[3] = {0.0f, 0.0f, 0.0f};
1211 baro_offset = -baroData.Altitude;
1212 pos[2] = -(baroData.Altitude + baro_offset);
1220 float Be[3] = {100,0,500};
1231 float gyro_bias[3] = {gyrosBias.x * DEG2RAD, gyrosBias.y * DEG2RAD, gyrosBias.z * DEG2RAD};
1238 baro_offset = -baroData.Altitude;
1245 ins_state = INS_WARMUP;
1248 ins_init_time = ins_last_time;
1251 }
else if (ins_state == INS_INIT)
1256 ins_state = INS_RUNNING;
1260 FlightStatusArmedGet(&armed);
1265 gps_updated &= (gpsData.Satellites >= 6) && (gpsData.PDOP <= 4.0f) && (
homeLocation.Set == HOMELOCATION_SET_TRUE);
1273 else if(dT <= 0.0005
f)
1288 if (
attitudeSettings.BiasCorrectGyro == ATTITUDESETTINGS_BIASCORRECTGYRO_TRUE) {
1289 gyros[0] = (gyrosData.x + gyrosBias.x) * DEG2RAD;
1290 gyros[1] = (gyrosData.y + gyrosBias.y) * DEG2RAD;
1291 gyros[2] = (gyrosData.z + gyrosBias.z) * DEG2RAD;
1293 gyros[0] = gyrosData.x * DEG2RAD;
1294 gyros[1] = gyrosData.y * DEG2RAD;
1295 gyros[2] = gyrosData.z * DEG2RAD;
1306 mag_updated =
false;
1311 baro_updated =
false;
1322 NEDPositionData nedPos;
1323 nedPos.North = NED[0];
1324 nedPos.East = NED[1];
1325 nedPos.Down = NED[2];
1326 NEDPositionSet(&nedPos);
1328 gps_updated =
false;
1332 if (gps_vel_updated) {
1335 vel[0] = gpsVelData.North;
1336 vel[1] = gpsVelData.East;
1337 vel[2] = gpsVelData.Down;
1339 gps_vel_updated =
false;
1343 if (gps_updated || gps_vel_updated) {
1351 float pos_var =
insSettings.GpsVar[INSSETTINGS_GPSVAR_POS] *
1352 (0.6f + powf(gpsData.Accuracy * 0.180f, 2));
1356 float speed_var =
insSettings.GpsVar[INSSETTINGS_GPSVAR_VEL] *
1357 (0.5f + powf(gpsVelData.Accuracy * 1.414f, 2));
1359 float v_pos_var =
insSettings.GpsVar[INSSETTINGS_GPSVAR_VERTPOS] +
1360 (0.7f + powf(gpsData.Accuracy * 0.167f, 3.0));
1369 static uint32_t indoor_pos_time;
1374 vel[0] = vel[1] = vel[2] = 0;
1375 NED[0] = NED[1] = 0;
1376 NED[2] = -(baroData.Altitude + baro_offset);
1384 INSCorrection(&magData.x, NED, vel, ( baroData.Altitude + baro_offset ), sensors);
1389 INSGetState(&state.State[0], &state.State[3], &state.State[6], &state.State[10], &state.State[13]);
1390 INSStateSet(&state);
1392 if (
insSettings.ComputeGyroBias == INSSETTINGS_COMPUTEGYROBIAS_FALSE)
1395 float accel_bias_corrected[3] = {accelsData.x - state.State[13], accelsData.y - state.State[14], accelsData.z - state.State[15]};
1405 AttitudeActualData attitude;
1407 INSGetState(NULL, NULL, &attitude.q1, gyro_bias, NULL);
1409 AttitudeActualSet(&attitude);
1411 if (
insSettings.ComputeGyroBias == INSSETTINGS_COMPUTEGYROBIAS_TRUE &&
1416 GyrosBiasData gyrosBias;
1417 gyrosBias.x = gyro_bias[0] * RAD2DEG;
1418 gyrosBias.y = gyro_bias[1] * RAD2DEG;
1419 gyrosBias.z = gyro_bias[2] * RAD2DEG;
1420 GyrosBiasSet(&gyrosBias);
1429 PositionActualData positionActual;
1430 VelocityActualData velocityActual;
1432 INSGetState(&positionActual.North, &velocityActual.North, NULL, NULL, NULL);
1434 PositionActualSet(&positionActual);
1435 VelocityActualSet(&velocityActual);
1444 filtered[0] = filtered[0] * alpha + raw[0] * (1 - alpha);
1445 filtered[1] = filtered[1] * alpha + raw[1] * (1 - alpha);
1446 filtered[2] = filtered[2] * alpha + raw[2] * (1 - alpha);
1448 filtered[0] = raw[0];
1449 filtered[1] = raw[1];
1450 filtered[2] = raw[2];
1463 static int32_t
getNED(GPSPositionData * gpsPosition,
float * NED)
1465 float dL[3] = {(gpsPosition->Latitude -
homeLocation.Latitude) / 10.0e6f * DEG2RAD,
1466 (gpsPosition->Longitude -
homeLocation.Longitude) / 10.0e6f * DEG2RAD,
1469 NED[0] =
T[0] * dL[0];
1470 NED[1] =
T[1] * dL[1];
1471 NED[2] =
T[2] * dL[2];
1485 const float TAU = 0.95f;
1490 accel[0] = accels.x;
1491 accel[1] = accels.y;
1492 accel[2] = accels.z;
1495 AttitudeActualData attitudeActual;
1496 AttitudeActualGet(&attitudeActual);
1497 q[0]=attitudeActual.q1;
1498 q[1]=attitudeActual.q2;
1499 q[2]=attitudeActual.q3;
1500 q[3]=attitudeActual.q4;
1502 for (uint8_t
i = 0;
i < 3;
i++) {
1504 for (uint8_t
j = 0;
j < 3;
j++)
1505 accel_ned[
i] += Rbe[
j][
i] * accel[
j];
1507 accel_ned[2] += GRAVITY;
1509 NedAccelData accelData;
1512 NedAccelGet(&accelData);
1513 accelData.North = accelData.North * TAU + accel_ned[0] * (1 - TAU);
1514 accelData.East = accelData.East * TAU + accel_ned[1] * (1 - TAU);
1515 accelData.Down = accelData.Down * TAU + accel_ned[2] * (1 - TAU);
1516 NedAccelSet(&accelData);
1526 FlightStatusArmedGet(&armed);
1527 if (armed != FLIGHTSTATUS_ARMED_DISARMED)
1534 GPSPositionData
gps;
1535 GPSPositionGet(&gps);
1536 GPSTimeData gpsTime;
1537 GPSTimeGet(&gpsTime);
1540 if (gps.PDOP < 3.5f &&
1541 gps.Satellites >= 7 &&
1542 (gps.Status == GPSPOSITION_STATUS_FIX3D ||
1543 gps.Status == GPSPOSITION_STATUS_DIFF3D) &&
1544 gpsTime.Year >= 2000)
1574 SystemAlarmsAlarmOptions severity;
1575 switch (error_code) {
1576 case SYSTEMALARMS_STATEESTIMATION_NONE:
1577 severity = SYSTEMALARMS_ALARM_OK;
1579 case SYSTEMALARMS_STATEESTIMATION_ACCELEROMETERQUEUENOTUPDATING:
1580 case SYSTEMALARMS_STATEESTIMATION_GYROQUEUENOTUPDATING:
1581 severity = SYSTEMALARMS_ALARM_WARNING;
1583 case SYSTEMALARMS_STATEESTIMATION_NOGPS:
1584 case SYSTEMALARMS_STATEESTIMATION_NOMAGNETOMETER:
1585 case SYSTEMALARMS_STATEESTIMATION_NOBAROMETER:
1586 case SYSTEMALARMS_STATEESTIMATION_NOHOME:
1587 case SYSTEMALARMS_STATEESTIMATION_TOOFEWSATELLITES:
1588 case SYSTEMALARMS_STATEESTIMATION_PDOPTOOHIGH:
1589 severity = SYSTEMALARMS_ALARM_ERROR;
1591 case SYSTEMALARMS_STATEESTIMATION_UNDEFINED:
1593 severity = SYSTEMALARMS_ALARM_CRITICAL;
1594 error_code = SYSTEMALARMS_STATEESTIMATION_UNDEFINED;
1599 SystemAlarmsStateEstimationOptions current_error_code;
1600 SystemAlarmsStateEstimationGet((uint8_t *) ¤t_error_code);
1601 if (current_error_code != error_code) {
1602 SystemAlarmsStateEstimationSet((uint8_t *) &error_code);
1606 AlarmsSet(SYSTEMALARMS_ALARM_ATTITUDE, (uint8_t) severity);
uint32_t arming_count
Track how many cycles the system has been arming to accelerate convergence.
void rot_mult(float R[3][3], const float vec[3], float vec_out[3], bool transpose)
Rotate a vector by a rotation matrix.
void INSGetState(float *pos, float *vel, float *attitude, float *gyro_bias, float *accel_bias)
Get the current state estimate.
uint32_t PIOS_Thread_Systime(void)
static AccelsData accelsData
uint32_t PIOS_DELAY_DiffuS(uint32_t raw)
Subtract raw time from now and convert to us.
#define PIOS_WDG_ATTITUDE
struct pios_queue * PIOS_Queue_Create(size_t queue_length, size_t item_size)
Main PiOS header to include all the compiled in PiOS options.
void Quaternion2R(float q[4], float Rbe[3][3])
static float calc_ned_accel(float *q, float *accels)
static volatile bool homeloc_flag
void RPY2Quaternion(const float rpy[3], float q[4])
Include file of the INSGPS exposed functionality.
void quat_copy(const float q[4], float qnew[4])
Duplicate a quaternion.
void INSSetAccelBias(const float gyro_bias[3])
static struct GPSGlobals * gps
static void check_home_location()
Determine if it is safe to set the home location then do it.
float position_correction_z
static struct pios_queue * gyroQueue
bool PIOS_WDG_RegisterFlag(uint16_t flag_requested)
Register a module against the watchdog.
float grot_filtered[3]
Low pass filtered gravity vector.
void INSGetVariance(float *p)
#define HORIZ_VEL_SENSORS
int32_t AttitudeStart(void)
bool PIOS_WDG_UpdateFlag(uint16_t flag)
Function called by modules to indicate they are still running.
int32_t AttitudeInitialize(void)
static StateEstimationData stateEstimation
void INSSetMagVar(const float scaled_mag_var[3])
void UAVObjCbSetFlag(const UAVObjEvent *objEv, void *ctx, void *obj, int len)
int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity)
static struct pios_thread * attitudeTaskHandle
void INSSetPosVelVar(float PosVar, float VelVar, float VertPosVar)
bool PIOS_Queue_Receive(struct pios_queue *queuep, void *itemp, uint32_t timeout_ms)
enum complementary_filter_status initialization
Tracks the initialization state of the complementary filter.
static INSSettingsData insSettings
complementary_filter_status
void INSSetGyroBias(const float gyro_bias[3])
uint32_t PIOS_SENSORS_GetSampleRate(enum pios_sensor_type type)
Get the sample rate of a sensor (Hz)
static void updateNedAccel()
static void accumulate_gyro_zero()
Zero the gyro accumulators.
static float T[3]
Scales used in NED transform (local tangent plane approx).
static int32_t setNavigationRaw()
Set the navigation information to the raw estimates.
static int32_t setAttitudeINSGPS()
Set the attitude to the current INSGPS estimate.
bool accumulating_gyro
Indicate if currently acquiring gyro samples.
static volatile bool settings_flag
static void AttitudeTask(void *parameters)
static void accumulate_gyro_compute()
Compute the mean gyro accumulated and assign the bias.
#define HORIZ_POS_SENSORS
static int32_t updateAttitudeComplementary(float dT, bool first_run, bool secondary, bool raw_gps, bool vel_compass)
Update the complementary filter attitude estimate.
#define MODULE_HIPRI_INITCALL(ifn, sfn)
void INSStatePrediction(const float gyro_data[3], const float accel_data[3], float dT)
Compute an update of the state estimate.
static bool gyroBiasSettingsUpdated
static int32_t getNED(GPSPositionData *gpsPosition, float *NED)
Convert the GPS LLA position into NED coordinates.
float circular_modulus_deg(float err)
Circular modulus.
bool PIOS_SENSORS_IsRegistered(enum pios_sensor_type type)
Checks if a sensor type is registered with the PIOS_SENSORS interface.
static AttitudeSettingsData attitudeSettings
void INSSetMagNorth(const float B[3])
static float cf_q[4]
The complementary filter attitude estimate.
Source file for the World Magnetic Model.
void INSSetBaroVar(float baro_var)
static struct PIOS_Sensor sensors[PIOS_SENSOR_NUM]
static struct pios_queue * magQueue
struct pios_thread * PIOS_Thread_Create(void(*fp)(void *), const char *namep, size_t stack_bytes, void *argp, enum pios_thread_prio_e prio)
uint32_t reset_timeval
Store when the function is initialized to time arming and convergence.
uint32_t accumulated_gyro_samples
How many gyro samples were acquired.
bool accel_filter_enabled
If the accelerometer LPF is enabled.
static void cfvert_update_baro(struct cfvert *cf, float baro, float dt)
Update the baro feedback.
static struct pios_queue * gpsVelQueue
int32_t TaskMonitorAdd(TaskInfoRunningElem task, struct pios_thread *threadp)
static HomeLocationData homeLocation
void INSSetState(const float pos[3], const float vel[3], const float q[4], const float gyro_bias[3], const float accel_bias[3])
static int32_t setNavigationNone()
Provide no navigation updates (indoor flying or without gps)
static void cfvert_predict_pos(struct cfvert *cf, float z_accel, float dt)
Predict the position in the future.
void INSGPSInit()
Reset the internal state variables and variances.
static void accumulate_gyro(GyrosData *gyrosData)
Store a gyro sample.
float accel_alpha
Coefficient for the accelerometer LPF.
void INSCorrection(const float mag_data[3], const float Pos[3], const float Vel[3], float BaroAlt, uint16_t SensorsUsed)
Correct the state and covariance estimate based on the sensors that were updated. ...
void INSSetArmed(bool armed)
Set the current flight state.
void Euler2R(float rpy[3], float Rbe[3][3])
void PIOS_Thread_Sleep(uint32_t time_ms)
Header for Coordinate conversions library in coordinate_conversions.c.
static int32_t updateAttitudeINSGPS(bool first_run, bool outdoor_mode)
Update the INSGPS attitude estimate.
void CrossProduct(const float v1[3], const float v2[3], float result[3])
void INSCovariancePrediction(float dT)
Compute an update of the state covariance.
static struct pios_queue * accelQueue
static volatile bool sensors_flag
Includes PiOS and core architecture components.
static void cfvert_reset(struct cfvert *cf, float baro, float time_constant)
Resets the vertical baro complementary filter and zeros the altitude.
void INSSetGyroVar(const float gyro_var[3])
static const float zeros[3]
static void set_state_estimation_error(SystemAlarmsStateEstimationOptions error_code)
Set alarm and alarm code.
static struct pios_queue * baroQueue
void INSSetAccelVar(const float accel_var[3])
static int32_t setAttitudeComplementary()
Set the AttitudeActual to the complementary filter estimate.
float accels_filtered[3]
Store the low pass filtered accelerometer.
static void apply_accel_filter(const float *raw, float *filtered)
A low pass filter on the accels which helps with vibration resistance.
static int32_t setNavigationINSGPS()
Set the navigation to the current INSGPS estimate.
void Quaternion2RPY(const float q[4], float rpy[3])
int WMM_GetMagVector(float Lat, float Lon, float AltEllipsoid, uint16_t Month, uint16_t Day, uint16_t Year, float B[3])
Struture that tracks the data for the vertical complementary filter.
static struct pios_queue * gpsQueue
#define FAILSAFE_TIMEOUT_MS
static bool home_location_updated
float accumulated_gyro[3]
The accumulator of gyros during arming.
static bool IS_NOT_FINITE(float x)
uint32_t PIOS_DELAY_GetRaw()
Get the raw delay timer, useful for timing.