2013-04-19 04:49:16 -03:00
|
|
|
#include <stdlib.h>
|
2015-10-26 09:01:52 -03:00
|
|
|
|
2015-08-11 03:28:46 -03:00
|
|
|
#include <AP_AHRS/AP_AHRS.h>
|
2015-10-26 09:01:52 -03:00
|
|
|
#include <AP_Baro/AP_Baro.h>
|
2015-08-15 19:53:26 -03:00
|
|
|
#include <AP_BattMonitor/AP_BattMonitor.h>
|
2015-08-11 03:28:46 -03:00
|
|
|
#include <AP_Compass/AP_Compass.h>
|
2015-10-26 09:01:52 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include <AP_Math/AP_Math.h>
|
|
|
|
#include <AP_Param/AP_Param.h>
|
2016-03-24 22:11:11 -03:00
|
|
|
#include <AP_Motors/AP_Motors.h>
|
|
|
|
#include <AC_AttitudeControl/AC_AttitudeControl.h>
|
|
|
|
#include <AC_AttitudeControl/AC_PosControl.h>
|
2019-04-05 19:48:11 -03:00
|
|
|
#include <AP_RSSI/AP_RSSI.h>
|
2019-06-13 23:58:15 -03:00
|
|
|
#include <AP_GPS/AP_GPS.h>
|
2013-04-19 04:49:16 -03:00
|
|
|
|
2019-01-18 00:23:42 -04:00
|
|
|
#include "AP_Logger.h"
|
|
|
|
#include "AP_Logger_File.h"
|
|
|
|
#include "AP_Logger_MAVLink.h"
|
|
|
|
#include "LoggerMessageWriter.h"
|
2015-08-06 09:18:28 -03:00
|
|
|
|
2013-04-19 04:49:16 -03:00
|
|
|
extern const AP_HAL::HAL& hal;
|
2013-01-14 23:02:08 -04:00
|
|
|
|
|
|
|
|
2013-04-19 10:19:16 -03:00
|
|
|
/*
|
2015-06-25 10:53:20 -03:00
|
|
|
write a structure format to the log - should be in frontend
|
2013-04-19 10:19:16 -03:00
|
|
|
*/
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger_Backend::Fill_Format(const struct LogStructure *s, struct log_Format &pkt)
|
2013-04-19 10:19:16 -03:00
|
|
|
{
|
2013-12-20 22:56:54 -04:00
|
|
|
memset(&pkt, 0, sizeof(pkt));
|
2013-12-16 20:12:42 -04:00
|
|
|
pkt.head1 = HEAD_BYTE1;
|
|
|
|
pkt.head2 = HEAD_BYTE2;
|
|
|
|
pkt.msgid = LOG_FORMAT_MSG;
|
2015-12-23 12:06:58 -04:00
|
|
|
pkt.type = s->msg_type;
|
|
|
|
pkt.length = s->msg_len;
|
2020-07-07 00:14:35 -03:00
|
|
|
strncpy_noterm(pkt.name, s->name, sizeof(pkt.name));
|
|
|
|
strncpy_noterm(pkt.format, s->format, sizeof(pkt.format));
|
|
|
|
strncpy_noterm(pkt.labels, s->labels, sizeof(pkt.labels));
|
2013-12-16 20:12:42 -04:00
|
|
|
}
|
|
|
|
|
2015-12-07 20:51:46 -04:00
|
|
|
/*
|
|
|
|
Pack a LogStructure packet into a structure suitable to go to the logfile:
|
|
|
|
*/
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger_Backend::Fill_Format_Units(const struct LogStructure *s, struct log_Format_Units &pkt)
|
2015-12-07 20:51:46 -04:00
|
|
|
{
|
|
|
|
memset(&pkt, 0, sizeof(pkt));
|
|
|
|
pkt.head1 = HEAD_BYTE1;
|
|
|
|
pkt.head2 = HEAD_BYTE2;
|
|
|
|
pkt.msgid = LOG_FORMAT_UNITS_MSG;
|
|
|
|
pkt.time_us = AP_HAL::micros64();
|
|
|
|
pkt.format_type = s->msg_type;
|
2020-07-07 00:14:35 -03:00
|
|
|
strncpy_noterm(pkt.units, s->units, sizeof(pkt.units));
|
|
|
|
strncpy_noterm(pkt.multipliers, s->multipliers, sizeof(pkt.multipliers));
|
2015-12-07 20:51:46 -04:00
|
|
|
}
|
|
|
|
|
2013-12-16 20:12:42 -04:00
|
|
|
/*
|
|
|
|
write a structure format to the log
|
|
|
|
*/
|
2019-01-18 00:24:08 -04:00
|
|
|
bool AP_Logger_Backend::Write_Format(const struct LogStructure *s)
|
2013-12-16 20:12:42 -04:00
|
|
|
{
|
|
|
|
struct log_Format pkt;
|
2019-01-18 00:24:08 -04:00
|
|
|
Fill_Format(s, pkt);
|
2015-08-06 09:18:28 -03:00
|
|
|
return WriteCriticalBlock(&pkt, sizeof(pkt));
|
2013-04-19 10:19:16 -03:00
|
|
|
}
|
|
|
|
|
2015-12-07 20:51:46 -04:00
|
|
|
/*
|
|
|
|
write a unit definition
|
|
|
|
*/
|
2019-01-18 00:24:08 -04:00
|
|
|
bool AP_Logger_Backend::Write_Unit(const struct UnitStructure *s)
|
2015-12-07 20:51:46 -04:00
|
|
|
{
|
2019-07-02 06:31:02 -03:00
|
|
|
struct log_Unit pkt{
|
2015-12-07 20:51:46 -04:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_UNIT_MSG),
|
|
|
|
time_us : AP_HAL::micros64(),
|
|
|
|
type : s->ID,
|
|
|
|
unit : { }
|
|
|
|
};
|
2020-07-07 00:14:35 -03:00
|
|
|
strncpy_noterm(pkt.unit, s->unit, sizeof(pkt.unit));
|
2015-12-07 20:51:46 -04:00
|
|
|
|
|
|
|
return WriteCriticalBlock(&pkt, sizeof(pkt));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
write a unit-multiplier definition
|
|
|
|
*/
|
2019-01-18 00:24:08 -04:00
|
|
|
bool AP_Logger_Backend::Write_Multiplier(const struct MultiplierStructure *s)
|
2015-12-07 20:51:46 -04:00
|
|
|
{
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_Format_Multiplier pkt{
|
2015-12-07 20:51:46 -04:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_MULT_MSG),
|
|
|
|
time_us : AP_HAL::micros64(),
|
|
|
|
type : s->ID,
|
|
|
|
multiplier : s->multiplier,
|
|
|
|
};
|
|
|
|
|
|
|
|
return WriteCriticalBlock(&pkt, sizeof(pkt));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
write the units for a format to the log
|
|
|
|
*/
|
2019-01-18 00:24:08 -04:00
|
|
|
bool AP_Logger_Backend::Write_Format_Units(const struct LogStructure *s)
|
2015-12-07 20:51:46 -04:00
|
|
|
{
|
|
|
|
struct log_Format_Units pkt;
|
2019-01-18 00:24:08 -04:00
|
|
|
Fill_Format_Units(s, pkt);
|
2015-12-07 20:51:46 -04:00
|
|
|
return WriteCriticalBlock(&pkt, sizeof(pkt));
|
|
|
|
}
|
|
|
|
|
2013-04-19 04:49:16 -03:00
|
|
|
/*
|
|
|
|
write a parameter to the log
|
|
|
|
*/
|
2019-01-18 00:24:08 -04:00
|
|
|
bool AP_Logger_Backend::Write_Parameter(const char *name, float value)
|
2013-04-19 04:49:16 -03:00
|
|
|
{
|
2019-07-02 06:31:02 -03:00
|
|
|
struct log_Parameter pkt{
|
2013-04-19 04:49:16 -03:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_PARAMETER_MSG),
|
2015-11-19 23:15:08 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
2013-04-19 04:49:16 -03:00
|
|
|
name : {},
|
|
|
|
value : value
|
|
|
|
};
|
2020-07-07 00:14:35 -03:00
|
|
|
strncpy_noterm(pkt.name, name, sizeof(pkt.name));
|
2015-08-06 09:18:28 -03:00
|
|
|
return WriteCriticalBlock(&pkt, sizeof(pkt));
|
2013-04-19 04:49:16 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
write a parameter to the log
|
|
|
|
*/
|
2019-01-18 00:24:08 -04:00
|
|
|
bool AP_Logger_Backend::Write_Parameter(const AP_Param *ap,
|
2015-11-09 18:14:22 -04:00
|
|
|
const AP_Param::ParamToken &token,
|
|
|
|
enum ap_var_type type)
|
2013-04-19 04:49:16 -03:00
|
|
|
{
|
|
|
|
char name[16];
|
|
|
|
ap->copy_name_token(token, &name[0], sizeof(name), true);
|
2019-01-18 00:24:08 -04:00
|
|
|
return Write_Parameter(name, ap->cast_to_float(type));
|
2013-04-19 04:49:16 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write an GPS packet
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_GPS(uint8_t i, uint64_t time_us)
|
2013-04-19 04:49:16 -03:00
|
|
|
{
|
2018-04-11 09:17:46 -03:00
|
|
|
const AP_GPS &gps = AP::gps();
|
2016-05-05 00:37:16 -03:00
|
|
|
if (time_us == 0) {
|
|
|
|
time_us = AP_HAL::micros64();
|
|
|
|
}
|
2015-08-05 03:25:48 -03:00
|
|
|
const struct Location &loc = gps.location(i);
|
2017-05-28 04:12:50 -03:00
|
|
|
|
|
|
|
float yaw_deg=0, yaw_accuracy_deg=0;
|
|
|
|
gps.gps_yaw_deg(i, yaw_deg, yaw_accuracy_deg);
|
|
|
|
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_GPS pkt = {
|
2015-08-05 03:25:48 -03:00
|
|
|
LOG_PACKET_HEADER_INIT((uint8_t)(LOG_GPS_MSG+i)),
|
2016-05-05 00:37:16 -03:00
|
|
|
time_us : time_us,
|
2015-08-05 03:25:48 -03:00
|
|
|
status : (uint8_t)gps.status(i),
|
|
|
|
gps_week_ms : gps.time_week_ms(i),
|
|
|
|
gps_week : gps.time_week(i),
|
|
|
|
num_sats : gps.num_sats(i),
|
|
|
|
hdop : gps.get_hdop(i),
|
|
|
|
latitude : loc.lat,
|
|
|
|
longitude : loc.lng,
|
|
|
|
altitude : loc.alt,
|
2016-05-04 21:23:34 -03:00
|
|
|
ground_speed : gps.ground_speed(i),
|
2016-05-04 22:21:34 -03:00
|
|
|
ground_course : gps.ground_course(i),
|
2015-08-05 03:25:48 -03:00
|
|
|
vel_z : gps.velocity(i).z,
|
2017-05-28 04:12:50 -03:00
|
|
|
yaw : yaw_deg,
|
2015-08-05 03:25:48 -03:00
|
|
|
used : (uint8_t)(gps.primary_sensor() == i)
|
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
2015-09-09 01:52:52 -03:00
|
|
|
|
2016-05-12 13:50:13 -03:00
|
|
|
/* write auxiliary accuracy information as well */
|
2015-09-09 01:52:52 -03:00
|
|
|
float hacc = 0, vacc = 0, sacc = 0;
|
|
|
|
gps.horizontal_accuracy(i, hacc);
|
|
|
|
gps.vertical_accuracy(i, vacc);
|
|
|
|
gps.speed_accuracy(i, sacc);
|
2019-07-02 06:31:02 -03:00
|
|
|
struct log_GPA pkt2{
|
2015-09-09 01:52:52 -03:00
|
|
|
LOG_PACKET_HEADER_INIT((uint8_t)(LOG_GPA_MSG+i)),
|
2016-05-05 00:37:16 -03:00
|
|
|
time_us : time_us,
|
2015-09-09 01:52:52 -03:00
|
|
|
vdop : gps.get_vdop(i),
|
2017-04-16 19:56:55 -03:00
|
|
|
hacc : (uint16_t)MIN((hacc*100), UINT16_MAX),
|
|
|
|
vacc : (uint16_t)MIN((vacc*100), UINT16_MAX),
|
|
|
|
sacc : (uint16_t)MIN((sacc*100), UINT16_MAX),
|
2019-09-03 16:40:48 -03:00
|
|
|
yaw_accuracy : yaw_accuracy_deg,
|
2016-05-05 03:03:59 -03:00
|
|
|
have_vv : (uint8_t)gps.have_vertical_velocity(i),
|
2017-07-08 20:06:47 -03:00
|
|
|
sample_ms : gps.last_message_time_ms(i),
|
|
|
|
delta_ms : gps.last_message_delta_time_ms(i)
|
2015-09-09 01:52:52 -03:00
|
|
|
};
|
|
|
|
WriteBlock(&pkt2, sizeof(pkt2));
|
2013-04-19 04:49:16 -03:00
|
|
|
}
|
|
|
|
|
2015-09-10 07:27:47 -03:00
|
|
|
|
2013-11-25 17:44:00 -04:00
|
|
|
// Write an RCIN packet
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_RCIN(void)
|
2013-11-25 17:44:00 -04:00
|
|
|
{
|
2020-08-19 05:56:50 -03:00
|
|
|
uint16_t values[16] = {};
|
2018-08-08 21:34:15 -03:00
|
|
|
rc().get_radio_in(values, ARRAY_SIZE(values));
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_RCIN pkt{
|
2013-11-25 17:44:00 -04:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_RCIN_MSG),
|
2015-11-19 23:15:08 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
2018-04-26 09:00:30 -03:00
|
|
|
chan1 : values[0],
|
|
|
|
chan2 : values[1],
|
|
|
|
chan3 : values[2],
|
|
|
|
chan4 : values[3],
|
|
|
|
chan5 : values[4],
|
|
|
|
chan6 : values[5],
|
|
|
|
chan7 : values[6],
|
|
|
|
chan8 : values[7],
|
|
|
|
chan9 : values[8],
|
|
|
|
chan10 : values[9],
|
|
|
|
chan11 : values[10],
|
|
|
|
chan12 : values[11],
|
|
|
|
chan13 : values[12],
|
|
|
|
chan14 : values[13]
|
2013-11-25 17:44:00 -04:00
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
2020-08-19 05:56:50 -03:00
|
|
|
|
|
|
|
// don't waste logging bandwidth if we haven't seen non-zero
|
|
|
|
// channels 15/16:
|
|
|
|
if (!seen_nonzero_rcin15_or_rcin16) {
|
|
|
|
if (!values[14] && !values[15]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
seen_nonzero_rcin15_or_rcin16 = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct log_RCIN2 pkt2{
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_RCIN2_MSG),
|
|
|
|
time_us : AP_HAL::micros64(),
|
|
|
|
chan15 : values[14],
|
|
|
|
chan16 : values[15]
|
|
|
|
};
|
|
|
|
WriteBlock(&pkt2, sizeof(pkt2));
|
2013-11-25 17:44:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write an SERVO packet
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_RCOUT(void)
|
2013-11-25 17:44:00 -04:00
|
|
|
{
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_RCOUT pkt{
|
2013-11-27 07:14:17 -04:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_RCOUT_MSG),
|
2015-11-19 23:15:08 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
2013-11-25 17:44:00 -04:00
|
|
|
chan1 : hal.rcout->read(0),
|
|
|
|
chan2 : hal.rcout->read(1),
|
|
|
|
chan3 : hal.rcout->read(2),
|
|
|
|
chan4 : hal.rcout->read(3),
|
|
|
|
chan5 : hal.rcout->read(4),
|
|
|
|
chan6 : hal.rcout->read(5),
|
|
|
|
chan7 : hal.rcout->read(6),
|
2014-08-12 12:08:17 -03:00
|
|
|
chan8 : hal.rcout->read(7),
|
|
|
|
chan9 : hal.rcout->read(8),
|
|
|
|
chan10 : hal.rcout->read(9),
|
|
|
|
chan11 : hal.rcout->read(10),
|
2016-06-06 00:42:03 -03:00
|
|
|
chan12 : hal.rcout->read(11),
|
|
|
|
chan13 : hal.rcout->read(12),
|
|
|
|
chan14 : hal.rcout->read(13)
|
2013-11-25 17:44:00 -04:00
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
|
|
|
}
|
|
|
|
|
2015-09-04 12:50:23 -03:00
|
|
|
// Write an RSSI packet
|
2019-04-05 19:48:11 -03:00
|
|
|
void AP_Logger::Write_RSSI()
|
2015-09-04 12:50:23 -03:00
|
|
|
{
|
2019-04-05 19:48:11 -03:00
|
|
|
AP_RSSI *rssi = AP::rssi();
|
|
|
|
if (rssi == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_RSSI pkt{
|
2015-09-04 12:50:23 -03:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_RSSI_MSG),
|
2015-11-19 23:15:08 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
2019-04-05 19:48:11 -03:00
|
|
|
RXRSSI : rssi->read_receiver_rssi()
|
2015-09-04 12:50:23 -03:00
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
|
|
|
}
|
|
|
|
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_Baro_instance(uint64_t time_us, uint8_t baro_instance, enum LogMessages type)
|
2014-01-27 19:35:18 -04:00
|
|
|
{
|
2018-03-05 16:36:23 -04:00
|
|
|
AP_Baro &baro = AP::baro();
|
2016-05-17 22:27:39 -03:00
|
|
|
float climbrate = baro.get_climb_rate();
|
2016-05-13 17:01:43 -03:00
|
|
|
float drift_offset = baro.get_baro_drift_offset();
|
2017-03-24 02:00:22 -03:00
|
|
|
float ground_temp = baro.get_ground_temperature();
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_BARO pkt{
|
2018-04-09 03:04:17 -03:00
|
|
|
LOG_PACKET_HEADER_INIT(type),
|
2015-05-21 22:34:05 -03:00
|
|
|
time_us : time_us,
|
2017-09-27 21:19:35 -03:00
|
|
|
altitude : baro.get_altitude(baro_instance),
|
|
|
|
pressure : baro.get_pressure(baro_instance),
|
|
|
|
temperature : (int16_t)(baro.get_temperature(baro_instance) * 100 + 0.5f),
|
2016-05-17 22:27:39 -03:00
|
|
|
climbrate : climbrate,
|
2017-09-27 21:19:35 -03:00
|
|
|
sample_time_ms: baro.get_last_update(baro_instance),
|
2016-05-13 17:01:43 -03:00
|
|
|
drift_offset : drift_offset,
|
2017-03-24 02:00:22 -03:00
|
|
|
ground_temp : ground_temp,
|
2019-07-30 21:07:34 -03:00
|
|
|
healthy : (uint8_t)baro.healthy(baro_instance)
|
2014-01-27 19:35:18 -04:00
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
2017-09-27 21:19:35 -03:00
|
|
|
}
|
2015-10-14 12:53:14 -03:00
|
|
|
|
2017-09-27 21:19:35 -03:00
|
|
|
// Write a BARO packet
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_Baro(uint64_t time_us)
|
2017-09-27 21:19:35 -03:00
|
|
|
{
|
|
|
|
if (time_us == 0) {
|
|
|
|
time_us = AP_HAL::micros64();
|
|
|
|
}
|
2018-03-05 16:36:23 -04:00
|
|
|
const AP_Baro &baro = AP::baro();
|
2019-01-18 00:24:08 -04:00
|
|
|
Write_Baro_instance(time_us, 0, LOG_BARO_MSG);
|
2020-09-05 01:18:24 -03:00
|
|
|
if (baro.num_instances() > 1) {
|
2019-01-18 00:24:08 -04:00
|
|
|
Write_Baro_instance(time_us, 1, LOG_BAR2_MSG);
|
2015-01-05 17:37:23 -04:00
|
|
|
}
|
2020-09-05 01:18:24 -03:00
|
|
|
if (baro.num_instances() > 2) {
|
2019-01-18 00:24:08 -04:00
|
|
|
Write_Baro_instance(time_us, 2, LOG_BAR3_MSG);
|
2015-09-10 07:27:47 -03:00
|
|
|
}
|
2014-01-27 19:35:18 -04:00
|
|
|
}
|
2013-04-19 04:49:16 -03:00
|
|
|
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_IMU_instance(const uint64_t time_us, const uint8_t imu_instance, const enum LogMessages type)
|
2013-04-19 04:49:16 -03:00
|
|
|
{
|
2018-03-10 05:36:33 -04:00
|
|
|
const AP_InertialSensor &ins = AP::ins();
|
2017-09-28 23:34:58 -03:00
|
|
|
const Vector3f &gyro = ins.get_gyro(imu_instance);
|
|
|
|
const Vector3f &accel = ins.get_accel(imu_instance);
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_IMU pkt{
|
2017-09-28 23:34:58 -03:00
|
|
|
LOG_PACKET_HEADER_INIT(type),
|
2015-05-21 22:34:05 -03:00
|
|
|
time_us : time_us,
|
2013-04-19 04:49:16 -03:00
|
|
|
gyro_x : gyro.x,
|
|
|
|
gyro_y : gyro.y,
|
|
|
|
gyro_z : gyro.z,
|
|
|
|
accel_x : accel.x,
|
|
|
|
accel_y : accel.y,
|
2014-12-29 06:19:50 -04:00
|
|
|
accel_z : accel.z,
|
2017-09-28 23:34:58 -03:00
|
|
|
gyro_error : ins.get_gyro_error_count(imu_instance),
|
|
|
|
accel_error : ins.get_accel_error_count(imu_instance),
|
|
|
|
temperature : ins.get_temperature(imu_instance),
|
|
|
|
gyro_health : (uint8_t)ins.get_gyro_health(imu_instance),
|
|
|
|
accel_health : (uint8_t)ins.get_accel_health(imu_instance),
|
|
|
|
gyro_rate : ins.get_gyro_rate_hz(imu_instance),
|
|
|
|
accel_rate : ins.get_accel_rate_hz(imu_instance),
|
2013-04-19 04:49:16 -03:00
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
2017-09-28 23:34:58 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write an raw accel/gyro data packet
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_IMU()
|
2017-09-28 23:34:58 -03:00
|
|
|
{
|
|
|
|
uint64_t time_us = AP_HAL::micros64();
|
|
|
|
|
2018-03-10 05:36:33 -04:00
|
|
|
const AP_InertialSensor &ins = AP::ins();
|
|
|
|
|
2019-01-18 00:24:08 -04:00
|
|
|
Write_IMU_instance(time_us, 0, LOG_IMU_MSG);
|
2013-12-08 05:45:04 -04:00
|
|
|
if (ins.get_gyro_count() < 2 && ins.get_accel_count() < 2) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-14 12:48:19 -03:00
|
|
|
|
2019-01-18 00:24:08 -04:00
|
|
|
Write_IMU_instance(time_us, 1, LOG_IMU2_MSG);
|
2017-09-28 23:34:58 -03:00
|
|
|
|
2014-06-26 01:04:55 -03:00
|
|
|
if (ins.get_gyro_count() < 3 && ins.get_accel_count() < 3) {
|
|
|
|
return;
|
|
|
|
}
|
2017-09-28 23:34:58 -03:00
|
|
|
|
2019-01-18 00:24:08 -04:00
|
|
|
Write_IMU_instance(time_us, 2, LOG_IMU3_MSG);
|
2013-12-08 05:45:04 -04:00
|
|
|
}
|
|
|
|
|
2015-06-13 10:06:49 -03:00
|
|
|
// Write an accel/gyro delta time data packet
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_IMUDT_instance(const uint64_t time_us, const uint8_t imu_instance, const enum LogMessages type)
|
2015-06-13 10:06:49 -03:00
|
|
|
{
|
2018-03-10 05:36:33 -04:00
|
|
|
const AP_InertialSensor &ins = AP::ins();
|
2015-06-13 10:06:49 -03:00
|
|
|
float delta_t = ins.get_delta_time();
|
2017-09-29 00:28:34 -03:00
|
|
|
float delta_vel_t = ins.get_delta_velocity_dt(imu_instance);
|
|
|
|
float delta_ang_t = ins.get_delta_angle_dt(imu_instance);
|
2015-06-13 10:06:49 -03:00
|
|
|
Vector3f delta_angle, delta_velocity;
|
2017-09-29 00:28:34 -03:00
|
|
|
ins.get_delta_angle(imu_instance, delta_angle);
|
|
|
|
ins.get_delta_velocity(imu_instance, delta_velocity);
|
2015-06-13 10:06:49 -03:00
|
|
|
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_IMUDT pkt{
|
2017-09-29 00:28:34 -03:00
|
|
|
LOG_PACKET_HEADER_INIT(type),
|
2015-06-13 10:06:49 -03:00
|
|
|
time_us : time_us,
|
|
|
|
delta_time : delta_t,
|
|
|
|
delta_vel_dt : delta_vel_t,
|
2016-04-26 02:50:29 -03:00
|
|
|
delta_ang_dt : delta_ang_t,
|
2015-06-13 10:06:49 -03:00
|
|
|
delta_ang_x : delta_angle.x,
|
|
|
|
delta_ang_y : delta_angle.y,
|
|
|
|
delta_ang_z : delta_angle.z,
|
|
|
|
delta_vel_x : delta_velocity.x,
|
|
|
|
delta_vel_y : delta_velocity.y,
|
|
|
|
delta_vel_z : delta_velocity.z
|
|
|
|
};
|
2017-09-29 00:28:34 -03:00
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
|
|
|
}
|
|
|
|
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_IMUDT(uint64_t time_us, uint8_t imu_mask)
|
2017-09-29 00:28:34 -03:00
|
|
|
{
|
2018-03-10 05:36:33 -04:00
|
|
|
const AP_InertialSensor &ins = AP::ins();
|
2016-05-08 23:26:30 -03:00
|
|
|
if (imu_mask & 1) {
|
2019-01-18 00:24:08 -04:00
|
|
|
Write_IMUDT_instance(time_us, 0, LOG_IMUDT_MSG);
|
2016-05-08 23:26:30 -03:00
|
|
|
}
|
2016-05-04 23:16:16 -03:00
|
|
|
if ((ins.get_gyro_count() < 2 && ins.get_accel_count() < 2) || !ins.use_gyro(1)) {
|
2015-06-13 10:06:49 -03:00
|
|
|
return;
|
|
|
|
}
|
2015-10-14 12:48:19 -03:00
|
|
|
|
2016-05-08 23:26:30 -03:00
|
|
|
if (imu_mask & 2) {
|
2019-01-18 00:24:08 -04:00
|
|
|
Write_IMUDT_instance(time_us, 1, LOG_IMUDT2_MSG);
|
2016-05-08 23:26:30 -03:00
|
|
|
}
|
2015-06-13 10:06:49 -03:00
|
|
|
|
2016-05-04 23:16:16 -03:00
|
|
|
if ((ins.get_gyro_count() < 3 && ins.get_accel_count() < 3) || !ins.use_gyro(2)) {
|
2015-06-13 10:06:49 -03:00
|
|
|
return;
|
|
|
|
}
|
2017-09-29 00:28:34 -03:00
|
|
|
|
2016-05-08 23:26:30 -03:00
|
|
|
if (imu_mask & 4) {
|
2019-01-18 00:24:08 -04:00
|
|
|
Write_IMUDT_instance(time_us, 2, LOG_IMUDT3_MSG);
|
2016-05-08 23:26:30 -03:00
|
|
|
}
|
2015-06-13 10:06:49 -03:00
|
|
|
}
|
|
|
|
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_Vibration()
|
2015-06-11 10:26:45 -03:00
|
|
|
{
|
2018-03-10 05:36:33 -04:00
|
|
|
const AP_InertialSensor &ins = AP::ins();
|
2020-10-04 00:49:05 -03:00
|
|
|
const uint64_t time_us = AP_HAL::micros64();
|
|
|
|
for (uint8_t i = 0; i < INS_MAX_INSTANCES; i++) {
|
|
|
|
if (!ins.use_accel(i)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Vector3f vibration = ins.get_vibration_levels(i);
|
|
|
|
const struct log_Vibe pkt{
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_VIBE_MSG),
|
|
|
|
time_us : time_us,
|
|
|
|
imu : i,
|
|
|
|
vibe_x : vibration.x,
|
|
|
|
vibe_y : vibration.y,
|
|
|
|
vibe_z : vibration.z,
|
|
|
|
clipping : ins.get_accel_clip_count(i)
|
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
|
|
|
}
|
2015-06-11 10:26:45 -03:00
|
|
|
}
|
|
|
|
|
2019-08-22 22:21:39 -03:00
|
|
|
void AP_Logger::Write_Command(const mavlink_command_int_t &packet,
|
|
|
|
const MAV_RESULT result,
|
|
|
|
bool was_command_long)
|
|
|
|
{
|
|
|
|
const struct log_MAVLink_Command pkt{
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_MAVLINK_COMMAND_MSG),
|
|
|
|
time_us : AP_HAL::micros64(),
|
|
|
|
target_system : packet.target_system,
|
|
|
|
target_component: packet.target_component,
|
|
|
|
frame : packet.frame,
|
|
|
|
command : packet.command,
|
|
|
|
current : packet.current,
|
|
|
|
autocontinue : packet.autocontinue,
|
|
|
|
param1 : packet.param1,
|
|
|
|
param2 : packet.param2,
|
|
|
|
param3 : packet.param3,
|
|
|
|
param4 : packet.param4,
|
|
|
|
x : packet.x,
|
|
|
|
y : packet.y,
|
|
|
|
z : packet.z,
|
|
|
|
result : (uint8_t)result,
|
|
|
|
was_command_long:was_command_long,
|
|
|
|
};
|
|
|
|
return WriteBlock(&pkt, sizeof(pkt));
|
|
|
|
}
|
|
|
|
|
2019-01-18 00:24:08 -04:00
|
|
|
bool AP_Logger_Backend::Write_Mission_Cmd(const AP_Mission &mission,
|
2015-11-09 18:14:22 -04:00
|
|
|
const AP_Mission::Mission_Command &cmd)
|
2015-06-30 01:33:50 -03:00
|
|
|
{
|
2018-11-24 23:10:07 -04:00
|
|
|
mavlink_mission_item_int_t mav_cmd = {};
|
|
|
|
AP_Mission::mission_cmd_to_mavlink_int(cmd,mav_cmd);
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_Cmd pkt{
|
2018-11-24 23:10:07 -04:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_CMD_MSG),
|
|
|
|
time_us : AP_HAL::micros64(),
|
|
|
|
command_total : mission.num_commands(),
|
|
|
|
sequence : mav_cmd.seq,
|
|
|
|
command : mav_cmd.command,
|
|
|
|
param1 : mav_cmd.param1,
|
|
|
|
param2 : mav_cmd.param2,
|
|
|
|
param3 : mav_cmd.param3,
|
|
|
|
param4 : mav_cmd.param4,
|
|
|
|
latitude : mav_cmd.x,
|
|
|
|
longitude : mav_cmd.y,
|
|
|
|
altitude : mav_cmd.z,
|
|
|
|
frame : mav_cmd.frame
|
|
|
|
};
|
|
|
|
return WriteBlock(&pkt, sizeof(pkt));
|
2015-06-30 01:33:50 -03:00
|
|
|
}
|
|
|
|
|
2020-04-13 01:20:30 -03:00
|
|
|
bool AP_Logger_Backend::Write_EntireMission()
|
2015-06-30 01:33:50 -03:00
|
|
|
{
|
2020-04-13 01:20:30 -03:00
|
|
|
// kick off asynchronous write:
|
|
|
|
return _startup_messagewriter->writeentiremission();
|
2015-06-30 01:33:50 -03:00
|
|
|
}
|
|
|
|
|
2013-05-02 20:18:14 -03:00
|
|
|
// Write a text message to the log
|
2019-01-18 00:24:08 -04:00
|
|
|
bool AP_Logger_Backend::Write_Message(const char *message)
|
2013-05-02 20:18:14 -03:00
|
|
|
{
|
2019-07-02 06:31:02 -03:00
|
|
|
struct log_Message pkt{
|
2013-05-02 20:18:14 -03:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_MESSAGE_MSG),
|
2015-11-19 23:15:08 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
2013-05-02 20:18:14 -03:00
|
|
|
msg : {}
|
|
|
|
};
|
2020-07-07 00:14:35 -03:00
|
|
|
strncpy_noterm(pkt.msg, message, sizeof(pkt.msg));
|
2015-08-27 23:47:16 -03:00
|
|
|
return WriteCriticalBlock(&pkt, sizeof(pkt));
|
2013-05-02 20:18:14 -03:00
|
|
|
}
|
|
|
|
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_Power(void)
|
2014-02-13 07:07:32 -04:00
|
|
|
{
|
2019-01-15 21:15:24 -04:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
|
2018-04-12 20:49:48 -03:00
|
|
|
uint8_t safety_and_armed = uint8_t(hal.util->safety_switch_state());
|
|
|
|
if (hal.util->get_soft_armed()) {
|
|
|
|
// encode armed state in bit 3
|
|
|
|
safety_and_armed |= 1U<<2;
|
|
|
|
}
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_POWR pkt{
|
2014-02-13 07:07:32 -04:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_POWR_MSG),
|
2015-11-19 23:15:08 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
2016-06-02 17:55:05 -03:00
|
|
|
Vcc : hal.analogin->board_voltage(),
|
|
|
|
Vservo : hal.analogin->servorail_voltage(),
|
2018-04-12 20:49:48 -03:00
|
|
|
flags : hal.analogin->power_status_flags(),
|
2020-07-19 21:34:43 -03:00
|
|
|
accumulated_flags : hal.analogin->accumulated_power_status_flags(),
|
2018-04-12 20:49:48 -03:00
|
|
|
safety_and_arm : safety_and_armed
|
2014-02-13 07:07:32 -04:00
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-01-03 01:01:08 -04:00
|
|
|
// Write an AHRS2 packet
|
2019-10-23 21:32:32 -03:00
|
|
|
void AP_Logger::Write_AHRS2()
|
2014-01-03 01:01:08 -04:00
|
|
|
{
|
2019-10-23 21:32:32 -03:00
|
|
|
const AP_AHRS &ahrs = AP::ahrs();
|
2014-01-03 01:01:08 -04:00
|
|
|
Vector3f euler;
|
|
|
|
struct Location loc;
|
2017-04-15 08:19:36 -03:00
|
|
|
Quaternion quat;
|
2019-03-12 06:45:14 -03:00
|
|
|
if (!ahrs.get_secondary_attitude(euler) || !ahrs.get_secondary_position(loc) || !ahrs.get_secondary_quaternion(quat)) {
|
2014-01-03 01:01:08 -04:00
|
|
|
return;
|
|
|
|
}
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_AHRS pkt{
|
2014-01-30 18:33:12 -04:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_AHR2_MSG),
|
2015-11-19 23:15:08 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
2014-01-03 01:01:08 -04:00
|
|
|
roll : (int16_t)(degrees(euler.x)*100),
|
|
|
|
pitch : (int16_t)(degrees(euler.y)*100),
|
|
|
|
yaw : (uint16_t)(wrap_360_cd(degrees(euler.z)*100)),
|
|
|
|
alt : loc.alt*1.0e-2f,
|
|
|
|
lat : loc.lat,
|
2017-04-15 08:19:36 -03:00
|
|
|
lng : loc.lng,
|
|
|
|
q1 : quat.q1,
|
|
|
|
q2 : quat.q2,
|
|
|
|
q3 : quat.q3,
|
|
|
|
q4 : quat.q4,
|
2014-01-03 01:01:08 -04:00
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
|
|
|
}
|
|
|
|
|
2015-05-14 22:59:40 -03:00
|
|
|
// Write a POS packet
|
2019-10-23 21:32:32 -03:00
|
|
|
void AP_Logger::Write_POS()
|
2015-05-14 22:59:40 -03:00
|
|
|
{
|
2019-10-23 21:32:32 -03:00
|
|
|
const AP_AHRS &ahrs = AP::ahrs();
|
|
|
|
|
2015-05-14 22:59:40 -03:00
|
|
|
Location loc;
|
|
|
|
if (!ahrs.get_position(loc)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-01-30 15:09:58 -04:00
|
|
|
float home, origin;
|
|
|
|
ahrs.get_relative_position_D_home(home);
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_POS pkt{
|
2015-05-14 22:59:40 -03:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_POS_MSG),
|
2017-01-30 15:09:58 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
|
|
|
lat : loc.lat,
|
|
|
|
lng : loc.lng,
|
|
|
|
alt : loc.alt*1.0e-2f,
|
|
|
|
rel_home_alt : -home,
|
2017-07-21 23:27:45 -03:00
|
|
|
rel_origin_alt : ahrs.get_relative_position_D_origin(origin) ? -origin : quiet_nanf(),
|
2015-05-14 22:59:40 -03:00
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
|
|
|
}
|
|
|
|
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_Radio(const mavlink_radio_t &packet)
|
2014-03-11 14:05:02 -03:00
|
|
|
{
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_Radio pkt{
|
2014-03-11 14:05:02 -03:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_RADIO_MSG),
|
2015-11-19 23:15:08 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
2014-03-11 14:05:02 -03:00
|
|
|
rssi : packet.rssi,
|
|
|
|
remrssi : packet.remrssi,
|
|
|
|
txbuf : packet.txbuf,
|
|
|
|
noise : packet.noise,
|
|
|
|
remnoise : packet.remnoise,
|
|
|
|
rxerrors : packet.rxerrors,
|
|
|
|
fixed : packet.fixed
|
|
|
|
};
|
2016-11-22 11:34:53 -04:00
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
2014-03-11 14:05:02 -03:00
|
|
|
}
|
|
|
|
|
2014-06-10 23:55:04 -03:00
|
|
|
// Write a Camera packet
|
2019-06-27 04:24:04 -03:00
|
|
|
void AP_Logger::Write_CameraInfo(enum LogMessages msg, const Location ¤t_loc, uint64_t timestamp_us)
|
2014-06-10 23:55:04 -03:00
|
|
|
{
|
2019-06-27 04:24:04 -03:00
|
|
|
const AP_AHRS &ahrs = AP::ahrs();
|
|
|
|
|
2016-01-28 18:51:52 -04:00
|
|
|
int32_t altitude, altitude_rel, altitude_gps;
|
2019-01-02 00:46:33 -04:00
|
|
|
if (current_loc.relative_alt) {
|
2014-06-10 23:55:04 -03:00
|
|
|
altitude = current_loc.alt+ahrs.get_home().alt;
|
|
|
|
altitude_rel = current_loc.alt;
|
|
|
|
} else {
|
|
|
|
altitude = current_loc.alt;
|
|
|
|
altitude_rel = current_loc.alt - ahrs.get_home().alt;
|
|
|
|
}
|
2017-11-12 20:31:31 -04:00
|
|
|
const AP_GPS &gps = AP::gps();
|
2016-01-28 18:51:52 -04:00
|
|
|
if (gps.status() >= AP_GPS::GPS_OK_FIX_3D) {
|
|
|
|
altitude_gps = gps.location().alt;
|
|
|
|
} else {
|
|
|
|
altitude_gps = 0;
|
|
|
|
}
|
2014-06-10 23:55:04 -03:00
|
|
|
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_Camera pkt{
|
2016-02-26 01:16:04 -04:00
|
|
|
LOG_PACKET_HEADER_INIT(static_cast<uint8_t>(msg)),
|
2018-05-14 22:04:09 -03:00
|
|
|
time_us : timestamp_us?timestamp_us:AP_HAL::micros64(),
|
2014-06-10 23:55:04 -03:00
|
|
|
gps_time : gps.time_week_ms(),
|
|
|
|
gps_week : gps.time_week(),
|
|
|
|
latitude : current_loc.lat,
|
|
|
|
longitude : current_loc.lng,
|
|
|
|
altitude : altitude,
|
|
|
|
altitude_rel: altitude_rel,
|
2016-01-28 18:51:52 -04:00
|
|
|
altitude_gps: altitude_gps,
|
2014-06-10 23:55:04 -03:00
|
|
|
roll : (int16_t)ahrs.roll_sensor,
|
|
|
|
pitch : (int16_t)ahrs.pitch_sensor,
|
|
|
|
yaw : (uint16_t)ahrs.yaw_sensor
|
|
|
|
};
|
2015-10-06 01:13:40 -03:00
|
|
|
WriteCriticalBlock(&pkt, sizeof(pkt));
|
2014-06-10 23:55:04 -03:00
|
|
|
}
|
2014-11-13 06:38:33 -04:00
|
|
|
|
2016-01-28 18:51:52 -04:00
|
|
|
// Write a Camera packet
|
2019-06-27 04:24:04 -03:00
|
|
|
void AP_Logger::Write_Camera(const Location ¤t_loc, uint64_t timestamp_us)
|
2016-01-28 18:51:52 -04:00
|
|
|
{
|
2019-06-27 04:24:04 -03:00
|
|
|
Write_CameraInfo(LOG_CAMERA_MSG, current_loc, timestamp_us);
|
2016-01-28 18:51:52 -04:00
|
|
|
}
|
|
|
|
|
2016-01-06 20:29:52 -04:00
|
|
|
// Write a Trigger packet
|
2019-06-27 04:24:04 -03:00
|
|
|
void AP_Logger::Write_Trigger(const Location ¤t_loc)
|
2016-01-06 20:29:52 -04:00
|
|
|
{
|
2019-06-27 04:24:04 -03:00
|
|
|
Write_CameraInfo(LOG_TRIGGER_MSG, current_loc, 0);
|
2016-01-06 20:29:52 -04:00
|
|
|
}
|
|
|
|
|
2014-12-18 12:55:11 -04:00
|
|
|
// Write an attitude packet
|
2019-10-23 21:32:32 -03:00
|
|
|
void AP_Logger::Write_Attitude(const Vector3f &targets)
|
2017-03-30 20:37:35 -03:00
|
|
|
{
|
2019-10-23 21:32:32 -03:00
|
|
|
const AP_AHRS &ahrs = AP::ahrs();
|
|
|
|
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_Attitude pkt{
|
2017-03-30 20:37:35 -03:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_ATTITUDE_MSG),
|
|
|
|
time_us : AP_HAL::micros64(),
|
|
|
|
control_roll : (int16_t)targets.x,
|
|
|
|
roll : (int16_t)ahrs.roll_sensor,
|
|
|
|
control_pitch : (int16_t)targets.y,
|
|
|
|
pitch : (int16_t)ahrs.pitch_sensor,
|
2019-01-13 00:24:05 -04:00
|
|
|
control_yaw : (uint16_t)wrap_360_cd(targets.z),
|
|
|
|
yaw : (uint16_t)wrap_360_cd(ahrs.yaw_sensor),
|
2017-03-30 20:37:35 -03:00
|
|
|
error_rp : (uint16_t)(ahrs.get_error_rp() * 100),
|
|
|
|
error_yaw : (uint16_t)(ahrs.get_error_yaw() * 100)
|
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write an attitude packet
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_AttitudeView(AP_AHRS_View &ahrs, const Vector3f &targets)
|
2014-12-18 12:55:11 -04:00
|
|
|
{
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_Attitude pkt{
|
2014-12-18 12:55:11 -04:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_ATTITUDE_MSG),
|
2015-11-19 23:15:08 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
2014-12-18 12:55:11 -04:00
|
|
|
control_roll : (int16_t)targets.x,
|
|
|
|
roll : (int16_t)ahrs.roll_sensor,
|
|
|
|
control_pitch : (int16_t)targets.y,
|
|
|
|
pitch : (int16_t)ahrs.pitch_sensor,
|
2019-02-14 17:07:58 -04:00
|
|
|
control_yaw : (uint16_t)wrap_360_cd(targets.z),
|
|
|
|
yaw : (uint16_t)wrap_360_cd(ahrs.yaw_sensor),
|
2014-12-18 12:55:11 -04:00
|
|
|
error_rp : (uint16_t)(ahrs.get_error_rp() * 100),
|
|
|
|
error_yaw : (uint16_t)(ahrs.get_error_yaw() * 100)
|
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
|
|
|
}
|
|
|
|
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_Current_instance(const uint64_t time_us,
|
2020-01-07 19:58:03 -04:00
|
|
|
const uint8_t battery_instance)
|
2014-12-18 17:34:29 -04:00
|
|
|
{
|
2018-01-16 15:09:47 -04:00
|
|
|
AP_BattMonitor &battery = AP::battery();
|
2017-09-29 00:09:59 -03:00
|
|
|
float temp;
|
|
|
|
bool has_temp = battery.get_temperature(temp, battery_instance);
|
2019-07-07 11:37:56 -03:00
|
|
|
float current, consumed_mah, consumed_wh;
|
2019-10-08 16:40:18 -03:00
|
|
|
if (!battery.current_amps(current, battery_instance)) {
|
2019-07-08 06:43:38 -03:00
|
|
|
current = quiet_nanf();
|
2019-07-07 11:37:56 -03:00
|
|
|
}
|
|
|
|
if (!battery.consumed_mah(consumed_mah, battery_instance)) {
|
2019-07-08 06:43:38 -03:00
|
|
|
consumed_mah = quiet_nanf();
|
2019-07-07 11:37:56 -03:00
|
|
|
}
|
|
|
|
if (!battery.consumed_wh(consumed_wh, battery_instance)) {
|
2019-07-08 06:43:38 -03:00
|
|
|
consumed_wh = quiet_nanf();
|
2019-07-07 11:37:56 -03:00
|
|
|
}
|
|
|
|
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_Current pkt = {
|
2020-01-07 19:58:03 -04:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_CURRENT_MSG),
|
2017-09-29 00:09:59 -03:00
|
|
|
time_us : time_us,
|
2020-01-07 19:58:03 -04:00
|
|
|
instance : battery_instance,
|
2017-09-29 00:09:59 -03:00
|
|
|
voltage : battery.voltage(battery_instance),
|
|
|
|
voltage_resting : battery.voltage_resting_estimate(battery_instance),
|
2019-07-07 11:37:56 -03:00
|
|
|
current_amps : current,
|
|
|
|
current_total : consumed_mah,
|
|
|
|
consumed_wh : consumed_wh,
|
2017-09-29 00:09:59 -03:00
|
|
|
temperature : (int16_t)(has_temp ? (temp * 100) : 0),
|
|
|
|
resistance : battery.get_resistance(battery_instance)
|
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
|
|
|
|
|
|
|
// individual cell voltages
|
|
|
|
if (battery.has_cell_voltages(battery_instance)) {
|
|
|
|
const AP_BattMonitor::cells &cells = battery.get_cell_voltages(battery_instance);
|
2019-07-02 06:31:02 -03:00
|
|
|
struct log_Current_Cells cell_pkt{
|
2020-01-07 19:58:03 -04:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_CURRENT_CELLS_MSG),
|
2017-09-29 00:09:59 -03:00
|
|
|
time_us : time_us,
|
2020-01-07 19:58:03 -04:00
|
|
|
instance : battery_instance,
|
2017-09-29 00:09:59 -03:00
|
|
|
voltage : battery.voltage(battery_instance)
|
2016-06-02 18:00:57 -03:00
|
|
|
};
|
2017-09-29 00:09:59 -03:00
|
|
|
for (uint8_t i = 0; i < ARRAY_SIZE(cells.cells); i++) {
|
|
|
|
cell_pkt.cell_voltages[i] = cells.cells[i] + 1;
|
|
|
|
}
|
|
|
|
WriteBlock(&cell_pkt, sizeof(cell_pkt));
|
2017-04-08 16:04:12 -03:00
|
|
|
|
2017-09-29 00:09:59 -03:00
|
|
|
// check battery structure can hold all cells
|
|
|
|
static_assert(ARRAY_SIZE(cells.cells) == (sizeof(cell_pkt.cell_voltages) / sizeof(cell_pkt.cell_voltages[0])),
|
|
|
|
"Battery cell number doesn't match in library and log structure");
|
|
|
|
}
|
|
|
|
}
|
2017-04-08 16:04:12 -03:00
|
|
|
|
2017-09-29 00:09:59 -03:00
|
|
|
// Write an Current data packet
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_Current()
|
2017-09-29 00:09:59 -03:00
|
|
|
{
|
|
|
|
const uint64_t time_us = AP_HAL::micros64();
|
2018-01-16 15:09:47 -04:00
|
|
|
const uint8_t num_instances = AP::battery().num_instances();
|
2018-09-12 20:39:30 -03:00
|
|
|
for (uint8_t i = 0; i < num_instances; i++) {
|
2020-01-07 19:58:03 -04:00
|
|
|
Write_Current_instance(time_us, i);
|
2016-06-02 18:00:57 -03:00
|
|
|
}
|
2014-12-18 17:34:29 -04:00
|
|
|
}
|
|
|
|
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_Compass_instance(const uint64_t time_us, const uint8_t mag_instance, const enum LogMessages type)
|
2014-12-20 15:08:13 -04:00
|
|
|
{
|
2018-06-25 08:57:09 -03:00
|
|
|
const Compass &compass = AP::compass();
|
|
|
|
|
2017-09-28 23:53:31 -03:00
|
|
|
const Vector3f &mag_field = compass.get_field(mag_instance);
|
|
|
|
const Vector3f &mag_offsets = compass.get_offsets(mag_instance);
|
|
|
|
const Vector3f &mag_motor_offsets = compass.get_motor_offsets(mag_instance);
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_Compass pkt{
|
2017-09-28 23:53:31 -03:00
|
|
|
LOG_PACKET_HEADER_INIT(type),
|
2016-05-05 00:37:16 -03:00
|
|
|
time_us : time_us,
|
2014-12-20 15:08:13 -04:00
|
|
|
mag_x : (int16_t)mag_field.x,
|
|
|
|
mag_y : (int16_t)mag_field.y,
|
|
|
|
mag_z : (int16_t)mag_field.z,
|
|
|
|
offset_x : (int16_t)mag_offsets.x,
|
|
|
|
offset_y : (int16_t)mag_offsets.y,
|
|
|
|
offset_z : (int16_t)mag_offsets.z,
|
|
|
|
motor_offset_x : (int16_t)mag_motor_offsets.x,
|
|
|
|
motor_offset_y : (int16_t)mag_motor_offsets.y,
|
2015-04-18 09:31:48 -03:00
|
|
|
motor_offset_z : (int16_t)mag_motor_offsets.z,
|
2017-09-28 23:53:31 -03:00
|
|
|
health : (uint8_t)compass.healthy(mag_instance),
|
|
|
|
SUS : compass.last_update_usec(mag_instance)
|
2014-12-20 15:08:13 -04:00
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
2017-09-28 23:53:31 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write a Compass packet
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_Compass(uint64_t time_us)
|
2017-09-28 23:53:31 -03:00
|
|
|
{
|
|
|
|
if (time_us == 0) {
|
|
|
|
time_us = AP_HAL::micros64();
|
|
|
|
}
|
2018-06-25 08:57:09 -03:00
|
|
|
const Compass &compass = AP::compass();
|
|
|
|
if (compass.get_count() > 0) {
|
2019-01-18 00:24:08 -04:00
|
|
|
Write_Compass_instance(time_us, 0, LOG_COMPASS_MSG);
|
2018-06-25 08:57:09 -03:00
|
|
|
}
|
2015-10-14 13:05:36 -03:00
|
|
|
|
2015-01-16 18:27:01 -04:00
|
|
|
if (compass.get_count() > 1) {
|
2019-01-18 00:24:08 -04:00
|
|
|
Write_Compass_instance(time_us, 1, LOG_COMPASS2_MSG);
|
2015-01-16 18:27:01 -04:00
|
|
|
}
|
2015-10-14 13:05:36 -03:00
|
|
|
|
2015-01-16 18:27:01 -04:00
|
|
|
if (compass.get_count() > 2) {
|
2019-01-18 00:24:08 -04:00
|
|
|
Write_Compass_instance(time_us, 2, LOG_COMPASS3_MSG);
|
2015-01-16 18:27:01 -04:00
|
|
|
}
|
2014-12-20 15:08:13 -04:00
|
|
|
}
|
|
|
|
|
2014-12-22 16:10:02 -04:00
|
|
|
// Write a mode packet.
|
2019-10-17 00:48:00 -03:00
|
|
|
bool AP_Logger_Backend::Write_Mode(uint8_t mode, const ModeReason reason)
|
2014-12-22 16:10:02 -04:00
|
|
|
{
|
2019-10-17 00:48:00 -03:00
|
|
|
static_assert(sizeof(ModeReason) <= sizeof(uint8_t), "Logging expects the ModeReason to fit in 8 bits");
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_Mode pkt{
|
2014-12-22 16:10:02 -04:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_MODE_MSG),
|
2015-11-19 23:15:08 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
2014-12-22 16:10:02 -04:00
|
|
|
mode : mode,
|
2016-01-25 19:45:27 -04:00
|
|
|
mode_num : mode,
|
2019-10-17 00:48:00 -03:00
|
|
|
mode_reason : static_cast<uint8_t>(reason)
|
2014-12-22 16:10:02 -04:00
|
|
|
};
|
2015-08-27 23:47:16 -03:00
|
|
|
return WriteCriticalBlock(&pkt, sizeof(pkt));
|
2014-12-22 16:10:02 -04:00
|
|
|
}
|
|
|
|
|
2014-11-20 06:53:12 -04:00
|
|
|
// Write ESC status messages
|
2019-02-11 01:48:39 -04:00
|
|
|
// id starts from 0
|
|
|
|
// rpm is eRPM (rpm * 100)
|
|
|
|
// voltage is in centi-volts
|
|
|
|
// current is in centi-amps
|
|
|
|
// temperature is in centi-degrees Celsius
|
|
|
|
// current_tot is in centi-amp hours
|
2020-03-26 20:59:13 -03:00
|
|
|
void AP_Logger::Write_ESC(uint8_t instance, uint64_t time_us, int32_t rpm, uint16_t voltage, uint16_t current, int16_t esc_temp, uint16_t current_tot, int16_t motor_temp)
|
2014-11-13 06:38:33 -04:00
|
|
|
{
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_Esc pkt{
|
2020-03-26 20:59:13 -03:00
|
|
|
LOG_PACKET_HEADER_INIT(uint8_t(LOG_ESC_MSG)),
|
2019-02-11 01:48:39 -04:00
|
|
|
time_us : time_us,
|
2020-03-26 20:59:13 -03:00
|
|
|
instance : instance,
|
2019-02-11 01:48:39 -04:00
|
|
|
rpm : rpm,
|
|
|
|
voltage : voltage,
|
|
|
|
current : current,
|
2019-11-19 21:37:29 -04:00
|
|
|
esc_temp : esc_temp,
|
|
|
|
current_tot : current_tot,
|
|
|
|
motor_temp : motor_temp
|
2019-02-11 01:48:39 -04:00
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
2014-11-13 06:38:33 -04:00
|
|
|
}
|
2015-01-19 18:10:33 -04:00
|
|
|
|
2020-01-04 00:25:55 -04:00
|
|
|
/*
|
|
|
|
write servo status from CAN servo
|
|
|
|
*/
|
|
|
|
void AP_Logger::Write_ServoStatus(uint64_t time_us, uint8_t id, float position, float force, float speed, uint8_t power_pct)
|
|
|
|
{
|
|
|
|
const struct log_CSRV pkt {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_CSRV_MSG),
|
|
|
|
time_us : time_us,
|
|
|
|
id : id,
|
|
|
|
position : position,
|
|
|
|
force : force,
|
|
|
|
speed : speed,
|
|
|
|
power_pct : power_pct
|
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
|
|
|
}
|
|
|
|
|
2020-01-04 00:56:44 -04:00
|
|
|
/*
|
|
|
|
write ESC status from CAN ESC
|
|
|
|
*/
|
|
|
|
void AP_Logger::Write_ESCStatus(uint64_t time_us, uint8_t id, uint32_t error_count, float voltage, float current, float temperature, int32_t rpm, uint8_t power_pct)
|
|
|
|
{
|
|
|
|
const struct log_CESC pkt {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_CESC_MSG),
|
|
|
|
time_us : time_us,
|
|
|
|
id : id,
|
|
|
|
error_count : error_count,
|
|
|
|
voltage : voltage,
|
|
|
|
current : current,
|
|
|
|
temperature : temperature,
|
|
|
|
rpm : rpm,
|
|
|
|
power_pct : power_pct
|
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-21 22:42:08 -03:00
|
|
|
// Write a Yaw PID packet
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_PID(uint8_t msg_type, const PID_Info &info)
|
2015-05-21 22:42:08 -03:00
|
|
|
{
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_PID pkt{
|
2015-05-21 22:42:08 -03:00
|
|
|
LOG_PACKET_HEADER_INIT(msg_type),
|
2015-11-19 23:15:08 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
2019-06-27 06:31:52 -03:00
|
|
|
target : info.target,
|
2018-08-08 01:11:43 -03:00
|
|
|
actual : info.actual,
|
2019-06-27 06:31:52 -03:00
|
|
|
error : info.error,
|
2015-05-21 22:42:08 -03:00
|
|
|
P : info.P,
|
|
|
|
I : info.I,
|
|
|
|
D : info.D,
|
2020-05-10 04:16:23 -03:00
|
|
|
FF : info.FF,
|
|
|
|
Dmod : info.Dmod
|
2015-05-21 22:42:08 -03:00
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
|
|
|
}
|
2015-07-03 08:49:45 -03:00
|
|
|
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_Origin(uint8_t origin_type, const Location &loc)
|
2015-07-03 08:49:45 -03:00
|
|
|
{
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_ORGN pkt{
|
2015-07-03 08:49:45 -03:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_ORGN_MSG),
|
2019-07-02 06:31:02 -03:00
|
|
|
time_us : AP_HAL::micros64(),
|
2015-07-03 08:49:45 -03:00
|
|
|
origin_type : origin_type,
|
|
|
|
latitude : loc.lat,
|
|
|
|
longitude : loc.lng,
|
|
|
|
altitude : loc.alt
|
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
|
|
|
}
|
2015-08-07 07:34:14 -03:00
|
|
|
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_RPM(const AP_RPM &rpm_sensor)
|
2015-08-07 07:34:14 -03:00
|
|
|
{
|
2020-03-05 19:50:52 -04:00
|
|
|
float rpm1 = -1, rpm2 = -1;
|
|
|
|
|
|
|
|
rpm_sensor.get_rpm(0, rpm1);
|
|
|
|
rpm_sensor.get_rpm(1, rpm2);
|
|
|
|
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_RPM pkt{
|
2015-08-07 07:34:14 -03:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_RPM_MSG),
|
2015-11-19 23:15:08 -04:00
|
|
|
time_us : AP_HAL::micros64(),
|
2020-03-05 19:50:52 -04:00
|
|
|
rpm1 : rpm1,
|
|
|
|
rpm2 : rpm2
|
2015-08-07 07:34:14 -03:00
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
2016-01-28 18:51:52 -04:00
|
|
|
}
|
2016-03-24 22:11:11 -03:00
|
|
|
|
2017-04-18 11:43:03 -03:00
|
|
|
// Write a rate packet
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_Rate(const AP_AHRS_View *ahrs,
|
2016-03-24 22:11:11 -03:00
|
|
|
const AP_Motors &motors,
|
|
|
|
const AC_AttitudeControl &attitude_control,
|
|
|
|
const AC_PosControl &pos_control)
|
|
|
|
{
|
|
|
|
const Vector3f &rate_targets = attitude_control.rate_bf_targets();
|
|
|
|
const Vector3f &accel_target = pos_control.get_accel_target();
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_Rate pkt_rate{
|
2016-03-24 22:11:11 -03:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_RATE_MSG),
|
|
|
|
time_us : AP_HAL::micros64(),
|
2016-06-18 07:47:45 -03:00
|
|
|
control_roll : degrees(rate_targets.x),
|
2018-12-21 02:15:40 -04:00
|
|
|
roll : degrees(ahrs->get_gyro().x),
|
2016-03-24 22:11:11 -03:00
|
|
|
roll_out : motors.get_roll(),
|
2016-06-18 07:47:45 -03:00
|
|
|
control_pitch : degrees(rate_targets.y),
|
2018-12-21 02:15:40 -04:00
|
|
|
pitch : degrees(ahrs->get_gyro().y),
|
2016-03-24 22:11:11 -03:00
|
|
|
pitch_out : motors.get_pitch(),
|
2016-06-18 07:47:45 -03:00
|
|
|
control_yaw : degrees(rate_targets.z),
|
2018-12-21 02:15:40 -04:00
|
|
|
yaw : degrees(ahrs->get_gyro().z),
|
2016-03-24 22:11:11 -03:00
|
|
|
yaw_out : motors.get_yaw(),
|
|
|
|
control_accel : (float)accel_target.z,
|
2018-12-21 02:15:40 -04:00
|
|
|
accel : (float)(-(ahrs->get_accel_ef_blended().z + GRAVITY_MSS) * 100.0f),
|
2016-03-24 22:11:11 -03:00
|
|
|
accel_out : motors.get_throttle()
|
|
|
|
};
|
|
|
|
WriteBlock(&pkt_rate, sizeof(pkt_rate));
|
|
|
|
}
|
2016-07-03 23:14:26 -03:00
|
|
|
|
2017-04-03 23:47:04 -03:00
|
|
|
// Write visual odometry sensor data
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_VisualOdom(float time_delta, const Vector3f &angle_delta, const Vector3f &position_delta, float confidence)
|
2017-04-03 23:47:04 -03:00
|
|
|
{
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_VisualOdom pkt_visualodom{
|
2017-04-03 23:47:04 -03:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_VISUALODOM_MSG),
|
|
|
|
time_us : AP_HAL::micros64(),
|
|
|
|
time_delta : time_delta,
|
|
|
|
angle_delta_x : angle_delta.x,
|
|
|
|
angle_delta_y : angle_delta.y,
|
|
|
|
angle_delta_z : angle_delta.z,
|
|
|
|
position_delta_x : position_delta.x,
|
|
|
|
position_delta_y : position_delta.y,
|
|
|
|
position_delta_z : position_delta.z,
|
|
|
|
confidence : confidence
|
|
|
|
};
|
|
|
|
WriteBlock(&pkt_visualodom, sizeof(log_VisualOdom));
|
|
|
|
}
|
2017-04-09 08:17:17 -03:00
|
|
|
|
2020-03-26 01:00:30 -03:00
|
|
|
// Write visual position sensor data. x,y,z are in meters, angles are in degrees
|
2020-09-21 07:52:44 -03:00
|
|
|
void AP_Logger::Write_VisualPosition(uint64_t remote_time_us, uint32_t time_ms, float x, float y, float z, float roll, float pitch, float yaw, float pos_err, float ang_err, uint8_t reset_counter, bool ignored)
|
2020-03-26 01:00:30 -03:00
|
|
|
{
|
|
|
|
const struct log_VisualPosition pkt_visualpos {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_VISUALPOS_MSG),
|
|
|
|
time_us : AP_HAL::micros64(),
|
|
|
|
remote_time_us : remote_time_us,
|
|
|
|
time_ms : time_ms,
|
|
|
|
pos_x : x,
|
|
|
|
pos_y : y,
|
|
|
|
pos_z : z,
|
|
|
|
roll : roll,
|
|
|
|
pitch : pitch,
|
2020-04-10 21:52:57 -03:00
|
|
|
yaw : yaw,
|
2020-06-04 04:54:19 -03:00
|
|
|
pos_err : pos_err,
|
|
|
|
ang_err : ang_err,
|
2020-09-21 07:52:44 -03:00
|
|
|
reset_counter : reset_counter,
|
|
|
|
ignored : (uint8_t)ignored
|
2020-03-26 01:00:30 -03:00
|
|
|
};
|
|
|
|
WriteBlock(&pkt_visualpos, sizeof(log_VisualPosition));
|
|
|
|
}
|
|
|
|
|
2020-05-15 01:30:57 -03:00
|
|
|
// Write visual velocity sensor data, velocity in NED meters per second
|
2020-09-21 07:52:44 -03:00
|
|
|
void AP_Logger::Write_VisualVelocity(uint64_t remote_time_us, uint32_t time_ms, const Vector3f &vel, float vel_err, uint8_t reset_counter, bool ignored)
|
2020-05-15 01:30:57 -03:00
|
|
|
{
|
|
|
|
const struct log_VisualVelocity pkt_visualvel {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_VISUALVEL_MSG),
|
|
|
|
time_us : AP_HAL::micros64(),
|
|
|
|
remote_time_us : remote_time_us,
|
|
|
|
time_ms : time_ms,
|
|
|
|
vel_x : vel.x,
|
|
|
|
vel_y : vel.y,
|
|
|
|
vel_z : vel.z,
|
2020-05-28 22:24:26 -03:00
|
|
|
vel_err : vel_err,
|
2020-09-21 07:52:44 -03:00
|
|
|
reset_counter : reset_counter,
|
|
|
|
ignored : (uint8_t)ignored
|
2020-05-15 01:30:57 -03:00
|
|
|
};
|
|
|
|
WriteBlock(&pkt_visualvel, sizeof(log_VisualVelocity));
|
|
|
|
}
|
|
|
|
|
2017-04-09 08:17:17 -03:00
|
|
|
// Write AOA and SSA
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_AOA_SSA(AP_AHRS &ahrs)
|
2017-04-09 08:17:17 -03:00
|
|
|
{
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_AOA_SSA aoa_ssa{
|
2017-04-09 08:17:17 -03:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_AOA_SSA_MSG),
|
|
|
|
time_us : AP_HAL::micros64(),
|
|
|
|
AOA : ahrs.getAOA(),
|
|
|
|
SSA : ahrs.getSSA()
|
|
|
|
};
|
|
|
|
|
|
|
|
WriteBlock(&aoa_ssa, sizeof(aoa_ssa));
|
|
|
|
}
|
2017-04-18 11:43:03 -03:00
|
|
|
|
|
|
|
// Write beacon sensor (position) data
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_Beacon(AP_Beacon &beacon)
|
2017-04-18 11:43:03 -03:00
|
|
|
{
|
2018-02-22 00:53:55 -04:00
|
|
|
if (!beacon.enabled()) {
|
|
|
|
return;
|
|
|
|
}
|
2017-04-18 11:43:03 -03:00
|
|
|
// position
|
|
|
|
Vector3f pos;
|
|
|
|
float accuracy = 0.0f;
|
|
|
|
beacon.get_vehicle_position_ned(pos, accuracy);
|
|
|
|
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_Beacon pkt_beacon{
|
2017-04-18 11:43:03 -03:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_BEACON_MSG),
|
|
|
|
time_us : AP_HAL::micros64(),
|
|
|
|
health : (uint8_t)beacon.healthy(),
|
|
|
|
count : (uint8_t)beacon.count(),
|
|
|
|
dist0 : beacon.beacon_distance(0),
|
|
|
|
dist1 : beacon.beacon_distance(1),
|
|
|
|
dist2 : beacon.beacon_distance(2),
|
|
|
|
dist3 : beacon.beacon_distance(3),
|
|
|
|
posx : pos.x,
|
|
|
|
posy : pos.y,
|
|
|
|
posz : pos.z
|
|
|
|
};
|
|
|
|
WriteBlock(&pkt_beacon, sizeof(pkt_beacon));
|
|
|
|
}
|
2017-07-14 14:00:13 -03:00
|
|
|
|
|
|
|
// Write proximity sensor distances
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_Proximity(AP_Proximity &proximity)
|
2017-07-14 14:00:13 -03:00
|
|
|
{
|
|
|
|
// exit immediately if not enabled
|
2019-09-27 05:59:32 -03:00
|
|
|
if (proximity.get_status() == AP_Proximity::Status::NotConnected) {
|
2017-07-14 14:00:13 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-14 14:00:21 -03:00
|
|
|
AP_Proximity::Proximity_Distance_Array dist_array {};
|
|
|
|
proximity.get_horizontal_distances(dist_array);
|
2017-07-14 14:00:13 -03:00
|
|
|
|
|
|
|
float dist_up;
|
|
|
|
if (!proximity.get_upward_distance(dist_up)) {
|
|
|
|
dist_up = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
float close_ang = 0.0f, close_dist = 0.0f;
|
|
|
|
proximity.get_closest_object(close_ang, close_dist);
|
|
|
|
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_Proximity pkt_proximity{
|
2017-07-14 14:00:13 -03:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_PROXIMITY_MSG),
|
|
|
|
time_us : AP_HAL::micros64(),
|
|
|
|
health : (uint8_t)proximity.get_status(),
|
2017-07-14 14:00:21 -03:00
|
|
|
dist0 : dist_array.distance[0],
|
|
|
|
dist45 : dist_array.distance[1],
|
|
|
|
dist90 : dist_array.distance[2],
|
|
|
|
dist135 : dist_array.distance[3],
|
|
|
|
dist180 : dist_array.distance[4],
|
|
|
|
dist225 : dist_array.distance[5],
|
|
|
|
dist270 : dist_array.distance[6],
|
|
|
|
dist315 : dist_array.distance[7],
|
2017-07-14 14:00:13 -03:00
|
|
|
distup : dist_up,
|
|
|
|
closest_angle : close_ang,
|
|
|
|
closest_dist : close_dist
|
|
|
|
};
|
|
|
|
WriteBlock(&pkt_proximity, sizeof(pkt_proximity));
|
|
|
|
}
|
2017-07-26 14:09:33 -03:00
|
|
|
|
2019-01-18 00:24:08 -04:00
|
|
|
void AP_Logger::Write_SRTL(bool active, uint16_t num_points, uint16_t max_points, uint8_t action, const Vector3f& breadcrumb)
|
2017-07-26 14:09:33 -03:00
|
|
|
{
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_SRTL pkt_srtl{
|
2017-07-26 14:09:33 -03:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_SRTL_MSG),
|
|
|
|
time_us : AP_HAL::micros64(),
|
|
|
|
active : active,
|
|
|
|
num_points : num_points,
|
|
|
|
max_points : max_points,
|
|
|
|
action : action,
|
|
|
|
N : breadcrumb.x,
|
|
|
|
E : breadcrumb.y,
|
|
|
|
D : breadcrumb.z
|
|
|
|
};
|
|
|
|
WriteBlock(&pkt_srtl, sizeof(pkt_srtl));
|
|
|
|
}
|
2019-06-08 01:59:04 -03:00
|
|
|
|
2020-07-01 03:11:34 -03:00
|
|
|
void AP_Logger::Write_OABendyRuler(uint8_t type, bool active, float target_yaw, float target_pitch, bool resist_chg, float margin, const Location &final_dest, const Location &oa_dest)
|
2019-06-08 01:59:04 -03:00
|
|
|
{
|
2019-07-02 06:31:02 -03:00
|
|
|
const struct log_OABendyRuler pkt{
|
2019-08-05 03:22:05 -03:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_OA_BENDYRULER_MSG),
|
2019-06-08 01:59:04 -03:00
|
|
|
time_us : AP_HAL::micros64(),
|
2020-07-01 03:11:34 -03:00
|
|
|
type : type,
|
2019-08-05 03:22:05 -03:00
|
|
|
active : active,
|
|
|
|
target_yaw : (uint16_t)wrap_360(target_yaw),
|
|
|
|
yaw : (uint16_t)wrap_360(AP::ahrs().yaw_sensor * 0.01f),
|
2020-07-01 03:11:34 -03:00
|
|
|
target_pitch: (uint16_t)target_pitch,
|
2020-06-21 10:25:41 -03:00
|
|
|
resist_chg : resist_chg,
|
2019-08-05 03:22:05 -03:00
|
|
|
margin : margin,
|
2019-06-08 01:59:04 -03:00
|
|
|
final_lat : final_dest.lat,
|
|
|
|
final_lng : final_dest.lng,
|
2020-07-01 03:11:34 -03:00
|
|
|
final_alt : final_dest.alt,
|
2019-06-08 01:59:04 -03:00
|
|
|
oa_lat : oa_dest.lat,
|
2020-07-01 03:11:34 -03:00
|
|
|
oa_lng : oa_dest.lng,
|
|
|
|
oa_alt : oa_dest.alt
|
2019-08-05 03:22:05 -03:00
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
|
|
|
}
|
|
|
|
|
2019-09-07 01:56:51 -03:00
|
|
|
void AP_Logger::Write_OADijkstra(uint8_t state, uint8_t error_id, uint8_t curr_point, uint8_t tot_points, const Location &final_dest, const Location &oa_dest)
|
2019-08-05 03:22:05 -03:00
|
|
|
{
|
2019-07-02 06:31:02 -03:00
|
|
|
struct log_OADijkstra pkt{
|
2019-08-05 03:22:05 -03:00
|
|
|
LOG_PACKET_HEADER_INIT(LOG_OA_DIJKSTRA_MSG),
|
|
|
|
time_us : AP_HAL::micros64(),
|
|
|
|
state : state,
|
2019-09-07 01:56:51 -03:00
|
|
|
error_id : error_id,
|
2019-08-05 03:22:05 -03:00
|
|
|
curr_point : curr_point,
|
|
|
|
tot_points : tot_points,
|
|
|
|
final_lat : final_dest.lat,
|
|
|
|
final_lng : final_dest.lng,
|
|
|
|
oa_lat : oa_dest.lat,
|
|
|
|
oa_lng : oa_dest.lng
|
2019-06-08 01:59:04 -03:00
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
|
|
|
}
|
2020-07-21 14:00:18 -03:00
|
|
|
|
|
|
|
void AP_Logger::Write_SimpleAvoidance(uint8_t state, const Vector2f& desired_vel, const Vector2f& modified_vel, bool back_up)
|
|
|
|
{
|
|
|
|
struct log_SimpleAvoid pkt{
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_SIMPLE_AVOID_MSG),
|
|
|
|
time_us : AP_HAL::micros64(),
|
|
|
|
state : state,
|
|
|
|
desired_vel_x : desired_vel.x * 0.01f,
|
|
|
|
desired_vel_y : desired_vel.y * 0.01f,
|
|
|
|
modified_vel_x : modified_vel.x * 0.01f,
|
|
|
|
modified_vel_y : modified_vel.y * 0.01f,
|
|
|
|
backing_up : back_up,
|
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
|
|
|
}
|
2020-07-24 02:59:41 -03:00
|
|
|
|
|
|
|
void AP_Logger::Write_Winch(bool healthy, bool thread_end, bool moving, bool clutch, uint8_t mode, float desired_length, float length, float desired_rate, uint16_t tension, float voltage, int8_t temp)
|
|
|
|
{
|
|
|
|
struct log_Winch pkt{
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_WINCH_MSG),
|
|
|
|
time_us : AP_HAL::micros64(),
|
|
|
|
healthy : healthy,
|
|
|
|
thread_end : thread_end,
|
|
|
|
moving : moving,
|
|
|
|
clutch : clutch,
|
|
|
|
mode : mode,
|
|
|
|
desired_length : desired_length,
|
|
|
|
length : length,
|
|
|
|
desired_rate : desired_rate,
|
|
|
|
tension : tension,
|
|
|
|
voltage : voltage,
|
|
|
|
temp : temp
|
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
|
|
|
}
|
2020-09-09 04:16:39 -03:00
|
|
|
|
|
|
|
void AP_Logger::Write_PSC(const Vector3f &pos_target, const Vector3f &position, const Vector3f &vel_target, const Vector3f &velocity, const Vector3f &accel_target, const float &accel_x, const float &accel_y)
|
|
|
|
{
|
|
|
|
struct log_PSC pkt{
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_PSC_MSG),
|
|
|
|
time_us : AP_HAL::micros64(),
|
|
|
|
pos_target_x : pos_target.x * 0.01f,
|
|
|
|
pos_target_Y : pos_target.y * 0.01f,
|
|
|
|
position_x : position.x * 0.01f,
|
|
|
|
position_y : position.y * 0.01f,
|
|
|
|
vel_target_x : vel_target.x * 0.01f,
|
|
|
|
vel_target_y : vel_target.y * 0.01f,
|
|
|
|
velocity_x : velocity.x * 0.01f,
|
|
|
|
velocity_y : velocity.y * 0.01f,
|
|
|
|
accel_target_x : accel_target.x * 0.01f,
|
|
|
|
accel_target_y : accel_target.y * 0.01f,
|
|
|
|
accel_x : accel_x * 0.01f,
|
|
|
|
accel_y : accel_y * 0.01f
|
|
|
|
};
|
|
|
|
WriteBlock(&pkt, sizeof(pkt));
|
|
|
|
}
|