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>
|
2015-06-26 02:12:17 -03:00
|
|
|
#include <fenv.h>
|
2013-12-29 07:56:30 -04:00
|
|
|
#include <AP_Math.h>
|
|
|
|
#include <AP_HAL.h>
|
|
|
|
#include <AP_HAL_AVR.h>
|
2015-05-04 03:19:06 -03:00
|
|
|
#include <AP_HAL_SITL.h>
|
2013-12-29 07:56:30 -04:00
|
|
|
#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>
|
|
|
|
#include <AP_AHRS.h>
|
|
|
|
#include <SITL.h>
|
|
|
|
#include <AP_Compass.h>
|
|
|
|
#include <AP_Baro.h>
|
|
|
|
#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>
|
2015-01-02 20:49:11 -04:00
|
|
|
#include <AP_OpticalFlow.h>
|
2015-01-28 04:28:32 -04:00
|
|
|
#include <AP_SerialManager.h>
|
2015-01-29 07:28:21 -04:00
|
|
|
#include <RC_Channel.h>
|
2015-04-24 03:06:05 -03:00
|
|
|
#include <AP_RangeFinder.h>
|
2013-12-29 07:56:30 -04:00
|
|
|
#include <stdio.h>
|
2014-02-28 23:24:51 -04:00
|
|
|
#include <errno.h>
|
2015-06-18 22:57:19 -03:00
|
|
|
#include <signal.h>
|
|
|
|
#include <unistd.h>
|
2015-06-09 21:09:56 -03:00
|
|
|
#include <utility/getopt_cpp.h>
|
2015-06-29 02:59:53 -03:00
|
|
|
#include "Parameters.h"
|
|
|
|
#include "VehicleType.h"
|
|
|
|
#include "MsgHandler.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"
|
2015-06-12 21:23:12 -03:00
|
|
|
#include "DataFlashFileReader.h"
|
2013-12-29 07:56:30 -04:00
|
|
|
|
2015-05-09 19:20:32 -03:00
|
|
|
#define streq(x, y) (!strcmp(x, y))
|
|
|
|
|
2013-12-29 07:56:30 -04:00
|
|
|
const AP_HAL::HAL& hal = AP_HAL_BOARD_DRIVER;
|
|
|
|
|
2015-06-20 09:30:00 -03:00
|
|
|
class ReplayVehicle {
|
2015-06-01 03:14:11 -03:00
|
|
|
public:
|
|
|
|
void setup();
|
2015-06-20 09:30:00 -03:00
|
|
|
void load_parameters(void);
|
2015-06-01 03:14:11 -03:00
|
|
|
|
|
|
|
AP_InertialSensor ins;
|
|
|
|
AP_Baro barometer;
|
|
|
|
AP_GPS gps;
|
|
|
|
Compass compass;
|
|
|
|
RangeFinder rng;
|
|
|
|
NavEKF EKF{&ahrs, barometer, rng};
|
|
|
|
AP_AHRS_NavEKF ahrs {ins, barometer, gps, rng, EKF};
|
|
|
|
AP_InertialNav_NavEKF inertial_nav{ahrs};
|
|
|
|
AP_Vehicle::FixedWing aparm;
|
|
|
|
AP_Airspeed airspeed{aparm};
|
2015-06-25 10:52:48 -03:00
|
|
|
DataFlash_Class dataflash;
|
2013-12-29 07:56:30 -04:00
|
|
|
|
2015-06-20 09:30:00 -03:00
|
|
|
private:
|
|
|
|
Parameters g;
|
2015-06-01 03:14:11 -03:00
|
|
|
|
|
|
|
// setup the var_info table
|
|
|
|
AP_Param param_loader{var_info};
|
|
|
|
|
|
|
|
static const AP_Param::Info var_info[];
|
|
|
|
};
|
2014-01-04 20:39:43 -04:00
|
|
|
|
2015-06-20 09:30:00 -03:00
|
|
|
ReplayVehicle replayvehicle;
|
2013-12-29 18:47:50 -04:00
|
|
|
|
2015-06-20 09:30:00 -03:00
|
|
|
#define GSCALAR(v, name, def) { replayvehicle.g.v.vtype, name, Parameters::k_param_ ## v, &replayvehicle.g.v, {def_value : def} }
|
|
|
|
#define GOBJECT(v, name, class) { AP_PARAM_GROUP, name, Parameters::k_param_ ## v, &replayvehicle.v, {group_info : class::var_info} }
|
|
|
|
#define GOBJECTN(v, pname, name, class) { AP_PARAM_GROUP, name, Parameters::k_param_ ## pname, &replayvehicle.v, {group_info : class::var_info} }
|
2014-01-04 20:39:43 -04:00
|
|
|
|
2015-06-20 09:30:00 -03:00
|
|
|
const AP_Param::Info ReplayVehicle::var_info[] PROGMEM = {
|
2015-06-01 03:14:11 -03:00
|
|
|
GSCALAR(dummy, "_DUMMY", 0),
|
2014-03-01 00:15:46 -04:00
|
|
|
|
2015-06-01 03:14:11 -03:00
|
|
|
// barometer ground calibration. The GND_ prefix is chosen for
|
|
|
|
// compatibility with previous releases of ArduPlane
|
|
|
|
// @Group: GND_
|
|
|
|
// @Path: ../libraries/AP_Baro/AP_Baro.cpp
|
|
|
|
GOBJECT(barometer, "GND_", AP_Baro),
|
|
|
|
|
|
|
|
// @Group: INS_
|
|
|
|
// @Path: ../libraries/AP_InertialSensor/AP_InertialSensor.cpp
|
|
|
|
GOBJECT(ins, "INS_", AP_InertialSensor),
|
|
|
|
|
|
|
|
// @Group: AHRS_
|
|
|
|
// @Path: ../libraries/AP_AHRS/AP_AHRS.cpp
|
|
|
|
GOBJECT(ahrs, "AHRS_", AP_AHRS),
|
|
|
|
|
|
|
|
// @Group: ARSPD_
|
|
|
|
// @Path: ../libraries/AP_Airspeed/AP_Airspeed.cpp
|
|
|
|
GOBJECT(airspeed, "ARSPD_", AP_Airspeed),
|
|
|
|
|
|
|
|
// @Group: EKF_
|
|
|
|
// @Path: ../libraries/AP_NavEKF/AP_NavEKF.cpp
|
|
|
|
GOBJECTN(EKF, NavEKF, "EKF_", NavEKF),
|
|
|
|
|
|
|
|
// @Group: COMPASS_
|
|
|
|
// @Path: ../libraries/AP_Compass/AP_Compass.cpp
|
|
|
|
GOBJECT(compass, "COMPASS_", Compass),
|
|
|
|
|
|
|
|
AP_VAREND
|
2014-12-07 20:25:22 -04:00
|
|
|
};
|
|
|
|
|
2015-06-20 09:30:00 -03:00
|
|
|
|
|
|
|
void ReplayVehicle::load_parameters(void)
|
2015-06-01 03:14:11 -03:00
|
|
|
{
|
|
|
|
if (!AP_Param::check_var_info()) {
|
|
|
|
hal.scheduler->panic(PSTR("Bad parameter table"));
|
|
|
|
}
|
|
|
|
}
|
2014-03-01 00:15:46 -04:00
|
|
|
|
2015-06-25 01:17:00 -03:00
|
|
|
/*
|
|
|
|
Replay specific log structures
|
|
|
|
*/
|
|
|
|
struct PACKED log_Chek {
|
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
uint64_t time_us;
|
|
|
|
int16_t roll;
|
|
|
|
int16_t pitch;
|
|
|
|
uint16_t yaw;
|
|
|
|
int32_t lat;
|
|
|
|
int32_t lng;
|
|
|
|
float alt;
|
|
|
|
float vnorth;
|
|
|
|
float veast;
|
|
|
|
float vdown;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum {
|
2015-07-01 07:40:46 -03:00
|
|
|
LOG_CHEK_MSG=100
|
2015-06-25 01:17:00 -03:00
|
|
|
};
|
|
|
|
|
2015-06-20 09:30:00 -03:00
|
|
|
static const struct LogStructure log_structure[] PROGMEM = {
|
2015-06-25 01:17:00 -03:00
|
|
|
LOG_COMMON_STRUCTURES,
|
|
|
|
{ LOG_CHEK_MSG, sizeof(log_Chek),
|
|
|
|
"CHEK", "QccCLLffff", "TimeUS,Roll,Pitch,Yaw,Lat,Lng,Alt,VN,VE,VD" }
|
2015-06-20 09:30:00 -03:00
|
|
|
};
|
|
|
|
|
2015-07-04 09:43:54 -03:00
|
|
|
void ReplayVehicle::setup(void)
|
|
|
|
{
|
|
|
|
// we pass zero log structures, as we will be outputting the log
|
|
|
|
// structures we need manually, to prevent FMT duplicates
|
|
|
|
dataflash.Init(log_structure, 0);
|
2015-06-20 09:30:00 -03:00
|
|
|
dataflash.StartNewLog();
|
|
|
|
|
|
|
|
ahrs.set_compass(&compass);
|
|
|
|
ahrs.set_fly_forward(true);
|
|
|
|
ahrs.set_wind_estimation(true);
|
|
|
|
ahrs.set_correct_centrifugal(true);
|
|
|
|
ahrs.set_ekf_use(true);
|
|
|
|
|
|
|
|
printf("Starting disarmed\n");
|
|
|
|
hal.util->set_soft_armed(false);
|
|
|
|
|
|
|
|
barometer.init();
|
|
|
|
barometer.setHIL(0);
|
|
|
|
barometer.update();
|
|
|
|
compass.init();
|
|
|
|
ins.set_hil_mode();
|
|
|
|
}
|
|
|
|
|
|
|
|
class Replay {
|
|
|
|
public:
|
|
|
|
void setup();
|
|
|
|
void loop();
|
|
|
|
|
|
|
|
Replay(ReplayVehicle &vehicle) :
|
|
|
|
filename("log.bin"),
|
|
|
|
_vehicle(vehicle) { }
|
|
|
|
|
2015-06-18 22:57:19 -03:00
|
|
|
void flush_dataflash(void);
|
|
|
|
|
2015-07-02 01:27:10 -03:00
|
|
|
bool check_solution = false;
|
|
|
|
const char *log_filename = NULL;
|
|
|
|
|
2015-07-04 02:14:14 -03:00
|
|
|
/*
|
|
|
|
information about a log from find_log_info
|
|
|
|
*/
|
|
|
|
struct log_information {
|
|
|
|
uint16_t update_rate;
|
|
|
|
bool have_imu2;
|
|
|
|
} log_info {};
|
|
|
|
|
2015-06-20 09:30:00 -03:00
|
|
|
private:
|
|
|
|
const char *filename;
|
|
|
|
ReplayVehicle &_vehicle;
|
|
|
|
|
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
|
|
|
SITL sitl;
|
|
|
|
#endif
|
|
|
|
|
2015-07-07 02:13:51 -03:00
|
|
|
LogReader logreader{_vehicle.ahrs, _vehicle.ins, _vehicle.barometer, _vehicle.compass, _vehicle.gps, _vehicle.airspeed, _vehicle.dataflash, log_structure, ARRAY_SIZE(log_structure), nottypes};
|
2015-06-20 09:30:00 -03:00
|
|
|
|
|
|
|
FILE *plotf;
|
|
|
|
FILE *plotf2;
|
|
|
|
FILE *ekf1f;
|
|
|
|
FILE *ekf2f;
|
|
|
|
FILE *ekf3f;
|
|
|
|
FILE *ekf4f;
|
|
|
|
|
|
|
|
bool done_parameters;
|
|
|
|
bool done_baro_init;
|
|
|
|
bool done_home_init;
|
|
|
|
int32_t arm_time_ms = -1;
|
|
|
|
bool ahrs_healthy;
|
|
|
|
bool have_imt = false;
|
|
|
|
bool have_imt2 = false;
|
|
|
|
bool have_fram = false;
|
|
|
|
bool use_imt = true;
|
2015-06-26 02:12:17 -03:00
|
|
|
bool check_generate = false;
|
|
|
|
float tolerance_euler = 3;
|
|
|
|
float tolerance_pos = 2;
|
|
|
|
float tolerance_vel = 2;
|
2015-07-07 02:13:51 -03:00
|
|
|
const char **nottypes = NULL;
|
2015-07-07 02:55:41 -03:00
|
|
|
uint16_t downsample = 0;
|
|
|
|
uint32_t output_counter = 0;
|
2015-06-26 02:12:17 -03:00
|
|
|
|
|
|
|
struct {
|
|
|
|
float max_roll_error;
|
|
|
|
float max_pitch_error;
|
|
|
|
float max_yaw_error;
|
|
|
|
float max_pos_error;
|
|
|
|
float max_alt_error;
|
|
|
|
float max_vel_error;
|
|
|
|
} check_result {};
|
2015-06-20 09:30:00 -03:00
|
|
|
|
|
|
|
void _parse_command_line(uint8_t argc, char * const argv[]);
|
|
|
|
|
|
|
|
uint8_t num_user_parameters;
|
|
|
|
struct {
|
|
|
|
char name[17];
|
|
|
|
float value;
|
|
|
|
} user_parameters[100];
|
|
|
|
|
|
|
|
void set_ins_update_rate(uint16_t update_rate);
|
|
|
|
|
|
|
|
void usage(void);
|
|
|
|
void set_user_parameters(void);
|
|
|
|
void read_sensors(const char *type);
|
2015-06-26 02:12:17 -03:00
|
|
|
void log_check_generate();
|
|
|
|
void log_check_solution();
|
2015-07-04 02:14:14 -03:00
|
|
|
bool show_error(const char *text, float max_error, float tolerance);
|
2015-06-26 02:12:17 -03:00
|
|
|
void report_checks();
|
2015-07-04 02:14:14 -03:00
|
|
|
bool find_log_info(struct log_information &info);
|
2015-07-07 02:13:51 -03:00
|
|
|
const char **parse_list_from_string(const char *str);
|
2015-06-20 09:30:00 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
Replay replay(replayvehicle);
|
|
|
|
|
2015-06-01 03:14:11 -03:00
|
|
|
void Replay::usage(void)
|
2014-03-01 00:15:46 -04:00
|
|
|
{
|
|
|
|
::printf("Options:\n");
|
2015-06-09 21:09:56 -03:00
|
|
|
::printf("\t--parm NAME=VALUE set parameter NAME to VALUE\n");
|
|
|
|
::printf("\t--accel-mask MASK set accel mask (1=accel1 only, 2=accel2 only, 3=both)\n");
|
|
|
|
::printf("\t--gyro-mask MASK set gyro mask (1=gyro1 only, 2=gyro2 only, 3=both)\n");
|
|
|
|
::printf("\t--arm-time time arm at time (milliseconds)\n");
|
2015-06-16 01:26:07 -03:00
|
|
|
::printf("\t--no-imt don't use IMT data\n");
|
2015-06-25 01:17:00 -03:00
|
|
|
::printf("\t--check-generate generate CHEK messages in output\n");
|
2015-06-26 02:12:17 -03:00
|
|
|
::printf("\t--check check solution against CHEK messages\n");
|
|
|
|
::printf("\t--tolerance-euler tolerance for euler angles in degrees\n");
|
|
|
|
::printf("\t--tolerance-pos tolerance for position in meters\n");
|
|
|
|
::printf("\t--tolerance-vel tolerance for velocity in meters/second\n");
|
2015-07-07 02:13:51 -03:00
|
|
|
::printf("\t--nottypes list of msg types not to output, comma separated\n");
|
2015-07-07 02:55:41 -03:00
|
|
|
::printf("\t--downsample downsampling rate for output\n");
|
2014-03-01 00:15:46 -04:00
|
|
|
}
|
|
|
|
|
2015-06-25 01:17:00 -03:00
|
|
|
|
|
|
|
enum {
|
2015-06-26 02:12:17 -03:00
|
|
|
OPT_CHECK = 128,
|
|
|
|
OPT_CHECK_GENERATE,
|
|
|
|
OPT_TOLERANCE_EULER,
|
|
|
|
OPT_TOLERANCE_POS,
|
2015-07-07 02:13:51 -03:00
|
|
|
OPT_TOLERANCE_VEL,
|
2015-07-07 02:55:41 -03:00
|
|
|
OPT_NOTTYPES,
|
|
|
|
OPT_DOWNSAMPLE
|
2015-06-25 01:17:00 -03:00
|
|
|
};
|
|
|
|
|
2015-06-18 22:57:19 -03:00
|
|
|
void Replay::flush_dataflash(void) {
|
|
|
|
_vehicle.dataflash.flush();
|
|
|
|
}
|
|
|
|
|
2015-07-07 02:13:51 -03:00
|
|
|
/*
|
|
|
|
create a list from a comma separated string
|
|
|
|
*/
|
|
|
|
const char **Replay::parse_list_from_string(const char *str_in)
|
|
|
|
{
|
|
|
|
uint16_t comma_count=0;
|
|
|
|
const char *p;
|
|
|
|
for (p=str_in; *p; p++) {
|
|
|
|
if (*p == ',') comma_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *str = strdup(str_in);
|
|
|
|
if (str == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
const char **ret = (const char **)calloc(comma_count+2, sizeof(char *));
|
|
|
|
if (ret == NULL) {
|
|
|
|
free(str);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
char *saveptr = NULL;
|
|
|
|
uint16_t idx = 0;
|
|
|
|
for (p=strtok_r(str, ",", &saveptr); p; p=strtok_r(NULL, ",", &saveptr)) {
|
|
|
|
ret[idx++] = p;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-06-09 21:09:56 -03:00
|
|
|
void Replay::_parse_command_line(uint8_t argc, char * const argv[])
|
2013-12-29 07:56:30 -04:00
|
|
|
{
|
2015-06-09 21:09:56 -03:00
|
|
|
const struct GetOptLong::option options[] = {
|
|
|
|
{"parm", true, 0, 'p'},
|
|
|
|
{"param", true, 0, 'p'},
|
|
|
|
{"help", false, 0, 'h'},
|
|
|
|
{"accel-mask", true, 0, 'a'},
|
|
|
|
{"gyro-mask", true, 0, 'g'},
|
|
|
|
{"arm-time", true, 0, 'A'},
|
2015-06-16 01:26:07 -03:00
|
|
|
{"no-imt", false, 0, 'n'},
|
2015-06-26 02:12:17 -03:00
|
|
|
{"check-generate", false, 0, OPT_CHECK_GENERATE},
|
|
|
|
{"check", false, 0, OPT_CHECK},
|
|
|
|
{"tolerance-euler", true, 0, OPT_TOLERANCE_EULER},
|
|
|
|
{"tolerance-pos", true, 0, OPT_TOLERANCE_POS},
|
|
|
|
{"tolerance-vel", true, 0, OPT_TOLERANCE_VEL},
|
2015-07-07 02:13:51 -03:00
|
|
|
{"nottypes", true, 0, OPT_NOTTYPES},
|
2015-07-07 02:55:41 -03:00
|
|
|
{"downsample", true, 0, OPT_DOWNSAMPLE},
|
2015-06-09 21:09:56 -03:00
|
|
|
{0, false, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
GetOptLong gopt(argc, argv, "r:p:ha:g:A:", options);
|
2014-01-04 20:39:43 -04:00
|
|
|
|
2014-02-26 04:34:01 -04:00
|
|
|
int opt;
|
2015-06-09 21:09:56 -03:00
|
|
|
while ((opt = gopt.getoption()) != -1) {
|
2014-02-26 04:34:01 -04:00
|
|
|
switch (opt) {
|
2014-03-01 17:00:13 -04:00
|
|
|
case 'g':
|
2015-06-09 21:09:56 -03:00
|
|
|
logreader.set_gyro_mask(strtol(gopt.optarg, NULL, 0));
|
2014-03-01 17:00:13 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'a':
|
2015-06-09 21:09:56 -03:00
|
|
|
logreader.set_accel_mask(strtol(gopt.optarg, NULL, 0));
|
2014-03-01 17:00:13 -04:00
|
|
|
break;
|
|
|
|
|
2014-04-21 00:00:59 -03:00
|
|
|
case 'A':
|
2015-06-09 21:09:56 -03:00
|
|
|
arm_time_ms = strtol(gopt.optarg, NULL, 0);
|
2014-04-21 00:00:59 -03:00
|
|
|
break;
|
|
|
|
|
2015-06-16 01:26:07 -03:00
|
|
|
case 'n':
|
|
|
|
use_imt = false;
|
|
|
|
logreader.set_use_imt(use_imt);
|
|
|
|
break;
|
|
|
|
|
2015-06-25 01:17:00 -03:00
|
|
|
case 'p': {
|
2015-06-09 21:09:56 -03:00
|
|
|
const char *eq = strchr(gopt.optarg, '=');
|
2014-03-01 00:15:46 -04:00
|
|
|
if (eq == NULL) {
|
|
|
|
::printf("Usage: -p NAME=VALUE\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2015-06-09 21:09:56 -03:00
|
|
|
memset(user_parameters[num_user_parameters].name, '\0', 16);
|
|
|
|
strncpy(user_parameters[num_user_parameters].name, gopt.optarg, eq-gopt.optarg);
|
|
|
|
user_parameters[num_user_parameters].value = atof(eq+1);
|
2014-03-01 00:15:46 -04:00
|
|
|
num_user_parameters++;
|
2015-07-06 12:30:59 -03:00
|
|
|
if (num_user_parameters >= ARRAY_SIZE(user_parameters)) {
|
2014-03-01 00:15:46 -04:00
|
|
|
::printf("Too many user parameters\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
2014-02-26 04:34:01 -04:00
|
|
|
}
|
2015-06-25 01:17:00 -03:00
|
|
|
|
2015-06-26 02:12:17 -03:00
|
|
|
case OPT_CHECK_GENERATE:
|
|
|
|
check_generate = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPT_CHECK:
|
|
|
|
check_solution = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPT_TOLERANCE_EULER:
|
|
|
|
tolerance_euler = atof(gopt.optarg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPT_TOLERANCE_POS:
|
|
|
|
tolerance_pos = atof(gopt.optarg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPT_TOLERANCE_VEL:
|
|
|
|
tolerance_vel = atof(gopt.optarg);
|
2015-06-25 01:17:00 -03:00
|
|
|
break;
|
|
|
|
|
2015-07-07 02:13:51 -03:00
|
|
|
case OPT_NOTTYPES:
|
|
|
|
nottypes = parse_list_from_string(gopt.optarg);
|
|
|
|
break;
|
|
|
|
|
2015-07-07 02:55:41 -03:00
|
|
|
case OPT_DOWNSAMPLE:
|
|
|
|
downsample = atoi(gopt.optarg);
|
|
|
|
break;
|
|
|
|
|
2015-06-25 01:17:00 -03:00
|
|
|
case 'h':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
exit(0);
|
|
|
|
}
|
2014-02-26 04:34:01 -04:00
|
|
|
}
|
|
|
|
|
2015-06-09 21:09:56 -03:00
|
|
|
argv += gopt.optind;
|
|
|
|
argc -= gopt.optind;
|
2014-02-26 04:34:01 -04:00
|
|
|
|
|
|
|
if (argc > 0) {
|
|
|
|
filename = argv[0];
|
2014-02-22 17:17:01 -04:00
|
|
|
}
|
2015-06-09 21:09:56 -03:00
|
|
|
}
|
|
|
|
|
2015-07-04 02:14:14 -03:00
|
|
|
class IMUCounter : public DataFlashFileReader {
|
2015-06-12 21:23:12 -03:00
|
|
|
public:
|
2015-07-04 02:14:14 -03:00
|
|
|
IMUCounter() {}
|
2015-06-12 21:23:12 -03:00
|
|
|
bool handle_log_format_msg(const struct log_Format &f);
|
|
|
|
bool handle_msg(const struct log_Format &f, uint8_t *msg);
|
|
|
|
|
2015-07-04 02:14:14 -03:00
|
|
|
uint64_t last_imu_timestamp;
|
2015-06-12 21:23:12 -03:00
|
|
|
private:
|
|
|
|
MsgHandler *handler;
|
|
|
|
};
|
2015-07-04 02:14:14 -03:00
|
|
|
|
|
|
|
bool IMUCounter::handle_log_format_msg(const struct log_Format &f) {
|
|
|
|
if (!strncmp(f.name,"IMU",4)) {
|
|
|
|
// an IMU message
|
2015-06-12 21:23:12 -03:00
|
|
|
handler = new MsgHandler(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
2015-07-04 02:14:14 -03:00
|
|
|
|
|
|
|
bool IMUCounter::handle_msg(const struct log_Format &f, uint8_t *msg) {
|
|
|
|
if (strncmp(f.name,"IMU",4)) {
|
|
|
|
// not an IMU message
|
2015-06-12 21:23:12 -03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-04 02:14:14 -03:00
|
|
|
if (handler->field_value(msg, "TimeUS", last_imu_timestamp)) {
|
|
|
|
} else if (handler->field_value(msg, "TimeMS", last_imu_timestamp)) {
|
|
|
|
last_imu_timestamp *= 1000;
|
2015-06-12 21:23:12 -03:00
|
|
|
} else {
|
2015-07-04 02:14:14 -03:00
|
|
|
::printf("Unable to find timestamp in IMU message");
|
2015-06-12 21:23:12 -03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-04 02:14:14 -03:00
|
|
|
/*
|
|
|
|
find information about the log
|
|
|
|
*/
|
|
|
|
bool Replay::find_log_info(struct log_information &info)
|
|
|
|
{
|
|
|
|
IMUCounter reader;
|
2015-06-12 21:23:12 -03:00
|
|
|
if (!reader.open_log(filename)) {
|
|
|
|
perror(filename);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
int samplecount = 0;
|
|
|
|
uint64_t prev = 0;
|
2015-07-04 02:14:14 -03:00
|
|
|
uint64_t smallest_delta = 0;
|
2015-06-12 21:23:12 -03:00
|
|
|
prev = 0;
|
2015-07-04 02:14:14 -03:00
|
|
|
while (samplecount < 1000) {
|
2015-06-12 21:23:12 -03:00
|
|
|
char type[5];
|
|
|
|
if (!reader.update(type)) {
|
|
|
|
break;
|
|
|
|
}
|
2015-07-04 02:14:14 -03:00
|
|
|
if (streq(type, "IMU")) {
|
2015-06-12 21:23:12 -03:00
|
|
|
if (prev == 0) {
|
2015-07-04 02:14:14 -03:00
|
|
|
prev = reader.last_imu_timestamp;
|
2015-06-12 21:23:12 -03:00
|
|
|
} else {
|
2015-07-04 02:14:14 -03:00
|
|
|
uint64_t delta = reader.last_imu_timestamp - prev;
|
|
|
|
if (smallest_delta == 0 || delta < smallest_delta) {
|
|
|
|
smallest_delta = delta;
|
|
|
|
}
|
2015-06-12 21:23:12 -03:00
|
|
|
samplecount++;
|
|
|
|
}
|
|
|
|
}
|
2015-07-04 02:14:14 -03:00
|
|
|
if (streq(type, "IMU2") && !info.have_imu2) {
|
|
|
|
info.have_imu2 = true;
|
|
|
|
}
|
2015-06-12 21:23:12 -03:00
|
|
|
}
|
2015-07-04 02:14:14 -03:00
|
|
|
if (smallest_delta == 0) {
|
|
|
|
::printf("Unable to determine log rate - insufficient IMU messages?!");
|
|
|
|
return false;
|
2015-06-12 21:23:12 -03:00
|
|
|
}
|
|
|
|
|
2015-07-04 02:14:14 -03:00
|
|
|
float rate = 1.0e6f/smallest_delta;
|
|
|
|
if (rate < 100) {
|
|
|
|
info.update_rate = 50;
|
|
|
|
} else {
|
|
|
|
info.update_rate = 400;
|
2015-06-12 21:23:12 -03:00
|
|
|
}
|
2015-07-04 02:14:14 -03:00
|
|
|
return true;
|
2015-06-12 21:23:12 -03:00
|
|
|
}
|
|
|
|
|
2015-06-18 22:57:19 -03:00
|
|
|
// catch floating point exceptions
|
|
|
|
static void _replay_sig_fpe(int signum)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: Floating point exception - flushing dataflash...\n");
|
|
|
|
replay.flush_dataflash();
|
|
|
|
fprintf(stderr, "ERROR: ... and aborting.\n");
|
2015-07-02 01:27:10 -03:00
|
|
|
if (replay.check_solution) {
|
|
|
|
FILE *f = fopen("replay_results.txt","a");
|
|
|
|
fprintf(f, "%s\tFPE\tFPE\tFPE\tFPE\tFPE\n",
|
|
|
|
replay.log_filename);
|
|
|
|
fclose(f);
|
|
|
|
}
|
2015-06-18 22:57:19 -03:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2015-06-09 21:09:56 -03:00
|
|
|
void Replay::setup()
|
|
|
|
{
|
|
|
|
::printf("Starting\n");
|
|
|
|
|
|
|
|
uint8_t argc;
|
|
|
|
char * const *argv;
|
|
|
|
|
|
|
|
hal.util->commandline_arguments(argc, argv);
|
|
|
|
|
|
|
|
_parse_command_line(argc, argv);
|
2014-02-22 17:17:01 -04:00
|
|
|
|
2015-07-08 21:20:45 -03:00
|
|
|
if (!check_generate) {
|
|
|
|
logreader.set_save_chek_messages(true);
|
|
|
|
}
|
|
|
|
|
2015-06-18 22:57:19 -03:00
|
|
|
// _parse_command_line sets up an FPE handler. We can do better:
|
|
|
|
signal(SIGFPE, _replay_sig_fpe);
|
|
|
|
|
2014-02-22 17:17:01 -04:00
|
|
|
hal.console->printf("Processing log %s\n", filename);
|
2015-06-12 21:23:12 -03:00
|
|
|
|
2015-07-01 23:23:48 -03:00
|
|
|
// remember filename for reporting
|
|
|
|
log_filename = filename;
|
|
|
|
|
2015-07-04 02:14:14 -03:00
|
|
|
if (!find_log_info(log_info)) {
|
|
|
|
printf("Update to get log information\n");
|
|
|
|
exit(1);
|
2015-06-12 21:23:12 -03:00
|
|
|
}
|
|
|
|
|
2015-07-04 02:14:14 -03:00
|
|
|
hal.console->printf("Using an update rate of %u Hz\n", log_info.update_rate);
|
2014-02-28 23:24:51 -04:00
|
|
|
|
2015-06-01 03:14:11 -03:00
|
|
|
if (!logreader.open_log(filename)) {
|
2014-02-28 23:24:51 -04:00
|
|
|
perror(filename);
|
|
|
|
exit(1);
|
|
|
|
}
|
2013-12-29 07:56:30 -04:00
|
|
|
|
2015-06-20 09:30:00 -03:00
|
|
|
_vehicle.setup();
|
2015-07-04 02:14:14 -03:00
|
|
|
set_ins_update_rate(log_info.update_rate);
|
2013-12-29 07:56:30 -04:00
|
|
|
|
2014-04-21 02:22:42 -03:00
|
|
|
feenableexcept(FE_INVALID | FE_OVERFLOW);
|
|
|
|
|
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-10-14 19:17:22 -03:00
|
|
|
fprintf(plotf, "time SIM.Roll SIM.Pitch SIM.Yaw BAR.Alt FLIGHT.Roll FLIGHT.Pitch FLIGHT.Yaw FLIGHT.dN FLIGHT.dE FLIGHT.Alt AHR2.Roll AHR2.Pitch AHR2.Yaw 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
|
|
|
}
|
|
|
|
|
2015-06-25 01:17:00 -03:00
|
|
|
void Replay::set_ins_update_rate(uint16_t _update_rate) {
|
2015-07-04 02:14:14 -03:00
|
|
|
switch (_update_rate) {
|
2015-06-20 09:30:00 -03:00
|
|
|
case 50:
|
|
|
|
_vehicle.ins.init(AP_InertialSensor::WARM_START, AP_InertialSensor::RATE_50HZ);
|
|
|
|
break;
|
|
|
|
case 100:
|
|
|
|
_vehicle.ins.init(AP_InertialSensor::WARM_START, AP_InertialSensor::RATE_100HZ);
|
|
|
|
break;
|
|
|
|
case 200:
|
|
|
|
_vehicle.ins.init(AP_InertialSensor::WARM_START, AP_InertialSensor::RATE_200HZ);
|
|
|
|
break;
|
|
|
|
case 400:
|
|
|
|
_vehicle.ins.init(AP_InertialSensor::WARM_START, AP_InertialSensor::RATE_400HZ);
|
|
|
|
break;
|
|
|
|
default:
|
2015-06-25 01:17:00 -03:00
|
|
|
printf("Invalid update rate (%d); use 50, 100, 200 or 400\n", _update_rate);
|
2015-06-20 09:30:00 -03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-01 00:15:46 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
setup user -p parameters
|
|
|
|
*/
|
2015-06-01 03:14:11 -03:00
|
|
|
void Replay::set_user_parameters(void)
|
2014-03-01 00:15:46 -04:00
|
|
|
{
|
|
|
|
for (uint8_t i=0; i<num_user_parameters; i++) {
|
2015-06-01 03:14:11 -03:00
|
|
|
if (!logreader.set_parameter(user_parameters[i].name, user_parameters[i].value)) {
|
2014-03-01 00:15:46 -04:00
|
|
|
::printf("Failed to set parameter %s to %f\n", user_parameters[i].name, user_parameters[i].value);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-01 03:14:11 -03:00
|
|
|
void Replay::read_sensors(const char *type)
|
2014-01-04 20:39:43 -04:00
|
|
|
{
|
2015-05-09 19:20:32 -03:00
|
|
|
if (!done_parameters && !streq(type,"FMT") && !streq(type,"PARM")) {
|
2014-03-01 00:15:46 -04:00
|
|
|
done_parameters = true;
|
|
|
|
set_user_parameters();
|
|
|
|
}
|
2015-06-16 01:26:07 -03:00
|
|
|
if (use_imt && streq(type,"IMT")) {
|
2015-06-15 05:13:23 -03:00
|
|
|
have_imt = true;
|
|
|
|
}
|
2015-06-16 01:26:07 -03:00
|
|
|
if (use_imt && streq(type,"IMT2")) {
|
2015-06-15 05:13:23 -03:00
|
|
|
have_imt2 = true;
|
|
|
|
}
|
2015-04-20 02:07:13 -03:00
|
|
|
|
2015-07-04 02:14:14 -03:00
|
|
|
if (!done_home_init) {
|
|
|
|
if (streq(type, "GPS") &&
|
|
|
|
(_vehicle.gps.status() >= AP_GPS::GPS_OK_FIX_3D) && done_baro_init) {
|
|
|
|
const Location &loc = _vehicle.gps.location();
|
|
|
|
::printf("GPS Lock at %.7f %.7f %.2fm time=%.1f seconds\n",
|
|
|
|
loc.lat * 1.0e-7f,
|
|
|
|
loc.lng * 1.0e-7f,
|
|
|
|
loc.alt * 0.01f,
|
|
|
|
hal.scheduler->millis()*0.001f);
|
|
|
|
_vehicle.ahrs.set_home(loc);
|
|
|
|
_vehicle.compass.set_initial_location(loc.lat, loc.lng);
|
|
|
|
done_home_init = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-09 19:20:32 -03:00
|
|
|
if (streq(type,"GPS")) {
|
2015-06-20 09:30:00 -03:00
|
|
|
_vehicle.gps.update();
|
|
|
|
if (_vehicle.gps.status() >= AP_GPS::GPS_OK_FIX_3D) {
|
|
|
|
_vehicle.ahrs.estimate_wind();
|
2014-02-17 18:11:46 -04:00
|
|
|
}
|
2015-05-09 19:20:32 -03:00
|
|
|
} else if (streq(type,"MAG")) {
|
2015-06-20 09:30:00 -03:00
|
|
|
_vehicle.compass.read();
|
2015-05-09 19:20:32 -03:00
|
|
|
} else if (streq(type,"ARSP")) {
|
2015-06-20 09:30:00 -03:00
|
|
|
_vehicle.ahrs.set_airspeed(&_vehicle.airspeed);
|
2015-05-09 19:20:32 -03:00
|
|
|
} else if (streq(type,"BARO")) {
|
2015-06-20 09:30:00 -03:00
|
|
|
_vehicle.barometer.update();
|
2015-04-20 02:07:13 -03:00
|
|
|
if (!done_baro_init) {
|
|
|
|
done_baro_init = true;
|
|
|
|
::printf("Barometer initialised\n");
|
2015-06-20 09:30:00 -03:00
|
|
|
_vehicle.barometer.update_calibration();
|
2015-04-20 02:07:13 -03:00
|
|
|
}
|
2015-05-27 08:20:38 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool run_ahrs = false;
|
|
|
|
if (streq(type,"FRAM")) {
|
|
|
|
if (!have_fram) {
|
|
|
|
have_fram = true;
|
|
|
|
printf("Have FRAM framing\n");
|
|
|
|
}
|
|
|
|
run_ahrs = true;
|
2015-04-20 02:07:13 -03:00
|
|
|
}
|
|
|
|
|
2015-06-15 05:13:23 -03:00
|
|
|
if (have_imt) {
|
|
|
|
if ((streq(type,"IMT") && !have_imt2) ||
|
|
|
|
(streq(type,"IMT2") && have_imt2)) {
|
|
|
|
run_ahrs = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-20 02:07:13 -03:00
|
|
|
// special handling of IMU messages as these trigger an ahrs.update()
|
2015-05-27 08:20:38 -03:00
|
|
|
if (!have_fram &&
|
2015-06-15 05:13:23 -03:00
|
|
|
!have_imt &&
|
2015-07-04 02:14:14 -03:00
|
|
|
((streq(type,"IMU") && !log_info.have_imu2) || (streq(type, "IMU2") && log_info.have_imu2))) {
|
2015-05-27 08:20:38 -03:00
|
|
|
run_ahrs = true;
|
|
|
|
}
|
2015-06-26 02:12:17 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
always run AHRS on CHECK messages when checking the solution
|
|
|
|
*/
|
|
|
|
if (check_solution) {
|
|
|
|
run_ahrs = streq(type, "CHEK");
|
|
|
|
}
|
|
|
|
|
2015-05-27 08:20:38 -03:00
|
|
|
if (run_ahrs) {
|
2015-06-20 09:30:00 -03:00
|
|
|
_vehicle.ahrs.update();
|
|
|
|
if (_vehicle.ahrs.get_home().lat != 0) {
|
|
|
|
_vehicle.inertial_nav.update(_vehicle.ins.get_delta_time());
|
2015-04-20 02:07:13 -03:00
|
|
|
}
|
2015-07-07 02:55:41 -03:00
|
|
|
if (downsample == 0 || ++output_counter % downsample == 0) {
|
|
|
|
if (!LogReader::in_list("EKF", nottypes)) {
|
|
|
|
_vehicle.dataflash.Log_Write_EKF(_vehicle.ahrs,false);
|
|
|
|
}
|
|
|
|
if (!LogReader::in_list("AHRS2", nottypes)) {
|
|
|
|
_vehicle.dataflash.Log_Write_AHRS2(_vehicle.ahrs);
|
|
|
|
}
|
|
|
|
if (!LogReader::in_list("POS", nottypes)) {
|
|
|
|
_vehicle.dataflash.Log_Write_POS(_vehicle.ahrs);
|
|
|
|
}
|
2015-07-07 02:13:51 -03:00
|
|
|
}
|
2015-06-20 09:30:00 -03:00
|
|
|
if (_vehicle.ahrs.healthy() != ahrs_healthy) {
|
|
|
|
ahrs_healthy = _vehicle.ahrs.healthy();
|
2015-05-19 02:21:12 -03:00
|
|
|
printf("AHRS health: %u at %lu\n",
|
|
|
|
(unsigned)ahrs_healthy,
|
|
|
|
(unsigned long)hal.scheduler->millis());
|
2014-01-05 01:37:47 -04:00
|
|
|
}
|
2015-06-26 02:12:17 -03:00
|
|
|
if (check_generate) {
|
|
|
|
log_check_generate();
|
|
|
|
} else if (check_solution) {
|
|
|
|
log_check_solution();
|
2015-06-25 01:17:00 -03:00
|
|
|
}
|
2013-12-29 08:21:09 -04:00
|
|
|
}
|
2013-12-29 07:56:30 -04:00
|
|
|
}
|
|
|
|
|
2015-06-25 01:17:00 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
copy current data to CHEK message
|
|
|
|
*/
|
2015-06-26 02:12:17 -03:00
|
|
|
void Replay::log_check_generate(void)
|
2015-06-25 01:17:00 -03:00
|
|
|
{
|
|
|
|
Vector3f euler;
|
|
|
|
Vector3f velocity;
|
|
|
|
Location loc {};
|
|
|
|
|
|
|
|
_vehicle.EKF.getEulerAngles(euler);
|
|
|
|
_vehicle.EKF.getVelNED(velocity);
|
|
|
|
_vehicle.EKF.getLLH(loc);
|
|
|
|
|
|
|
|
struct log_Chek packet = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_CHEK_MSG),
|
|
|
|
time_us : hal.scheduler->micros64(),
|
|
|
|
roll : (int16_t)(100*degrees(euler.x)), // roll angle (centi-deg, displayed as deg due to format string)
|
|
|
|
pitch : (int16_t)(100*degrees(euler.y)), // pitch angle (centi-deg, displayed as deg due to format string)
|
|
|
|
yaw : (uint16_t)wrap_360_cd(100*degrees(euler.z)), // yaw angle (centi-deg, displayed as deg due to format string)
|
|
|
|
lat : loc.lat,
|
|
|
|
lng : loc.lng,
|
|
|
|
alt : loc.alt*0.01f,
|
|
|
|
vnorth : velocity.x,
|
|
|
|
veast : velocity.y,
|
|
|
|
vdown : velocity.z
|
|
|
|
};
|
|
|
|
|
|
|
|
_vehicle.dataflash.WriteBlock(&packet, sizeof(packet));
|
|
|
|
}
|
|
|
|
|
2015-06-26 02:12:17 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
check current solution against CHEK message
|
|
|
|
*/
|
|
|
|
void Replay::log_check_solution(void)
|
|
|
|
{
|
|
|
|
const LR_MsgHandler::CheckState &check_state = logreader.get_check_state();
|
|
|
|
Vector3f euler;
|
|
|
|
Vector3f velocity;
|
|
|
|
Location loc {};
|
|
|
|
|
|
|
|
_vehicle.EKF.getEulerAngles(euler);
|
|
|
|
_vehicle.EKF.getVelNED(velocity);
|
|
|
|
_vehicle.EKF.getLLH(loc);
|
|
|
|
|
|
|
|
float roll_error = degrees(fabsf(euler.x - check_state.euler.x));
|
|
|
|
float pitch_error = degrees(fabsf(euler.y - check_state.euler.y));
|
2015-07-01 07:43:29 -03:00
|
|
|
float yaw_error = wrap_180_cd_float(100*degrees(fabsf(euler.z - check_state.euler.z)))*0.01f;
|
2015-06-26 02:12:17 -03:00
|
|
|
float vel_error = (velocity - check_state.velocity).length();
|
|
|
|
float pos_error = get_distance(check_state.pos, loc);
|
|
|
|
|
|
|
|
check_result.max_roll_error = max(check_result.max_roll_error, roll_error);
|
|
|
|
check_result.max_pitch_error = max(check_result.max_pitch_error, pitch_error);
|
|
|
|
check_result.max_yaw_error = max(check_result.max_yaw_error, yaw_error);
|
|
|
|
check_result.max_vel_error = max(check_result.max_vel_error, vel_error);
|
|
|
|
check_result.max_pos_error = max(check_result.max_pos_error, pos_error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-01 03:14:11 -03:00
|
|
|
void Replay::loop()
|
2013-12-29 07:56:30 -04:00
|
|
|
{
|
|
|
|
while (true) {
|
2015-05-10 22:16:05 -03:00
|
|
|
char type[5];
|
2014-04-21 00:00:59 -03:00
|
|
|
|
2015-06-02 23:31:21 -03:00
|
|
|
if (arm_time_ms >= 0 && hal.scheduler->millis() > (uint32_t)arm_time_ms) {
|
2015-01-28 19:45:14 -04:00
|
|
|
if (!hal.util->get_soft_armed()) {
|
|
|
|
hal.util->set_soft_armed(true);
|
2014-04-21 00:00:59 -03:00
|
|
|
::printf("Arming at %u ms\n", (unsigned)hal.scheduler->millis());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-01 03:14:11 -03: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);
|
2015-06-26 02:12:17 -03:00
|
|
|
break;
|
2013-12-29 07:56:30 -04:00
|
|
|
}
|
2014-01-04 20:39:43 -04:00
|
|
|
read_sensors(type);
|
2013-12-29 07:56:30 -04:00
|
|
|
|
2015-05-09 19:20:32 -03:00
|
|
|
if (streq(type,"ATT")) {
|
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;
|
2014-10-30 20:47:57 -03:00
|
|
|
float accelWeighting;
|
|
|
|
float accelZBias1;
|
|
|
|
float accelZBias2;
|
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;
|
2014-01-30 18:27:56 -04:00
|
|
|
|
2015-06-20 09:30:00 -03:00
|
|
|
const Matrix3f &dcm_matrix = _vehicle.ahrs.AP_AHRS_DCM::get_dcm_matrix();
|
2014-03-01 17:00:13 -04:00
|
|
|
dcm_matrix.to_euler(&DCM_attitude.x, &DCM_attitude.y, &DCM_attitude.z);
|
2015-06-20 09:30:00 -03:00
|
|
|
_vehicle.EKF.getEulerAngles(ekf_euler);
|
|
|
|
_vehicle.EKF.getVelNED(velNED);
|
|
|
|
_vehicle.EKF.getPosNED(posNED);
|
|
|
|
_vehicle.EKF.getGyroBias(gyroBias);
|
|
|
|
_vehicle.EKF.getIMU1Weighting(accelWeighting);
|
|
|
|
_vehicle.EKF.getAccelZBias(accelZBias1, accelZBias2);
|
|
|
|
_vehicle.EKF.getWind(windVel);
|
|
|
|
_vehicle.EKF.getMagNED(magNED);
|
|
|
|
_vehicle.EKF.getMagXYZ(magXYZ);
|
|
|
|
_vehicle.EKF.getInnovations(velInnov, posInnov, magInnov, tasInnov);
|
|
|
|
_vehicle.EKF.getVariances(velVar, posVar, hgtVar, magVar, tasVar, offset);
|
|
|
|
_vehicle.EKF.getFilterFaults(faultStatus);
|
|
|
|
_vehicle.EKF.getPosNED(ekf_relpos);
|
|
|
|
Vector3f inav_pos = _vehicle.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-10-19 05:41:57 -03:00
|
|
|
fprintf(plotf, "%.3f %.1f %.1f %.1f %.2f %.1f %.1f %.1f %.2f %.2f %.2f %.1f %.1f %.1f %.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,
|
2015-06-01 03:14:11 -03:00
|
|
|
logreader.get_sim_attitude().x,
|
|
|
|
logreader.get_sim_attitude().y,
|
|
|
|
logreader.get_sim_attitude().z,
|
2015-06-20 09:30:00 -03:00
|
|
|
_vehicle.barometer.get_altitude(),
|
2015-06-01 03:14:11 -03:00
|
|
|
logreader.get_attitude().x,
|
|
|
|
logreader.get_attitude().y,
|
|
|
|
wrap_180_cd(logreader.get_attitude().z*100)*0.01f,
|
|
|
|
logreader.get_inavpos().x,
|
|
|
|
logreader.get_inavpos().y,
|
|
|
|
logreader.get_relalt(),
|
|
|
|
logreader.get_ahr2_attitude().x,
|
|
|
|
logreader.get_ahr2_attitude().y,
|
|
|
|
wrap_180_cd(logreader.get_ahr2_attitude().z*100)*0.01f,
|
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,
|
2015-06-01 03:14:11 -03:00
|
|
|
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
|
2014-12-08 17:19:46 -04:00
|
|
|
float gyrX = (float)(6000*degrees(gyroBias.x)); // centi-deg/min
|
|
|
|
float gyrY = (float)(6000*degrees(gyroBias.y)); // centi-deg/min
|
|
|
|
float gyrZ = (float)(6000*degrees(gyroBias.z)); // centi-deg/min
|
2014-01-30 18:27:56 -04:00
|
|
|
|
|
|
|
// print EKF1 data packet
|
2014-12-08 17:19:46 -04:00
|
|
|
fprintf(ekf1f, "%.3f %u %d %d %u %.2f %.2f %.2f %.2f %.2f %.2f %.0f %.0f %.0f\n",
|
2014-01-30 18:27:56 -04:00
|
|
|
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
|
2014-10-30 20:47:57 -03:00
|
|
|
int8_t accWeight = (int8_t)(100*accelWeighting);
|
|
|
|
int8_t acc1 = (int8_t)(100*accelZBias1);
|
|
|
|
int8_t acc2 = (int8_t)(100*accelZBias2);
|
2014-01-30 18:27:56 -04:00
|
|
|
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(),
|
2014-10-30 20:47:57 -03:00
|
|
|
accWeight,
|
|
|
|
acc1,
|
|
|
|
acc2,
|
2014-01-30 18:27:56 -04:00
|
|
|
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-01-30 18:27:56 -04:00
|
|
|
|
|
|
|
// print EKF4 data packet
|
2015-01-02 20:53:10 -04:00
|
|
|
fprintf(ekf4f, "%.3f %u %d %d %d %d %d %d %d %d %d %d\n",
|
2014-01-30 18:27:56 -04:00
|
|
|
hal.scheduler->millis() * 0.001f,
|
2015-01-02 20:53:10 -04:00
|
|
|
(unsigned)hal.scheduler->millis(),
|
|
|
|
(int)sqrtvarV,
|
|
|
|
(int)sqrtvarP,
|
|
|
|
(int)sqrtvarH,
|
|
|
|
(int)sqrtvarMX,
|
|
|
|
(int)sqrtvarMY,
|
|
|
|
(int)sqrtvarMZ,
|
|
|
|
(int)sqrtvarVT,
|
|
|
|
(int)offsetNorth,
|
|
|
|
(int)offsetEast,
|
|
|
|
(int)faultStatus);
|
2013-12-29 07:56:30 -04:00
|
|
|
}
|
|
|
|
}
|
2015-06-26 02:12:17 -03:00
|
|
|
|
2015-07-04 02:14:14 -03:00
|
|
|
flush_dataflash();
|
|
|
|
|
2015-06-26 02:12:17 -03:00
|
|
|
if (check_solution) {
|
|
|
|
report_checks();
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2015-07-04 02:14:14 -03:00
|
|
|
|
|
|
|
bool Replay::show_error(const char *text, float max_error, float tolerance)
|
|
|
|
{
|
|
|
|
bool failed = max_error > tolerance;
|
|
|
|
printf("%s:\t%.2f %c %.2f\n",
|
|
|
|
text,
|
|
|
|
max_error,
|
|
|
|
failed?'>':'<',
|
|
|
|
tolerance);
|
|
|
|
return failed;
|
|
|
|
}
|
|
|
|
|
2015-06-26 02:12:17 -03:00
|
|
|
/*
|
|
|
|
report results of --check
|
|
|
|
*/
|
|
|
|
void Replay::report_checks(void)
|
|
|
|
{
|
|
|
|
bool failed = false;
|
|
|
|
if (tolerance_euler < 0.01f) {
|
|
|
|
tolerance_euler = 0.01f;
|
|
|
|
}
|
2015-07-01 23:23:48 -03:00
|
|
|
FILE *f = fopen("replay_results.txt","a");
|
|
|
|
if (f != NULL) {
|
2015-07-02 01:27:10 -03:00
|
|
|
fprintf(f, "%s\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\n",
|
2015-07-01 23:23:48 -03:00
|
|
|
log_filename,
|
|
|
|
check_result.max_roll_error,
|
|
|
|
check_result.max_pitch_error,
|
|
|
|
check_result.max_yaw_error,
|
|
|
|
check_result.max_pos_error,
|
|
|
|
check_result.max_vel_error);
|
|
|
|
fclose(f);
|
|
|
|
}
|
2015-07-04 02:14:14 -03:00
|
|
|
failed |= show_error("Roll error", check_result.max_roll_error, tolerance_euler);
|
|
|
|
failed |= show_error("Pitch error", check_result.max_pitch_error, tolerance_euler);
|
|
|
|
failed |= show_error("Yaw error", check_result.max_yaw_error, tolerance_euler);
|
|
|
|
failed |= show_error("Position error", check_result.max_pos_error, tolerance_pos);
|
|
|
|
failed |= show_error("Velocity error", check_result.max_vel_error, tolerance_vel);
|
2015-06-26 02:12:17 -03:00
|
|
|
if (failed) {
|
|
|
|
printf("Checks failed\n");
|
|
|
|
exit(1);
|
|
|
|
} else {
|
|
|
|
printf("Checks passed\n");
|
|
|
|
}
|
2013-12-29 07:56:30 -04:00
|
|
|
}
|
|
|
|
|
2015-06-01 03:14:11 -03:00
|
|
|
/*
|
|
|
|
compatibility with old pde style build
|
|
|
|
*/
|
|
|
|
void setup(void);
|
|
|
|
void loop(void);
|
|
|
|
|
|
|
|
void setup(void)
|
|
|
|
{
|
|
|
|
replay.setup();
|
|
|
|
}
|
|
|
|
void loop(void)
|
|
|
|
{
|
|
|
|
replay.loop();
|
|
|
|
}
|
|
|
|
|
2013-12-29 07:56:30 -04:00
|
|
|
AP_HAL_MAIN();
|