2015-05-29 23:12:49 -03:00
|
|
|
#include "Copter.h"
|
|
|
|
|
2011-12-23 18:26:24 -04:00
|
|
|
#if LOGGING_ENABLED == ENABLED
|
2011-07-17 07:31:07 -03:00
|
|
|
|
2019-01-18 00:23:42 -04:00
|
|
|
// Code to Write and Read packets from AP_Logger log memory
|
2010-12-19 12:40:33 -04:00
|
|
|
// Code to interact with the user to dump or erase logs
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Control_Tuning {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
2015-04-30 02:57:00 -03:00
|
|
|
uint64_t time_us;
|
2016-01-03 23:47:15 -04:00
|
|
|
float throttle_in;
|
|
|
|
float angle_boost;
|
2015-05-23 14:51:52 -03:00
|
|
|
float throttle_out;
|
2016-05-23 04:17:19 -03:00
|
|
|
float throttle_hover;
|
2014-01-13 08:31:43 -04:00
|
|
|
float desired_alt;
|
|
|
|
float inav_alt;
|
|
|
|
int32_t baro_alt;
|
2018-06-05 05:21:09 -03:00
|
|
|
float desired_rangefinder_alt;
|
2016-04-27 08:37:04 -03:00
|
|
|
int16_t rangefinder_alt;
|
2016-04-18 03:15:56 -03:00
|
|
|
float terr_alt;
|
2016-06-04 01:30:55 -03:00
|
|
|
int16_t target_climb_rate;
|
2014-01-13 08:31:43 -04:00
|
|
|
int16_t climb_rate;
|
2013-01-12 11:17:44 -04:00
|
|
|
};
|
2011-09-06 22:22:29 -03:00
|
|
|
|
2013-04-20 02:18:22 -03:00
|
|
|
// Write a control tuning packet
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::Log_Write_Control_Tuning()
|
2011-04-21 02:15:45 -03:00
|
|
|
{
|
2016-04-18 03:15:56 -03:00
|
|
|
// get terrain altitude
|
|
|
|
float terr_alt = 0.0f;
|
|
|
|
#if AP_TERRAIN_AVAILABLE && AC_TERRAIN
|
2018-04-04 08:16:34 -03:00
|
|
|
if (!terrain.height_above_terrain(terr_alt, true)) {
|
2019-01-18 00:23:42 -04:00
|
|
|
terr_alt = logger.quiet_nan();
|
2016-08-08 00:30:55 -03:00
|
|
|
}
|
2016-04-18 03:15:56 -03:00
|
|
|
#endif
|
2018-11-20 19:54:43 -04:00
|
|
|
float des_alt_m = 0.0f;
|
|
|
|
int16_t target_climb_rate_cms = 0;
|
|
|
|
if (!flightmode->has_manual_throttle()) {
|
|
|
|
des_alt_m = pos_control->get_alt_target() / 100.0f;
|
|
|
|
target_climb_rate_cms = pos_control->get_vel_target_z();
|
|
|
|
}
|
2016-04-18 03:15:56 -03:00
|
|
|
|
2018-06-05 05:21:09 -03:00
|
|
|
float _target_rangefinder_alt;
|
|
|
|
if (target_rangefinder_alt_used) {
|
|
|
|
_target_rangefinder_alt = target_rangefinder_alt * 0.01f; // cm->m
|
|
|
|
} else {
|
2019-01-18 00:23:42 -04:00
|
|
|
_target_rangefinder_alt = logger.quiet_nan();
|
2018-06-05 05:21:09 -03:00
|
|
|
}
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_Control_Tuning pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_CONTROL_TUNING_MSG),
|
2015-11-19 23:04:45 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
2017-01-09 03:31:26 -04:00
|
|
|
throttle_in : attitude_control->get_throttle_in(),
|
|
|
|
angle_boost : attitude_control->angle_boost(),
|
|
|
|
throttle_out : motors->get_throttle(),
|
|
|
|
throttle_hover : motors->get_throttle_hover(),
|
2018-11-20 19:54:43 -04:00
|
|
|
desired_alt : des_alt_m,
|
2015-02-10 08:28:30 -04:00
|
|
|
inav_alt : inertial_nav.get_altitude() / 100.0f,
|
2014-01-13 08:31:43 -04:00
|
|
|
baro_alt : baro_alt,
|
2018-06-05 05:21:09 -03:00
|
|
|
desired_rangefinder_alt : _target_rangefinder_alt,
|
2016-05-07 04:55:40 -03:00
|
|
|
rangefinder_alt : rangefinder_state.alt_cm,
|
2016-04-18 03:15:56 -03:00
|
|
|
terr_alt : terr_alt,
|
2018-11-20 19:54:43 -04:00
|
|
|
target_climb_rate : target_climb_rate_cms,
|
2014-01-13 08:31:43 -04:00
|
|
|
climb_rate : climb_rate
|
2013-01-12 11:17:44 -04:00
|
|
|
};
|
2019-01-18 00:23:42 -04:00
|
|
|
logger.WriteBlock(&pkt, sizeof(pkt));
|
2011-04-21 02:15:45 -03:00
|
|
|
}
|
|
|
|
|
2013-04-20 02:18:22 -03:00
|
|
|
// Write an attitude packet
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::Log_Write_Attitude()
|
2011-05-09 01:16:58 -03:00
|
|
|
{
|
2017-01-09 03:31:26 -04:00
|
|
|
Vector3f targets = attitude_control->get_att_target_euler_cd();
|
2016-04-27 06:35:18 -03:00
|
|
|
targets.z = wrap_360_cd(targets.z);
|
2019-01-18 00:24:08 -04:00
|
|
|
logger.Write_Attitude(ahrs, targets);
|
|
|
|
logger.Write_Rate(ahrs_view, *motors, *attitude_control, *pos_control);
|
2017-05-23 02:30:57 -03:00
|
|
|
if (should_log(MASK_LOG_PID)) {
|
2019-01-18 00:24:08 -04:00
|
|
|
logger.Write_PID(LOG_PIDR_MSG, attitude_control->get_rate_roll_pid().get_pid_info());
|
|
|
|
logger.Write_PID(LOG_PIDP_MSG, attitude_control->get_rate_pitch_pid().get_pid_info());
|
|
|
|
logger.Write_PID(LOG_PIDY_MSG, attitude_control->get_rate_yaw_pid().get_pid_info());
|
|
|
|
logger.Write_PID(LOG_PIDA_MSG, pos_control->get_accel_z_pid().get_pid_info() );
|
2017-05-23 02:30:57 -03:00
|
|
|
}
|
|
|
|
}
|
2014-01-03 20:51:57 -04:00
|
|
|
|
2017-05-23 02:30:57 -03:00
|
|
|
// Write an EKF and POS packet
|
|
|
|
void Copter::Log_Write_EKF_POS()
|
|
|
|
{
|
2019-01-18 00:24:08 -04:00
|
|
|
logger.Write_EKF(ahrs);
|
|
|
|
logger.Write_AHRS2(ahrs);
|
2015-05-04 03:18:46 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
2019-01-17 18:16:30 -04:00
|
|
|
sitl.Log_Write_SIMSTATE();
|
2014-01-03 20:51:57 -04:00
|
|
|
#endif
|
2019-01-18 00:24:08 -04:00
|
|
|
logger.Write_POS(ahrs);
|
2011-05-09 01:16:58 -03:00
|
|
|
}
|
|
|
|
|
2015-03-18 09:08:30 -03:00
|
|
|
struct PACKED log_MotBatt {
|
|
|
|
LOG_PACKET_HEADER;
|
2015-04-30 02:57:00 -03:00
|
|
|
uint64_t time_us;
|
2015-03-18 09:08:30 -03:00
|
|
|
float lift_max;
|
|
|
|
float bat_volt;
|
|
|
|
float bat_res;
|
|
|
|
float th_limit;
|
|
|
|
};
|
|
|
|
|
2015-03-04 02:21:01 -04:00
|
|
|
// Write an rate packet
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::Log_Write_MotBatt()
|
2015-03-04 02:21:01 -04:00
|
|
|
{
|
2015-07-15 04:27:45 -03:00
|
|
|
#if FRAME_CONFIG != HELI_FRAME
|
2015-03-18 09:08:30 -03:00
|
|
|
struct log_MotBatt pkt_mot = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_MOTBATT_MSG),
|
2015-11-19 23:04:45 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
2017-01-09 03:31:26 -04:00
|
|
|
lift_max : (float)(motors->get_lift_max()),
|
|
|
|
bat_volt : (float)(motors->get_batt_voltage_filt()),
|
2018-02-28 19:32:16 -04:00
|
|
|
bat_res : (float)(battery.get_resistance()),
|
2017-01-09 03:31:26 -04:00
|
|
|
th_limit : (float)(motors->get_throttle_limit())
|
2015-03-04 02:21:01 -04:00
|
|
|
};
|
2019-01-18 00:23:42 -04:00
|
|
|
logger.WriteBlock(&pkt_mot, sizeof(pkt_mot));
|
2015-07-15 04:27:45 -03:00
|
|
|
#endif
|
2015-03-04 02:21:01 -04:00
|
|
|
}
|
|
|
|
|
2013-01-12 11:17:44 -04:00
|
|
|
// Wrote an event packet
|
2019-02-01 07:30:00 -04:00
|
|
|
void Copter::Log_Write_Event(Log_Event id)
|
2011-11-19 20:57:10 -04:00
|
|
|
{
|
2019-02-01 07:30:00 -04:00
|
|
|
logger.Write_Event(id);
|
2012-11-10 02:04:23 -04:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Data_Int16t {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
2015-04-30 02:57:00 -03:00
|
|
|
uint64_t time_us;
|
2013-01-12 11:17:44 -04:00
|
|
|
uint8_t id;
|
|
|
|
int16_t data_value;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Write an int16_t data packet
|
2015-02-17 20:13:48 -04:00
|
|
|
UNUSED_FUNCTION
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::Log_Write_Data(uint8_t id, int16_t value)
|
2011-11-19 20:57:10 -04:00
|
|
|
{
|
2014-10-16 21:37:49 -03:00
|
|
|
if (should_log(MASK_LOG_ANY)) {
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_Data_Int16t pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_DATA_INT16_MSG),
|
2015-11-19 23:04:45 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
2013-01-12 11:17:44 -04:00
|
|
|
id : id,
|
|
|
|
data_value : value
|
|
|
|
};
|
2019-01-18 00:23:42 -04:00
|
|
|
logger.WriteCriticalBlock(&pkt, sizeof(pkt));
|
2013-01-09 08:06:40 -04:00
|
|
|
}
|
2012-11-10 02:04:23 -04:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Data_UInt16t {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
2015-04-30 02:57:00 -03:00
|
|
|
uint64_t time_us;
|
2013-01-12 11:17:44 -04:00
|
|
|
uint8_t id;
|
|
|
|
uint16_t data_value;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Write an uint16_t data packet
|
2015-02-17 20:13:48 -04:00
|
|
|
UNUSED_FUNCTION
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::Log_Write_Data(uint8_t id, uint16_t value)
|
2012-11-10 02:04:23 -04:00
|
|
|
{
|
2014-10-16 21:37:49 -03:00
|
|
|
if (should_log(MASK_LOG_ANY)) {
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_Data_UInt16t pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_DATA_UINT16_MSG),
|
2015-11-19 23:04:45 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
2013-01-12 11:17:44 -04:00
|
|
|
id : id,
|
|
|
|
data_value : value
|
|
|
|
};
|
2019-01-18 00:23:42 -04:00
|
|
|
logger.WriteCriticalBlock(&pkt, sizeof(pkt));
|
2013-01-09 08:06:40 -04:00
|
|
|
}
|
2012-11-10 02:04:23 -04:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Data_Int32t {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
2015-04-30 02:57:00 -03:00
|
|
|
uint64_t time_us;
|
2013-01-12 11:17:44 -04:00
|
|
|
uint8_t id;
|
|
|
|
int32_t data_value;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Write an int32_t data packet
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::Log_Write_Data(uint8_t id, int32_t value)
|
2012-11-10 02:04:23 -04:00
|
|
|
{
|
2014-10-16 21:37:49 -03:00
|
|
|
if (should_log(MASK_LOG_ANY)) {
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_Data_Int32t pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_DATA_INT32_MSG),
|
2015-11-19 23:04:45 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
2013-01-12 11:17:44 -04:00
|
|
|
id : id,
|
|
|
|
data_value : value
|
|
|
|
};
|
2019-01-18 00:23:42 -04:00
|
|
|
logger.WriteCriticalBlock(&pkt, sizeof(pkt));
|
2013-01-09 08:06:40 -04:00
|
|
|
}
|
2011-11-19 20:57:10 -04:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Data_UInt32t {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
2015-04-30 02:57:00 -03:00
|
|
|
uint64_t time_us;
|
2013-01-12 11:17:44 -04:00
|
|
|
uint8_t id;
|
|
|
|
uint32_t data_value;
|
|
|
|
};
|
2012-11-10 02:04:23 -04:00
|
|
|
|
2013-01-12 11:17:44 -04:00
|
|
|
// Write a uint32_t data packet
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::Log_Write_Data(uint8_t id, uint32_t value)
|
2013-01-12 11:17:44 -04:00
|
|
|
{
|
2014-10-16 21:37:49 -03:00
|
|
|
if (should_log(MASK_LOG_ANY)) {
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_Data_UInt32t pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_DATA_UINT32_MSG),
|
2015-11-19 23:04:45 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
2013-01-12 11:17:44 -04:00
|
|
|
id : id,
|
|
|
|
data_value : value
|
|
|
|
};
|
2019-01-18 00:23:42 -04:00
|
|
|
logger.WriteCriticalBlock(&pkt, sizeof(pkt));
|
2013-01-12 11:17:44 -04:00
|
|
|
}
|
|
|
|
}
|
2012-11-10 02:04:23 -04:00
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Data_Float {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
2015-04-30 02:57:00 -03:00
|
|
|
uint64_t time_us;
|
2013-01-12 11:17:44 -04:00
|
|
|
uint8_t id;
|
|
|
|
float data_value;
|
|
|
|
};
|
2012-11-10 02:04:23 -04:00
|
|
|
|
2013-01-12 11:17:44 -04:00
|
|
|
// Write a float data packet
|
2015-02-17 20:13:48 -04:00
|
|
|
UNUSED_FUNCTION
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::Log_Write_Data(uint8_t id, float value)
|
2013-01-12 11:17:44 -04:00
|
|
|
{
|
2014-10-16 21:37:49 -03:00
|
|
|
if (should_log(MASK_LOG_ANY)) {
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_Data_Float pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_DATA_FLOAT_MSG),
|
2015-11-19 23:04:45 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
2013-01-12 11:17:44 -04:00
|
|
|
id : id,
|
|
|
|
data_value : value
|
|
|
|
};
|
2019-01-18 00:23:42 -04:00
|
|
|
logger.WriteCriticalBlock(&pkt, sizeof(pkt));
|
2012-08-21 23:19:50 -03:00
|
|
|
}
|
2011-11-19 20:57:10 -04:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:51:09 -03:00
|
|
|
struct PACKED log_Error {
|
2013-01-12 11:17:44 -04:00
|
|
|
LOG_PACKET_HEADER;
|
2015-04-30 02:57:00 -03:00
|
|
|
uint64_t time_us;
|
2013-01-12 11:17:44 -04:00
|
|
|
uint8_t sub_system;
|
|
|
|
uint8_t error_code;
|
|
|
|
};
|
|
|
|
|
2013-04-20 02:18:22 -03:00
|
|
|
// Write an error packet
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::Log_Write_Error(uint8_t sub_system, uint8_t error_code)
|
2012-12-29 23:08:25 -04:00
|
|
|
{
|
2013-01-12 11:17:44 -04:00
|
|
|
struct log_Error pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_ERROR_MSG),
|
2015-11-19 23:04:45 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
2013-01-12 11:17:44 -04:00
|
|
|
sub_system : sub_system,
|
|
|
|
error_code : error_code,
|
|
|
|
};
|
2019-01-18 00:23:42 -04:00
|
|
|
logger.WriteCriticalBlock(&pkt, sizeof(pkt));
|
2012-12-29 23:08:25 -04:00
|
|
|
}
|
|
|
|
|
2015-04-26 21:29:04 -03:00
|
|
|
struct PACKED log_ParameterTuning {
|
|
|
|
LOG_PACKET_HEADER;
|
2015-04-30 02:57:00 -03:00
|
|
|
uint64_t time_us;
|
2015-04-26 21:29:04 -03:00
|
|
|
uint8_t parameter; // parameter we are tuning, e.g. 39 is CH6_CIRCLE_RATE
|
|
|
|
float tuning_value; // normalized value used inside tuning() function
|
|
|
|
int16_t control_in; // raw tune input value
|
|
|
|
int16_t tuning_low; // tuning low end value
|
|
|
|
int16_t tuning_high; // tuning high end value
|
|
|
|
};
|
|
|
|
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::Log_Write_Parameter_Tuning(uint8_t param, float tuning_val, int16_t control_in, int16_t tune_low, int16_t tune_high)
|
2015-04-26 21:29:04 -03:00
|
|
|
{
|
|
|
|
struct log_ParameterTuning pkt_tune = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_PARAMTUNE_MSG),
|
2015-11-19 23:04:45 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
2015-04-26 21:29:04 -03:00
|
|
|
parameter : param,
|
|
|
|
tuning_value : tuning_val,
|
|
|
|
control_in : control_in,
|
|
|
|
tuning_low : tune_low,
|
|
|
|
tuning_high : tune_high
|
|
|
|
};
|
|
|
|
|
2019-01-18 00:23:42 -04:00
|
|
|
logger.WriteBlock(&pkt_tune, sizeof(pkt_tune));
|
2015-04-26 21:29:04 -03:00
|
|
|
}
|
|
|
|
|
2015-07-12 10:06:21 -03:00
|
|
|
// logs when baro or compass becomes unhealthy
|
|
|
|
void Copter::Log_Sensor_Health()
|
|
|
|
{
|
|
|
|
// check baro
|
|
|
|
if (sensor_health.baro != barometer.healthy()) {
|
|
|
|
sensor_health.baro = barometer.healthy();
|
|
|
|
Log_Write_Error(ERROR_SUBSYSTEM_BARO, (sensor_health.baro ? ERROR_CODE_ERROR_RESOLVED : ERROR_CODE_UNHEALTHY));
|
|
|
|
}
|
|
|
|
|
|
|
|
// check compass
|
|
|
|
if (sensor_health.compass != compass.healthy()) {
|
|
|
|
sensor_health.compass = compass.healthy();
|
|
|
|
Log_Write_Error(ERROR_SUBSYSTEM_COMPASS, (sensor_health.compass ? ERROR_CODE_ERROR_RESOLVED : ERROR_CODE_UNHEALTHY));
|
|
|
|
}
|
2017-03-08 20:16:25 -04:00
|
|
|
|
|
|
|
// check primary GPS
|
|
|
|
if (sensor_health.primary_gps != gps.primary_sensor()) {
|
|
|
|
sensor_health.primary_gps = gps.primary_sensor();
|
|
|
|
Log_Write_Event(DATA_GPS_PRIMARY_CHANGED);
|
|
|
|
}
|
2015-07-12 10:06:21 -03:00
|
|
|
}
|
|
|
|
|
2015-06-18 18:09:39 -03:00
|
|
|
struct PACKED log_Heli {
|
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
uint64_t time_us;
|
2016-02-03 05:02:41 -04:00
|
|
|
float desired_rotor_speed;
|
|
|
|
float main_rotor_speed;
|
2015-06-18 18:09:39 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
#if FRAME_CONFIG == HELI_FRAME
|
|
|
|
// Write an helicopter packet
|
|
|
|
void Copter::Log_Write_Heli()
|
|
|
|
{
|
|
|
|
struct log_Heli pkt_heli = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_HELI_MSG),
|
2015-11-19 23:04:45 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
2017-01-09 03:31:26 -04:00
|
|
|
desired_rotor_speed : motors->get_desired_rotor_speed(),
|
|
|
|
main_rotor_speed : motors->get_main_rotor_speed(),
|
2015-06-18 18:09:39 -03:00
|
|
|
};
|
2019-01-18 00:23:42 -04:00
|
|
|
logger.WriteBlock(&pkt_heli, sizeof(pkt_heli));
|
2015-06-18 18:09:39 -03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-08-28 05:14:02 -03:00
|
|
|
// precision landing logging
|
|
|
|
struct PACKED log_Precland {
|
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
uint64_t time_us;
|
|
|
|
uint8_t healthy;
|
2016-07-15 14:21:10 -03:00
|
|
|
uint8_t target_acquired;
|
2015-08-28 05:14:02 -03:00
|
|
|
float pos_x;
|
|
|
|
float pos_y;
|
2016-07-15 14:21:10 -03:00
|
|
|
float vel_x;
|
|
|
|
float vel_y;
|
2018-08-07 22:31:16 -03:00
|
|
|
float meas_x;
|
|
|
|
float meas_y;
|
|
|
|
float meas_z;
|
|
|
|
uint32_t last_meas;
|
|
|
|
uint32_t ekf_outcount;
|
|
|
|
uint8_t estimator;
|
2015-08-28 05:14:02 -03:00
|
|
|
};
|
|
|
|
|
2018-08-07 22:31:16 -03:00
|
|
|
// Write a precision landing entry
|
2015-08-28 05:14:02 -03:00
|
|
|
void Copter::Log_Write_Precland()
|
|
|
|
{
|
|
|
|
#if PRECISION_LANDING == ENABLED
|
|
|
|
// exit immediately if not enabled
|
|
|
|
if (!precland.enabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-07 22:31:16 -03:00
|
|
|
Vector3f target_pos_meas = Vector3f(0.0f,0.0f,0.0f);
|
2016-07-15 14:21:10 -03:00
|
|
|
Vector2f target_pos_rel = Vector2f(0.0f,0.0f);
|
|
|
|
Vector2f target_vel_rel = Vector2f(0.0f,0.0f);
|
|
|
|
precland.get_target_position_relative_cm(target_pos_rel);
|
|
|
|
precland.get_target_velocity_relative_cms(target_vel_rel);
|
2018-08-07 22:31:16 -03:00
|
|
|
precland.get_target_position_measurement_cm(target_pos_meas);
|
2016-07-15 14:21:10 -03:00
|
|
|
|
2015-08-28 05:14:02 -03:00
|
|
|
struct log_Precland pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_PRECLAND_MSG),
|
2015-11-19 23:04:45 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
2015-08-28 05:14:02 -03:00
|
|
|
healthy : precland.healthy(),
|
2016-07-15 14:21:10 -03:00
|
|
|
target_acquired : precland.target_acquired(),
|
|
|
|
pos_x : target_pos_rel.x,
|
|
|
|
pos_y : target_pos_rel.y,
|
|
|
|
vel_x : target_vel_rel.x,
|
2018-08-07 22:31:16 -03:00
|
|
|
vel_y : target_vel_rel.y,
|
|
|
|
meas_x : target_pos_meas.x,
|
|
|
|
meas_y : target_pos_meas.y,
|
|
|
|
meas_z : target_pos_meas.z,
|
|
|
|
last_meas : precland.last_backend_los_meas_ms(),
|
|
|
|
ekf_outcount : precland.ekf_outlier_count(),
|
|
|
|
estimator : precland.estimator_type()
|
2015-08-28 05:14:02 -03:00
|
|
|
};
|
2019-01-18 00:23:42 -04:00
|
|
|
logger.WriteBlock(&pkt, sizeof(pkt));
|
2015-08-28 05:14:02 -03:00
|
|
|
#endif // PRECISION_LANDING == ENABLED
|
|
|
|
}
|
|
|
|
|
2018-08-07 22:31:16 -03:00
|
|
|
// guided target logging
|
2016-01-10 22:41:28 -04:00
|
|
|
struct PACKED log_GuidedTarget {
|
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
uint64_t time_us;
|
|
|
|
uint8_t type;
|
|
|
|
float pos_target_x;
|
|
|
|
float pos_target_y;
|
|
|
|
float pos_target_z;
|
|
|
|
float vel_target_x;
|
|
|
|
float vel_target_y;
|
|
|
|
float vel_target_z;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Write a Guided mode target
|
|
|
|
void Copter::Log_Write_GuidedTarget(uint8_t target_type, const Vector3f& pos_target, const Vector3f& vel_target)
|
|
|
|
{
|
|
|
|
struct log_GuidedTarget pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_GUIDEDTARGET_MSG),
|
|
|
|
time_us : AP_HAL::micros64(),
|
|
|
|
type : target_type,
|
|
|
|
pos_target_x : pos_target.x,
|
|
|
|
pos_target_y : pos_target.y,
|
|
|
|
pos_target_z : pos_target.z,
|
|
|
|
vel_target_x : vel_target.x,
|
|
|
|
vel_target_y : vel_target.y,
|
|
|
|
vel_target_z : vel_target.z
|
|
|
|
};
|
2019-01-18 00:23:42 -04:00
|
|
|
logger.WriteBlock(&pkt, sizeof(pkt));
|
2016-01-10 22:41:28 -04:00
|
|
|
}
|
|
|
|
|
2015-12-07 20:52:03 -04:00
|
|
|
// type and unit information can be found in
|
2019-01-18 00:23:42 -04:00
|
|
|
// libraries/AP_Logger/Logstructure.h; search for "log_Units" for
|
2015-12-07 20:52:03 -04:00
|
|
|
// units and "Format characters" for field type information
|
2015-10-25 14:03:46 -03:00
|
|
|
const struct LogStructure Copter::log_structure[] = {
|
2013-04-19 20:51:09 -03:00
|
|
|
LOG_COMMON_STRUCTURES,
|
2015-04-26 21:29:04 -03:00
|
|
|
{ LOG_PARAMTUNE_MSG, sizeof(log_ParameterTuning),
|
2015-12-07 20:52:03 -04:00
|
|
|
"PTUN", "QBfHHH", "TimeUS,Param,TunVal,CtrlIn,TunLo,TunHi", "s-----", "F-----" },
|
2014-01-13 08:31:43 -04:00
|
|
|
{ LOG_CONTROL_TUNING_MSG, sizeof(log_Control_Tuning),
|
2018-06-05 05:21:09 -03:00
|
|
|
"CTUN", "Qffffffefcfhh", "TimeUS,ThI,ABst,ThO,ThH,DAlt,Alt,BAlt,DSAlt,SAlt,TAlt,DCRt,CRt", "s----mmmmmmnn", "F----00B0BBBB" },
|
2015-03-18 09:08:30 -03:00
|
|
|
{ LOG_MOTBATT_MSG, sizeof(log_MotBatt),
|
2015-12-07 20:52:03 -04:00
|
|
|
"MOTB", "Qffff", "TimeUS,LiftMax,BatVolt,BatRes,ThLimit", "s-vw-", "F-00-" },
|
2013-04-19 20:51:09 -03:00
|
|
|
{ LOG_DATA_INT16_MSG, sizeof(log_Data_Int16t),
|
2015-12-07 20:52:03 -04:00
|
|
|
"D16", "QBh", "TimeUS,Id,Value", "s--", "F--" },
|
2013-04-19 20:51:09 -03:00
|
|
|
{ LOG_DATA_UINT16_MSG, sizeof(log_Data_UInt16t),
|
2015-12-07 20:52:03 -04:00
|
|
|
"DU16", "QBH", "TimeUS,Id,Value", "s--", "F--" },
|
2013-04-19 20:51:09 -03:00
|
|
|
{ LOG_DATA_INT32_MSG, sizeof(log_Data_Int32t),
|
2015-12-07 20:52:03 -04:00
|
|
|
"D32", "QBi", "TimeUS,Id,Value", "s--", "F--" },
|
2013-04-19 20:51:09 -03:00
|
|
|
{ LOG_DATA_UINT32_MSG, sizeof(log_Data_UInt32t),
|
2015-12-07 20:52:03 -04:00
|
|
|
"DU32", "QBI", "TimeUS,Id,Value", "s--", "F--" },
|
2013-04-19 20:51:09 -03:00
|
|
|
{ LOG_DATA_FLOAT_MSG, sizeof(log_Data_Float),
|
2015-12-07 20:52:03 -04:00
|
|
|
"DFLT", "QBf", "TimeUS,Id,Value", "s--", "F--" },
|
2013-04-19 20:51:09 -03:00
|
|
|
{ LOG_ERROR_MSG, sizeof(log_Error),
|
2015-12-07 20:52:03 -04:00
|
|
|
"ERR", "QBB", "TimeUS,Subsys,ECode", "s--", "F--" },
|
2018-02-22 20:06:04 -04:00
|
|
|
#if FRAME_CONFIG == HELI_FRAME
|
2015-06-18 18:09:39 -03:00
|
|
|
{ LOG_HELI_MSG, sizeof(log_Heli),
|
2015-12-07 20:52:03 -04:00
|
|
|
"HELI", "Qff", "TimeUS,DRRPM,ERRPM", "s--", "F--" },
|
2018-02-22 20:06:04 -04:00
|
|
|
#endif
|
|
|
|
#if PRECISION_LANDING == ENABLED
|
2015-08-28 05:14:02 -03:00
|
|
|
{ LOG_PRECLAND_MSG, sizeof(log_Precland),
|
2018-08-07 22:31:16 -03:00
|
|
|
"PL", "QBBfffffffIIB", "TimeUS,Heal,TAcq,pX,pY,vX,vY,mX,mY,mZ,LastMeasUS,EKFOutl,Est", "s--ddmmddms--","F--00BB00BC--" },
|
2018-02-22 20:06:04 -04:00
|
|
|
#endif
|
2016-01-10 22:41:28 -04:00
|
|
|
{ LOG_GUIDEDTARGET_MSG, sizeof(log_GuidedTarget),
|
2015-12-07 20:52:03 -04:00
|
|
|
"GUID", "QBffffff", "TimeUS,Type,pX,pY,pZ,vX,vY,vZ", "s-mmmnnn", "F-000000" },
|
2013-04-19 20:51:09 -03:00
|
|
|
};
|
2013-04-15 09:54:29 -03:00
|
|
|
|
2015-08-06 09:18:39 -03:00
|
|
|
void Copter::Log_Write_Vehicle_Startup_Messages()
|
|
|
|
{
|
2019-01-18 00:23:42 -04:00
|
|
|
// only 200(?) bytes are guaranteed by AP_Logger
|
2019-01-18 00:24:08 -04:00
|
|
|
logger.Write_MessageF("Frame: %s", get_frame_string());
|
|
|
|
logger.Write_Mode(control_mode, control_mode_reason);
|
2018-05-16 00:29:13 -03:00
|
|
|
ahrs.Log_Write_Home_And_Origin();
|
2019-01-18 00:23:42 -04:00
|
|
|
gps.Write_AP_Logger_Log_Startup_messages();
|
2015-08-06 09:18:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::log_init(void)
|
|
|
|
{
|
2019-01-18 00:23:42 -04:00
|
|
|
logger.Init(log_structure, ARRAY_SIZE(log_structure));
|
2012-08-21 23:19:50 -03:00
|
|
|
}
|
2011-12-20 01:04:51 -04:00
|
|
|
|
2015-07-31 20:06:20 -03:00
|
|
|
#else // LOGGING_ENABLED
|
|
|
|
|
|
|
|
void Copter::Log_Write_Control_Tuning() {}
|
|
|
|
void Copter::Log_Write_Performance() {}
|
|
|
|
void Copter::Log_Write_Attitude(void) {}
|
2017-05-23 02:30:57 -03:00
|
|
|
void Copter::Log_Write_EKF_POS() {}
|
2015-07-31 20:06:20 -03:00
|
|
|
void Copter::Log_Write_MotBatt() {}
|
2019-02-01 07:30:00 -04:00
|
|
|
void Copter::Log_Write_Event(Log_Event id) {}
|
2015-07-31 20:06:20 -03:00
|
|
|
void Copter::Log_Write_Data(uint8_t id, int32_t value) {}
|
|
|
|
void Copter::Log_Write_Data(uint8_t id, uint32_t value) {}
|
|
|
|
void Copter::Log_Write_Data(uint8_t id, int16_t value) {}
|
|
|
|
void Copter::Log_Write_Data(uint8_t id, uint16_t value) {}
|
|
|
|
void Copter::Log_Write_Data(uint8_t id, float value) {}
|
|
|
|
void Copter::Log_Write_Error(uint8_t sub_system, uint8_t error_code) {}
|
|
|
|
void Copter::Log_Write_Parameter_Tuning(uint8_t param, float tuning_val, int16_t control_in, int16_t tune_low, int16_t tune_high) {}
|
|
|
|
void Copter::Log_Sensor_Health() {}
|
2017-06-21 01:31:42 -03:00
|
|
|
void Copter::Log_Write_Precland() {}
|
2016-07-01 02:34:48 -03:00
|
|
|
void Copter::Log_Write_GuidedTarget(uint8_t target_type, const Vector3f& pos_target, const Vector3f& vel_target) {}
|
2017-06-21 01:31:42 -03:00
|
|
|
void Copter::Log_Write_Vehicle_Startup_Messages() {}
|
2015-07-31 20:06:20 -03:00
|
|
|
|
|
|
|
#if FRAME_CONFIG == HELI_FRAME
|
|
|
|
void Copter::Log_Write_Heli() {}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void Copter::log_init(void) {}
|
|
|
|
|
2016-01-19 01:26:14 -04:00
|
|
|
#endif // LOGGING_ENABLED
|