2013-12-29 07:56:30 -04:00
|
|
|
/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
/*
|
|
|
|
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
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <AP_Common.h>
|
|
|
|
#include <AP_Progmem.h>
|
|
|
|
#include <AP_Param.h>
|
2014-08-13 02:09:34 -03:00
|
|
|
#include <StorageManager.h>
|
2013-12-29 07:56:30 -04:00
|
|
|
#include <AP_Math.h>
|
|
|
|
#include <AP_HAL.h>
|
|
|
|
#include <AP_HAL_AVR.h>
|
|
|
|
#include <AP_HAL_AVR_SITL.h>
|
|
|
|
#include <AP_HAL_Linux.h>
|
|
|
|
#include <AP_HAL_Empty.h>
|
|
|
|
#include <AP_ADC.h>
|
|
|
|
#include <AP_Declination.h>
|
|
|
|
#include <AP_ADC_AnalogSource.h>
|
|
|
|
#include <Filter.h>
|
|
|
|
#include <AP_Buffer.h>
|
|
|
|
#include <AP_Airspeed.h>
|
|
|
|
#include <AP_Vehicle.h>
|
|
|
|
#include <AP_Notify.h>
|
|
|
|
#include <DataFlash.h>
|
|
|
|
#include <GCS_MAVLink.h>
|
|
|
|
#include <AP_GPS.h>
|
2014-01-05 01:37:47 -04:00
|
|
|
#include <AP_GPS_Glitch.h>
|
2013-12-29 07:56:30 -04:00
|
|
|
#include <AP_AHRS.h>
|
|
|
|
#include <SITL.h>
|
|
|
|
#include <AP_Compass.h>
|
|
|
|
#include <AP_Baro.h>
|
2014-07-29 03:25:50 -03:00
|
|
|
#include <AP_Baro_Glitch.h>
|
2013-12-29 07:56:30 -04:00
|
|
|
#include <AP_InertialSensor.h>
|
2014-01-04 20:39:43 -04:00
|
|
|
#include <AP_InertialNav.h>
|
2013-12-29 07:56:30 -04:00
|
|
|
#include <AP_NavEKF.h>
|
2014-03-19 07:01:48 -03:00
|
|
|
#include <AP_Mission.h>
|
2014-08-06 09:27:50 -03:00
|
|
|
#include <AP_Rally.h>
|
2014-08-10 08:25:16 -03:00
|
|
|
#include <AP_BattMonitor.h>
|
2014-07-25 04:15:29 -03:00
|
|
|
#include <AP_Terrain.h>
|
2014-03-01 00:15:46 -04:00
|
|
|
#include <Parameters.h>
|
2013-12-29 07:56:30 -04:00
|
|
|
#include <stdio.h>
|
2014-02-26 04:34:01 -04:00
|
|
|
#include <getopt.h>
|
2014-02-28 23:24:51 -04:00
|
|
|
#include <errno.h>
|
2014-04-21 02:22:42 -03:00
|
|
|
#include <fenv.h>
|
2013-12-29 07:56:30 -04:00
|
|
|
|
2014-05-13 06:10:24 -03:00
|
|
|
#ifndef INT16_MIN
|
2014-05-01 04:54:31 -03:00
|
|
|
#define INT16_MIN -32768
|
|
|
|
#define INT16_MAX 32767
|
2014-05-13 06:10:24 -03:00
|
|
|
#endif
|
2014-05-01 04:54:31 -03:00
|
|
|
|
2013-12-29 07:56:30 -04:00
|
|
|
#include "LogReader.h"
|
|
|
|
|
|
|
|
const AP_HAL::HAL& hal = AP_HAL_BOARD_DRIVER;
|
|
|
|
|
2014-03-01 00:15:46 -04:00
|
|
|
static Parameters g;
|
|
|
|
|
2013-12-29 07:56:30 -04:00
|
|
|
static AP_InertialSensor_HIL ins;
|
|
|
|
static AP_Baro_HIL barometer;
|
2014-03-31 04:46:01 -03:00
|
|
|
static AP_GPS gps;
|
2013-12-29 07:56:30 -04:00
|
|
|
static AP_Compass_HIL compass;
|
2014-03-31 04:46:01 -03:00
|
|
|
static AP_AHRS_NavEKF ahrs(ins, barometer, gps);
|
|
|
|
static GPS_Glitch gps_glitch(gps);
|
2014-07-29 03:25:50 -03:00
|
|
|
static Baro_Glitch baro_glitch(barometer);
|
|
|
|
static AP_InertialNav inertial_nav(ahrs, barometer, gps_glitch, baro_glitch);
|
2014-02-17 18:11:46 -04:00
|
|
|
static AP_Vehicle::FixedWing aparm;
|
|
|
|
static AP_Airspeed airspeed(aparm);
|
2013-12-29 07:56:30 -04:00
|
|
|
|
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_AVR_SITL
|
|
|
|
SITL sitl;
|
|
|
|
#endif
|
|
|
|
|
2014-01-04 20:39:43 -04:00
|
|
|
static const NavEKF &NavEKF = ahrs.get_NavEKF();
|
|
|
|
|
2014-04-21 05:11:20 -03:00
|
|
|
static LogReader LogReader(ahrs, ins, barometer, compass, gps, airspeed);
|
2013-12-29 07:56:30 -04:00
|
|
|
|
2013-12-29 18:47:50 -04:00
|
|
|
static FILE *plotf;
|
2014-01-03 00:38:08 -04:00
|
|
|
static FILE *plotf2;
|
2014-01-30 18:27:56 -04:00
|
|
|
static FILE *ekf1f;
|
|
|
|
static FILE *ekf2f;
|
|
|
|
static FILE *ekf3f;
|
|
|
|
static FILE *ekf4f;
|
2013-12-29 18:47:50 -04:00
|
|
|
|
2014-03-01 00:15:46 -04:00
|
|
|
static bool done_parameters;
|
2014-01-05 02:22:05 -04:00
|
|
|
static bool done_baro_init;
|
|
|
|
static bool done_home_init;
|
2014-04-21 02:22:42 -03:00
|
|
|
static uint16_t update_rate = 50;
|
2014-04-21 00:00:59 -03:00
|
|
|
static uint32_t arm_time_ms;
|
2014-01-04 20:39:43 -04:00
|
|
|
|
2014-03-01 00:15:46 -04:00
|
|
|
static uint8_t num_user_parameters;
|
|
|
|
static struct {
|
|
|
|
char name[17];
|
|
|
|
float value;
|
|
|
|
} user_parameters[100];
|
|
|
|
|
|
|
|
|
|
|
|
static void usage(void)
|
|
|
|
{
|
|
|
|
::printf("Options:\n");
|
|
|
|
::printf(" -rRATE set IMU rate in Hz\n");
|
|
|
|
::printf(" -pNAME=VALUE set parameter NAME to VALUE\n");
|
2014-03-01 17:00:13 -04:00
|
|
|
::printf(" -aMASK set accel mask (1=accel1 only, 2=accel2 only, 3=both)\n");
|
|
|
|
::printf(" -gMASK set gyro mask (1=gyro1 only, 2=gyro2 only, 3=both)\n");
|
2014-04-21 00:00:59 -03:00
|
|
|
::printf(" -A time arm at time milliseconds)\n");
|
2014-03-01 00:15:46 -04:00
|
|
|
}
|
|
|
|
|
2013-12-29 07:56:30 -04:00
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
::printf("Starting\n");
|
2014-01-04 20:39:43 -04:00
|
|
|
|
2014-02-22 17:17:01 -04:00
|
|
|
const char *filename = "log.bin";
|
|
|
|
uint8_t argc;
|
|
|
|
char * const *argv;
|
2014-02-26 04:34:01 -04:00
|
|
|
int opt;
|
|
|
|
|
2014-02-22 17:17:01 -04:00
|
|
|
hal.util->commandline_arguments(argc, argv);
|
2014-02-26 04:34:01 -04:00
|
|
|
|
2014-04-21 00:00:59 -03:00
|
|
|
while ((opt = getopt(argc, argv, "r:p:ha:g:A:")) != -1) {
|
2014-02-26 04:34:01 -04:00
|
|
|
switch (opt) {
|
2014-03-01 00:15:46 -04:00
|
|
|
case 'h':
|
|
|
|
usage();
|
|
|
|
exit(0);
|
2014-03-01 17:00:13 -04:00
|
|
|
|
2014-02-26 04:34:01 -04:00
|
|
|
case 'r':
|
|
|
|
update_rate = strtol(optarg, NULL, 0);
|
|
|
|
break;
|
2014-03-01 00:15:46 -04:00
|
|
|
|
2014-03-01 17:00:13 -04:00
|
|
|
case 'g':
|
|
|
|
LogReader.set_gyro_mask(strtol(optarg, NULL, 0));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'a':
|
|
|
|
LogReader.set_accel_mask(strtol(optarg, NULL, 0));
|
|
|
|
break;
|
|
|
|
|
2014-04-21 00:00:59 -03:00
|
|
|
case 'A':
|
|
|
|
arm_time_ms = strtoul(optarg, NULL, 0);
|
|
|
|
break;
|
|
|
|
|
2014-03-01 00:15:46 -04:00
|
|
|
case 'p':
|
|
|
|
char *eq = strchr(optarg, '=');
|
|
|
|
if (eq == NULL) {
|
|
|
|
::printf("Usage: -p NAME=VALUE\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
*eq++ = 0;
|
|
|
|
strncpy(user_parameters[num_user_parameters].name, optarg, 16);
|
|
|
|
user_parameters[num_user_parameters].value = atof(eq);
|
|
|
|
num_user_parameters++;
|
|
|
|
if (num_user_parameters >= sizeof(user_parameters)/sizeof(user_parameters[0])) {
|
|
|
|
::printf("Too many user parameters\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
2014-02-26 04:34:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argv += optind;
|
|
|
|
argc -= optind;
|
|
|
|
|
|
|
|
if (argc > 0) {
|
|
|
|
filename = argv[0];
|
2014-02-22 17:17:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
hal.console->printf("Processing log %s\n", filename);
|
2014-02-26 04:34:01 -04:00
|
|
|
if (update_rate != 0) {
|
|
|
|
hal.console->printf("Using an update rate of %u Hz\n", update_rate);
|
|
|
|
}
|
2014-02-28 23:24:51 -04:00
|
|
|
|
2014-03-01 00:15:46 -04:00
|
|
|
load_parameters();
|
|
|
|
|
2014-02-28 23:24:51 -04:00
|
|
|
if (!LogReader.open_log(filename)) {
|
|
|
|
perror(filename);
|
|
|
|
exit(1);
|
|
|
|
}
|
2013-12-29 07:56:30 -04:00
|
|
|
|
|
|
|
LogReader.wait_type(LOG_GPS_MSG);
|
|
|
|
LogReader.wait_type(LOG_IMU_MSG);
|
|
|
|
LogReader.wait_type(LOG_GPS_MSG);
|
|
|
|
LogReader.wait_type(LOG_IMU_MSG);
|
|
|
|
|
2014-04-21 02:22:42 -03:00
|
|
|
feenableexcept(FE_INVALID | FE_OVERFLOW);
|
|
|
|
|
2013-12-29 07:56:30 -04:00
|
|
|
ahrs.set_compass(&compass);
|
2013-12-29 18:32:20 -04:00
|
|
|
ahrs.set_fly_forward(true);
|
|
|
|
ahrs.set_wind_estimation(true);
|
2014-02-17 18:11:46 -04:00
|
|
|
ahrs.set_correct_centrifugal(true);
|
2014-04-21 00:00:59 -03:00
|
|
|
|
|
|
|
if (arm_time_ms != 0) {
|
|
|
|
ahrs.set_armed(false);
|
|
|
|
}
|
|
|
|
|
2013-12-29 07:56:30 -04:00
|
|
|
barometer.init();
|
2014-01-05 01:37:47 -04:00
|
|
|
barometer.setHIL(0);
|
|
|
|
barometer.read();
|
2013-12-29 07:56:30 -04:00
|
|
|
compass.init();
|
2014-01-05 01:37:47 -04:00
|
|
|
inertial_nav.init();
|
2014-02-26 04:34:01 -04:00
|
|
|
switch (update_rate) {
|
|
|
|
case 0:
|
|
|
|
case 50:
|
|
|
|
ins.init(AP_InertialSensor::WARM_START, AP_InertialSensor::RATE_50HZ);
|
|
|
|
break;
|
|
|
|
case 100:
|
|
|
|
ins.init(AP_InertialSensor::WARM_START, AP_InertialSensor::RATE_100HZ);
|
|
|
|
break;
|
|
|
|
case 200:
|
|
|
|
ins.init(AP_InertialSensor::WARM_START, AP_InertialSensor::RATE_200HZ);
|
|
|
|
break;
|
|
|
|
case 400:
|
|
|
|
ins.init(AP_InertialSensor::WARM_START, AP_InertialSensor::RATE_400HZ);
|
|
|
|
break;
|
|
|
|
}
|
2013-12-29 07:56:30 -04:00
|
|
|
|
2014-01-04 20:39:43 -04:00
|
|
|
plotf = fopen("plot.dat", "w");
|
|
|
|
plotf2 = fopen("plot2.dat", "w");
|
2014-01-30 18:27:56 -04:00
|
|
|
ekf1f = fopen("EKF1.dat", "w");
|
|
|
|
ekf2f = fopen("EKF2.dat", "w");
|
|
|
|
ekf3f = fopen("EKF3.dat", "w");
|
|
|
|
ekf4f = fopen("EKF4.dat", "w");
|
|
|
|
|
2014-01-05 01:37:47 -04:00
|
|
|
fprintf(plotf, "time SIM.Roll SIM.Pitch SIM.Yaw BAR.Alt FLIGHT.Roll FLIGHT.Pitch FLIGHT.Yaw FLIGHT.dN FLIGHT.dE FLIGHT.Alt DCM.Roll DCM.Pitch DCM.Yaw EKF.Roll EKF.Pitch EKF.Yaw INAV.dN INAV.dE INAV.Alt EKF.dN EKF.dE EKF.Alt\n");
|
2014-01-30 18:27:56 -04:00
|
|
|
fprintf(plotf2, "time E1 E2 E3 VN VE VD PN PE PD GX GY GZ WN WE MN ME MD MX MY MZ E1ref E2ref E3ref\n");
|
|
|
|
fprintf(ekf1f, "timestamp TimeMS Roll Pitch Yaw VN VE VD PN PE PD GX GY GZ\n");
|
|
|
|
fprintf(ekf2f, "timestamp TimeMS AX AY AZ VWN VWE MN ME MD MX MY MZ\n");
|
|
|
|
fprintf(ekf3f, "timestamp TimeMS IVN IVE IVD IPN IPE IPD IMX IMY IMZ IVT\n");
|
2014-05-14 05:39:18 -03:00
|
|
|
fprintf(ekf4f, "timestamp TimeMS SV SP SH SMX SMY SMZ SVT OFN EFE FS DS\n");
|
2014-01-04 20:39:43 -04:00
|
|
|
|
|
|
|
ahrs.set_ekf_use(true);
|
|
|
|
|
|
|
|
::printf("Waiting for InertialNav to start\n");
|
|
|
|
while (!ahrs.have_inertial_nav()) {
|
|
|
|
uint8_t type;
|
|
|
|
if (!LogReader.update(type)) break;
|
|
|
|
read_sensors(type);
|
2014-03-31 04:46:01 -03:00
|
|
|
if (type == LOG_GPS_MSG &&
|
|
|
|
gps.status() >= AP_GPS::GPS_OK_FIX_3D &&
|
|
|
|
done_baro_init && !done_home_init) {
|
|
|
|
const Location &loc = gps.location();
|
2014-01-05 02:22:05 -04:00
|
|
|
::printf("GPS Lock at %.7f %.7f %.2fm time=%.1f seconds\n",
|
2014-03-31 04:46:01 -03:00
|
|
|
loc.lat * 1.0e-7f,
|
|
|
|
loc.lng * 1.0e-7f,
|
|
|
|
loc.alt * 0.01f,
|
2014-01-05 02:22:05 -04:00
|
|
|
hal.scheduler->millis()*0.001f);
|
2014-03-31 04:46:01 -03:00
|
|
|
ahrs.set_home(loc);
|
|
|
|
compass.set_initial_location(loc.lat, loc.lng);
|
2014-01-05 02:22:05 -04:00
|
|
|
inertial_nav.setup_home_position();
|
|
|
|
done_home_init = true;
|
2014-01-04 20:39:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-17 18:11:46 -04:00
|
|
|
::printf("InertialNav started\n");
|
|
|
|
|
2014-01-04 20:39:43 -04:00
|
|
|
if (!ahrs.have_inertial_nav()) {
|
|
|
|
::printf("Failed to start NavEKF\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-01 00:15:46 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
setup user -p parameters
|
|
|
|
*/
|
|
|
|
static void set_user_parameters(void)
|
|
|
|
{
|
|
|
|
for (uint8_t i=0; i<num_user_parameters; i++) {
|
|
|
|
if (!LogReader.set_parameter(user_parameters[i].name, user_parameters[i].value)) {
|
|
|
|
::printf("Failed to set parameter %s to %f\n", user_parameters[i].name, user_parameters[i].value);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-04 20:39:43 -04:00
|
|
|
static void read_sensors(uint8_t type)
|
|
|
|
{
|
2014-03-01 00:15:46 -04:00
|
|
|
if (!done_parameters && type != LOG_FORMAT_MSG && type != LOG_PARAMETER_MSG) {
|
|
|
|
done_parameters = true;
|
|
|
|
set_user_parameters();
|
|
|
|
}
|
2014-01-04 20:39:43 -04:00
|
|
|
if (type == LOG_GPS_MSG) {
|
2014-03-31 04:46:01 -03:00
|
|
|
gps.update();
|
|
|
|
if (gps.status() >= AP_GPS::GPS_OK_FIX_3D) {
|
2014-02-17 18:11:46 -04:00
|
|
|
ahrs.estimate_wind();
|
|
|
|
}
|
2014-01-04 20:39:43 -04:00
|
|
|
} else if (type == LOG_IMU_MSG) {
|
2014-02-26 04:34:01 -04:00
|
|
|
uint32_t update_delta_usec = 1e6 / update_rate;
|
|
|
|
uint8_t update_count = update_rate>0?update_rate/50:1;
|
|
|
|
for (uint8_t i=0; i<update_count; i++) {
|
|
|
|
ahrs.update();
|
|
|
|
if (ahrs.get_home().lat != 0) {
|
|
|
|
inertial_nav.update(ins.get_delta_time());
|
|
|
|
}
|
2014-02-26 17:11:04 -04:00
|
|
|
hal.scheduler->stop_clock(hal.scheduler->micros() + (i+1)*update_delta_usec);
|
|
|
|
ins.set_gyro(0, ins.get_gyro());
|
|
|
|
ins.set_accel(0, ins.get_accel());
|
2014-01-05 01:37:47 -04:00
|
|
|
}
|
2014-01-04 20:39:43 -04:00
|
|
|
} else if ((type == LOG_PLANE_COMPASS_MSG && LogReader.vehicle == LogReader::VEHICLE_PLANE) ||
|
2014-03-06 06:40:08 -04:00
|
|
|
(type == LOG_COPTER_COMPASS_MSG && LogReader.vehicle == LogReader::VEHICLE_COPTER) ||
|
|
|
|
(type == LOG_ROVER_COMPASS_MSG && LogReader.vehicle == LogReader::VEHICLE_ROVER)) {
|
2014-01-04 20:39:43 -04:00
|
|
|
compass.read();
|
2014-02-17 18:11:46 -04:00
|
|
|
} else if (type == LOG_PLANE_AIRSPEED_MSG && LogReader.vehicle == LogReader::VEHICLE_PLANE) {
|
|
|
|
ahrs.set_airspeed(&airspeed);
|
|
|
|
} else if (type == LOG_BARO_MSG) {
|
2014-01-05 01:37:47 -04:00
|
|
|
barometer.read();
|
2014-01-05 02:22:05 -04:00
|
|
|
if (!done_baro_init) {
|
|
|
|
done_baro_init = true;
|
2014-02-25 06:10:49 -04:00
|
|
|
::printf("Barometer initialised\n");
|
2014-01-05 02:22:05 -04:00
|
|
|
barometer.update_calibration();
|
|
|
|
}
|
2013-12-29 08:21:09 -04:00
|
|
|
}
|
2013-12-29 07:56:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
while (true) {
|
|
|
|
uint8_t type;
|
2014-04-21 00:00:59 -03:00
|
|
|
|
|
|
|
if (arm_time_ms != 0 && hal.scheduler->millis() > arm_time_ms) {
|
|
|
|
if (!ahrs.get_armed()) {
|
|
|
|
ahrs.set_armed(true);
|
|
|
|
::printf("Arming at %u ms\n", (unsigned)hal.scheduler->millis());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-29 07:56:30 -04:00
|
|
|
if (!LogReader.update(type)) {
|
2014-01-05 01:37:47 -04:00
|
|
|
::printf("End of log at %.1f seconds\n", hal.scheduler->millis()*0.001f);
|
2013-12-29 18:47:50 -04:00
|
|
|
fclose(plotf);
|
2013-12-29 07:56:30 -04:00
|
|
|
exit(0);
|
|
|
|
}
|
2014-01-04 20:39:43 -04:00
|
|
|
read_sensors(type);
|
2013-12-29 07:56:30 -04:00
|
|
|
|
2014-01-04 20:39:43 -04:00
|
|
|
if ((type == LOG_PLANE_ATTITUDE_MSG && LogReader.vehicle == LogReader::VEHICLE_PLANE) ||
|
2014-03-06 02:50:50 -04:00
|
|
|
(type == LOG_COPTER_ATTITUDE_MSG && LogReader.vehicle == LogReader::VEHICLE_COPTER) ||
|
|
|
|
(type == LOG_ROVER_ATTITUDE_MSG && LogReader.vehicle == LogReader::VEHICLE_ROVER)) {
|
2014-01-30 18:27:56 -04:00
|
|
|
|
2013-12-29 08:21:09 -04:00
|
|
|
Vector3f ekf_euler;
|
2013-12-31 17:54:56 -04:00
|
|
|
Vector3f velNED;
|
|
|
|
Vector3f posNED;
|
|
|
|
Vector3f gyroBias;
|
|
|
|
Vector3f accelBias;
|
2014-01-30 18:27:56 -04:00
|
|
|
Vector3f windVel;
|
2013-12-31 17:54:56 -04:00
|
|
|
Vector3f magNED;
|
|
|
|
Vector3f magXYZ;
|
2014-01-04 20:39:43 -04:00
|
|
|
Vector3f DCM_attitude;
|
2014-01-05 01:37:47 -04:00
|
|
|
Vector3f ekf_relpos;
|
2014-01-30 18:27:56 -04:00
|
|
|
Vector3f velInnov;
|
|
|
|
Vector3f posInnov;
|
|
|
|
Vector3f magInnov;
|
|
|
|
float tasInnov;
|
2014-04-01 01:33:32 -03:00
|
|
|
float velVar;
|
|
|
|
float posVar;
|
|
|
|
float hgtVar;
|
2014-01-30 18:27:56 -04:00
|
|
|
Vector3f magVar;
|
2014-04-01 01:33:32 -03:00
|
|
|
float tasVar;
|
|
|
|
Vector2f offset;
|
2014-05-14 05:39:18 -03:00
|
|
|
uint8_t faultStatus;
|
|
|
|
float deltaGyroBias;
|
2014-01-30 18:27:56 -04:00
|
|
|
|
2014-03-01 17:00:13 -04:00
|
|
|
const Matrix3f &dcm_matrix = ((AP_AHRS_DCM)ahrs).get_dcm_matrix();
|
|
|
|
dcm_matrix.to_euler(&DCM_attitude.x, &DCM_attitude.y, &DCM_attitude.z);
|
2013-12-29 08:21:09 -04:00
|
|
|
NavEKF.getEulerAngles(ekf_euler);
|
2013-12-31 17:54:56 -04:00
|
|
|
NavEKF.getVelNED(velNED);
|
|
|
|
NavEKF.getPosNED(posNED);
|
|
|
|
NavEKF.getGyroBias(gyroBias);
|
|
|
|
NavEKF.getAccelBias(accelBias);
|
2014-01-30 18:27:56 -04:00
|
|
|
NavEKF.getWind(windVel);
|
2013-12-31 17:54:56 -04:00
|
|
|
NavEKF.getMagNED(magNED);
|
|
|
|
NavEKF.getMagXYZ(magXYZ);
|
2014-01-30 18:27:56 -04:00
|
|
|
NavEKF.getInnovations(velInnov, posInnov, magInnov, tasInnov);
|
2014-04-01 01:33:32 -03:00
|
|
|
NavEKF.getVariances(velVar, posVar, hgtVar, magVar, tasVar, offset);
|
2014-05-14 05:39:18 -03:00
|
|
|
NavEKF.getFilterFaults(faultStatus,deltaGyroBias);
|
2014-03-01 17:00:13 -04:00
|
|
|
NavEKF.getPosNED(ekf_relpos);
|
2014-01-05 01:37:47 -04:00
|
|
|
Vector3f inav_pos = inertial_nav.get_position() * 0.01f;
|
2013-12-31 17:54:56 -04:00
|
|
|
float temp = degrees(ekf_euler.z);
|
2014-01-30 18:27:56 -04:00
|
|
|
|
2013-12-31 17:54:56 -04:00
|
|
|
if (temp < 0.0f) temp = temp + 360.0f;
|
2014-01-05 01:37:47 -04:00
|
|
|
fprintf(plotf, "%.3f %.1f %.1f %.1f %.2f %.1f %.1f %.1f %.2f %.2f %.2f %.1f %.1f %.1f %.1f %.1f %.1f %.2f %.2f %.2f %.2f %.2f %.2f\n",
|
2014-01-03 00:38:08 -04:00
|
|
|
hal.scheduler->millis() * 0.001f,
|
2014-01-03 01:07:39 -04:00
|
|
|
LogReader.get_sim_attitude().x,
|
|
|
|
LogReader.get_sim_attitude().y,
|
|
|
|
LogReader.get_sim_attitude().z,
|
2014-01-05 01:37:47 -04:00
|
|
|
barometer.get_altitude(),
|
2014-01-03 00:38:08 -04:00
|
|
|
LogReader.get_attitude().x,
|
|
|
|
LogReader.get_attitude().y,
|
|
|
|
LogReader.get_attitude().z,
|
2014-01-05 01:37:47 -04:00
|
|
|
LogReader.get_inavpos().x,
|
|
|
|
LogReader.get_inavpos().y,
|
2014-02-22 17:17:55 -04:00
|
|
|
LogReader.get_relalt(),
|
2014-01-04 20:39:43 -04:00
|
|
|
degrees(DCM_attitude.x),
|
|
|
|
degrees(DCM_attitude.y),
|
|
|
|
degrees(DCM_attitude.z),
|
2014-01-03 00:38:08 -04:00
|
|
|
degrees(ekf_euler.x),
|
|
|
|
degrees(ekf_euler.y),
|
2014-01-05 01:37:47 -04:00
|
|
|
degrees(ekf_euler.z),
|
|
|
|
inav_pos.x,
|
|
|
|
inav_pos.y,
|
|
|
|
inav_pos.z,
|
|
|
|
ekf_relpos.x,
|
|
|
|
ekf_relpos.y,
|
|
|
|
-ekf_relpos.z);
|
2014-01-30 18:27:56 -04:00
|
|
|
fprintf(plotf2, "%.3f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f\n",
|
2013-12-29 18:47:50 -04:00
|
|
|
hal.scheduler->millis() * 0.001f,
|
|
|
|
degrees(ekf_euler.x),
|
|
|
|
degrees(ekf_euler.y),
|
2013-12-31 17:54:56 -04:00
|
|
|
temp,
|
|
|
|
velNED.x,
|
|
|
|
velNED.y,
|
|
|
|
velNED.z,
|
|
|
|
posNED.x,
|
|
|
|
posNED.y,
|
|
|
|
posNED.z,
|
2014-01-30 18:27:56 -04:00
|
|
|
60*degrees(gyroBias.x),
|
|
|
|
60*degrees(gyroBias.y),
|
|
|
|
60*degrees(gyroBias.z),
|
|
|
|
windVel.x,
|
|
|
|
windVel.y,
|
2013-12-31 17:54:56 -04:00
|
|
|
magNED.x,
|
|
|
|
magNED.y,
|
|
|
|
magNED.z,
|
|
|
|
magXYZ.x,
|
|
|
|
magXYZ.y,
|
|
|
|
magXYZ.z,
|
|
|
|
LogReader.get_attitude().x,
|
|
|
|
LogReader.get_attitude().y,
|
|
|
|
LogReader.get_attitude().z);
|
2014-01-30 18:27:56 -04:00
|
|
|
|
|
|
|
// define messages for EKF1 data packet
|
|
|
|
int16_t roll = (int16_t)(100*degrees(ekf_euler.x)); // roll angle (centi-deg)
|
|
|
|
int16_t pitch = (int16_t)(100*degrees(ekf_euler.y)); // pitch angle (centi-deg)
|
|
|
|
uint16_t yaw = (uint16_t)wrap_360_cd(100*degrees(ekf_euler.z)); // yaw angle (centi-deg)
|
|
|
|
float velN = (float)(velNED.x); // velocity North (m/s)
|
|
|
|
float velE = (float)(velNED.y); // velocity East (m/s)
|
|
|
|
float velD = (float)(velNED.z); // velocity Down (m/s)
|
|
|
|
float posN = (float)(posNED.x); // metres North
|
|
|
|
float posE = (float)(posNED.y); // metres East
|
|
|
|
float posD = (float)(posNED.z); // metres Down
|
|
|
|
int16_t gyrX = (int16_t)(6000*degrees(gyroBias.x)); // centi-deg/min
|
|
|
|
int16_t gyrY = (int16_t)(6000*degrees(gyroBias.y)); // centi-deg/min
|
|
|
|
int16_t gyrZ = (int16_t)(6000*degrees(gyroBias.z)); // centi-deg/min
|
|
|
|
|
|
|
|
// print EKF1 data packet
|
|
|
|
fprintf(ekf1f, "%.3f %u %d %d %u %.2f %.2f %.2f %.2f %.2f %.2f %d %d %d\n",
|
|
|
|
hal.scheduler->millis() * 0.001f,
|
|
|
|
hal.scheduler->millis(),
|
|
|
|
roll,
|
|
|
|
pitch,
|
|
|
|
yaw,
|
|
|
|
velN,
|
|
|
|
velE,
|
|
|
|
velD,
|
|
|
|
posN,
|
|
|
|
posE,
|
|
|
|
posD,
|
|
|
|
gyrX,
|
|
|
|
gyrY,
|
|
|
|
gyrZ);
|
|
|
|
|
|
|
|
// define messages for EKF2 data packet
|
|
|
|
int8_t accX = (int8_t)(100*accelBias.x);
|
|
|
|
int8_t accY = (int8_t)(100*accelBias.y);
|
|
|
|
int8_t accZ = (int8_t)(100*accelBias.z);
|
|
|
|
int16_t windN = (int16_t)(100*windVel.x);
|
|
|
|
int16_t windE = (int16_t)(100*windVel.y);
|
|
|
|
int16_t magN = (int16_t)(magNED.x);
|
|
|
|
int16_t magE = (int16_t)(magNED.y);
|
|
|
|
int16_t magD = (int16_t)(magNED.z);
|
|
|
|
int16_t magX = (int16_t)(magXYZ.x);
|
|
|
|
int16_t magY = (int16_t)(magXYZ.y);
|
|
|
|
int16_t magZ = (int16_t)(magXYZ.z);
|
|
|
|
|
|
|
|
// print EKF2 data packet
|
|
|
|
fprintf(ekf2f, "%.3f %d %d %d %d %d %d %d %d %d %d %d %d\n",
|
|
|
|
hal.scheduler->millis() * 0.001f,
|
|
|
|
hal.scheduler->millis(),
|
|
|
|
accX,
|
|
|
|
accY,
|
|
|
|
accZ,
|
|
|
|
windN,
|
|
|
|
windE,
|
|
|
|
magN,
|
|
|
|
magE,
|
|
|
|
magD,
|
|
|
|
magX,
|
|
|
|
magY,
|
|
|
|
magZ);
|
|
|
|
|
|
|
|
// define messages for EKF3 data packet
|
|
|
|
int16_t innovVN = (int16_t)(100*velInnov.x);
|
|
|
|
int16_t innovVE = (int16_t)(100*velInnov.y);
|
|
|
|
int16_t innovVD = (int16_t)(100*velInnov.z);
|
|
|
|
int16_t innovPN = (int16_t)(100*posInnov.x);
|
|
|
|
int16_t innovPE = (int16_t)(100*posInnov.y);
|
|
|
|
int16_t innovPD = (int16_t)(100*posInnov.z);
|
|
|
|
int16_t innovMX = (int16_t)(magInnov.x);
|
|
|
|
int16_t innovMY = (int16_t)(magInnov.y);
|
|
|
|
int16_t innovMZ = (int16_t)(magInnov.z);
|
|
|
|
int16_t innovVT = (int16_t)(100*tasInnov);
|
|
|
|
|
|
|
|
// print EKF3 data packet
|
|
|
|
fprintf(ekf3f, "%.3f %d %d %d %d %d %d %d %d %d %d %d\n",
|
|
|
|
hal.scheduler->millis() * 0.001f,
|
|
|
|
hal.scheduler->millis(),
|
|
|
|
innovVN,
|
|
|
|
innovVE,
|
|
|
|
innovVD,
|
|
|
|
innovPN,
|
|
|
|
innovPE,
|
|
|
|
innovPD,
|
|
|
|
innovMX,
|
|
|
|
innovMY,
|
|
|
|
innovMZ,
|
|
|
|
innovVT);
|
|
|
|
|
|
|
|
// define messages for EKF4 data packet
|
2014-05-01 04:54:31 -03:00
|
|
|
int16_t sqrtvarV = (int16_t)(constrain_float(100*velVar,INT16_MIN,INT16_MAX));
|
|
|
|
int16_t sqrtvarP = (int16_t)(constrain_float(100*posVar,INT16_MIN,INT16_MAX));
|
|
|
|
int16_t sqrtvarH = (int16_t)(constrain_float(100*hgtVar,INT16_MIN,INT16_MAX));
|
|
|
|
int16_t sqrtvarMX = (int16_t)(constrain_float(100*magVar.x,INT16_MIN,INT16_MAX));
|
|
|
|
int16_t sqrtvarMY = (int16_t)(constrain_float(100*magVar.y,INT16_MIN,INT16_MAX));
|
|
|
|
int16_t sqrtvarMZ = (int16_t)(constrain_float(100*magVar.z,INT16_MIN,INT16_MAX));
|
|
|
|
int16_t sqrtvarVT = (int16_t)(constrain_float(100*tasVar,INT16_MIN,INT16_MAX));
|
|
|
|
int16_t offsetNorth = (int8_t)(constrain_float(offset.x,INT16_MIN,INT16_MAX));
|
|
|
|
int16_t offsetEast = (int8_t)(constrain_float(offset.y,INT16_MIN,INT16_MAX));
|
2014-05-14 05:39:18 -03:00
|
|
|
uint8_t divergeRate = (uint8_t)(100*deltaGyroBias);
|
2014-01-30 18:27:56 -04:00
|
|
|
|
|
|
|
// print EKF4 data packet
|
2014-05-14 05:39:18 -03:00
|
|
|
fprintf(ekf4f, "%.3f %d %d %d %d %d %d %d %d %d %d %d %d\n",
|
2014-01-30 18:27:56 -04:00
|
|
|
hal.scheduler->millis() * 0.001f,
|
|
|
|
hal.scheduler->millis(),
|
2014-04-01 01:33:32 -03:00
|
|
|
sqrtvarV,
|
|
|
|
sqrtvarP,
|
|
|
|
sqrtvarH,
|
2014-01-30 18:27:56 -04:00
|
|
|
sqrtvarMX,
|
|
|
|
sqrtvarMY,
|
|
|
|
sqrtvarMZ,
|
2014-04-01 01:33:32 -03:00
|
|
|
sqrtvarVT,
|
|
|
|
offsetNorth,
|
2014-05-14 05:39:18 -03:00
|
|
|
offsetEast,
|
|
|
|
faultStatus,
|
|
|
|
divergeRate);
|
2013-12-29 07:56:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AP_HAL_MAIN();
|