2015-12-27 03:05:14 -04:00
|
|
|
#include "Tracker.h"
|
|
|
|
|
|
|
|
#if LOGGING_ENABLED == ENABLED
|
|
|
|
|
2019-01-18 00:23:42 -04:00
|
|
|
// Code to Write and Read packets from AP_Logger log memory
|
2015-12-27 03:05:14 -04:00
|
|
|
|
|
|
|
// Write an attitude packet
|
|
|
|
void Tracker::Log_Write_Attitude()
|
|
|
|
{
|
|
|
|
Vector3f targets;
|
2016-02-09 04:20:55 -04:00
|
|
|
targets.y = nav_status.pitch * 100.0f;
|
2016-04-27 06:35:18 -03:00
|
|
|
targets.z = wrap_360_cd(nav_status.bearing * 100.0f);
|
2021-01-09 04:07:21 -04:00
|
|
|
ahrs.Write_Attitude(targets);
|
2019-07-02 20:54:48 -03:00
|
|
|
AP::ahrs_navekf().Log_Write();
|
2021-01-09 04:07:21 -04:00
|
|
|
ahrs.Write_AHRS2();
|
2015-12-27 03:05:14 -04:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
2019-01-17 18:16:24 -04:00
|
|
|
sitl.Log_Write_SIMSTATE();
|
2015-12-27 03:05:14 -04:00
|
|
|
#endif
|
2021-01-09 04:07:21 -04:00
|
|
|
ahrs.Write_POS();
|
2015-12-27 03:05:14 -04:00
|
|
|
}
|
|
|
|
|
2016-05-12 02:17:31 -03:00
|
|
|
struct PACKED log_Vehicle_Baro {
|
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
uint64_t time_us;
|
|
|
|
float press;
|
|
|
|
float alt_diff;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Write a vehicle baro packet
|
|
|
|
void Tracker::Log_Write_Vehicle_Baro(float pressure, float altitude)
|
|
|
|
{
|
|
|
|
struct log_Vehicle_Baro pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_V_BAR_MSG),
|
|
|
|
time_us : AP_HAL::micros64(),
|
|
|
|
press : pressure,
|
|
|
|
alt_diff : altitude
|
|
|
|
};
|
2019-01-18 00:23:42 -04:00
|
|
|
logger.WriteBlock(&pkt, sizeof(pkt));
|
2016-05-12 02:17:31 -03:00
|
|
|
}
|
|
|
|
|
2016-06-09 03:33:07 -03:00
|
|
|
struct PACKED log_Vehicle_Pos {
|
|
|
|
LOG_PACKET_HEADER;
|
|
|
|
uint64_t time_us;
|
|
|
|
int32_t vehicle_lat;
|
|
|
|
int32_t vehicle_lng;
|
|
|
|
int32_t vehicle_alt;
|
2016-06-13 00:52:03 -03:00
|
|
|
float vehicle_vel_x;
|
|
|
|
float vehicle_vel_y;
|
|
|
|
float vehicle_vel_z;
|
2016-06-09 03:33:07 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Write a vehicle pos packet
|
2016-06-13 00:52:03 -03:00
|
|
|
void Tracker::Log_Write_Vehicle_Pos(int32_t lat, int32_t lng, int32_t alt, const Vector3f& vel)
|
2016-06-09 11:13:51 -03:00
|
|
|
{
|
2016-06-09 03:33:07 -03:00
|
|
|
struct log_Vehicle_Pos pkt = {
|
|
|
|
LOG_PACKET_HEADER_INIT(LOG_V_POS_MSG),
|
|
|
|
time_us : AP_HAL::micros64(),
|
2016-06-09 11:13:51 -03:00
|
|
|
vehicle_lat : lat,
|
|
|
|
vehicle_lng : lng,
|
|
|
|
vehicle_alt : alt,
|
2016-06-13 00:52:03 -03:00
|
|
|
vehicle_vel_x : vel.x,
|
|
|
|
vehicle_vel_y : vel.y,
|
|
|
|
vehicle_vel_z : vel.z,
|
2016-06-09 03:33:07 -03:00
|
|
|
};
|
2019-01-18 00:23:42 -04:00
|
|
|
logger.WriteBlock(&pkt, sizeof(pkt));
|
2016-06-09 03:33:07 -03:00
|
|
|
}
|
2016-05-12 02:17:31 -03:00
|
|
|
|
2020-03-26 20:39:59 -03:00
|
|
|
// @LoggerMessage: VBAR
|
|
|
|
// @Description: Information received from tracked vehicle; barometer data
|
2020-04-07 04:36:53 -03:00
|
|
|
// @Field: TimeUS: Time since system startup
|
|
|
|
// @Field: Press: vehicle barometric pressure
|
2020-03-26 20:39:59 -03:00
|
|
|
// @Field: AltDiff: altitude difference based on difference on barometric pressure
|
|
|
|
|
|
|
|
// @LoggerMessage: VPOS
|
|
|
|
// @Description: Information received from tracked vehicle; barometer position data
|
2020-04-07 04:36:53 -03:00
|
|
|
// @Field: TimeUS: Time since system startup
|
2020-03-26 20:39:59 -03:00
|
|
|
// @Field: Lat: tracked vehicle latitude
|
|
|
|
// @Field: Lng: tracked vehicle longitude
|
|
|
|
// @Field: Alt: tracked vehicle altitude
|
|
|
|
// @Field: VelX: tracked vehicle velocity, latitude component
|
|
|
|
// @Field: VelY: tracked vehicle velocity, longitude component
|
|
|
|
// @Field: VelZ: tracked vehicle velocity, vertical component, down
|
|
|
|
|
2017-09-05 21:53:00 -03: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
|
2017-09-05 21:53:00 -03:00
|
|
|
// units and "Format characters" for field type information
|
2015-12-27 03:05:14 -04:00
|
|
|
const struct LogStructure Tracker::log_structure[] = {
|
|
|
|
LOG_COMMON_STRUCTURES,
|
2016-05-12 02:17:31 -03:00
|
|
|
{LOG_V_BAR_MSG, sizeof(log_Vehicle_Baro),
|
2017-09-05 21:53:00 -03:00
|
|
|
"VBAR", "Qff", "TimeUS,Press,AltDiff", "sPm", "F00" },
|
2016-06-09 03:33:07 -03:00
|
|
|
{LOG_V_POS_MSG, sizeof(log_Vehicle_Pos),
|
2017-09-05 21:53:00 -03:00
|
|
|
"VPOS", "QLLefff", "TimeUS,Lat,Lng,Alt,VelX,VelY,VelZ", "sddmnnn", "FGGB000" }
|
2015-12-27 03:05:14 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
void Tracker::Log_Write_Vehicle_Startup_Messages()
|
|
|
|
{
|
2019-09-13 12:41:55 -03:00
|
|
|
logger.Write_Mode((uint8_t)mode->number(), ModeReason::INITIALISED);
|
2019-01-18 00:23:42 -04:00
|
|
|
gps.Write_AP_Logger_Log_Startup_messages();
|
2015-12-27 03:05:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Tracker::log_init(void)
|
|
|
|
{
|
2019-01-18 00:23:42 -04:00
|
|
|
logger.Init(log_structure, ARRAY_SIZE(log_structure));
|
2015-12-27 03:05:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#else // LOGGING_ENABLED
|
|
|
|
|
|
|
|
void Tracker::Log_Write_Attitude(void) {}
|
|
|
|
|
|
|
|
void Tracker::log_init(void) {}
|
2017-01-02 01:43:51 -04:00
|
|
|
void Tracker::Log_Write_Vehicle_Pos(int32_t lat, int32_t lng, int32_t alt, const Vector3f& vel) {}
|
|
|
|
void Tracker::Log_Write_Vehicle_Baro(float pressure, float altitude) {}
|
2018-04-20 20:18:04 -03:00
|
|
|
void Tracker::Log_Write_Vehicle_Startup_Messages() {}
|
2015-12-27 03:05:14 -04:00
|
|
|
|
|
|
|
#endif // LOGGING_ENABLED
|