2015-06-01 02:04:25 -03:00
|
|
|
#include "Tracker.h"
|
|
|
|
|
2013-10-13 04:14:13 -03:00
|
|
|
/*
|
|
|
|
update INS and attitude
|
|
|
|
*/
|
2015-06-01 02:04:25 -03:00
|
|
|
void Tracker::update_ahrs()
|
2013-10-13 04:14:13 -03:00
|
|
|
{
|
|
|
|
ahrs.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
read and update compass
|
|
|
|
*/
|
2015-06-01 02:04:25 -03:00
|
|
|
void Tracker::update_compass(void)
|
2013-10-13 04:14:13 -03:00
|
|
|
{
|
2021-07-25 21:32:13 -03:00
|
|
|
compass.read();
|
2013-10-13 04:14:13 -03:00
|
|
|
}
|
|
|
|
|
2019-02-08 15:22:08 -04:00
|
|
|
// Save compass offsets
|
|
|
|
void Tracker::compass_save() {
|
2021-07-27 21:27:38 -03:00
|
|
|
if (AP::compass().available() &&
|
2019-02-08 15:22:08 -04:00
|
|
|
compass.get_learn_type() >= Compass::LEARN_INTERNAL &&
|
|
|
|
!hal.util->get_soft_armed()) {
|
|
|
|
compass.save_offsets();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-21 18:27:35 -03:00
|
|
|
/*
|
|
|
|
Accel calibration
|
|
|
|
*/
|
|
|
|
void Tracker::accel_cal_update() {
|
|
|
|
if (hal.util->get_soft_armed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ins.acal_update();
|
|
|
|
float trim_roll, trim_pitch;
|
2016-12-13 22:06:30 -04:00
|
|
|
if (ins.get_new_trim(trim_roll, trim_pitch)) {
|
2015-10-21 18:27:35 -03:00
|
|
|
ahrs.set_trim(Vector3f(trim_roll, trim_pitch, 0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-13 04:14:13 -03:00
|
|
|
/*
|
|
|
|
read the GPS
|
|
|
|
*/
|
2015-06-01 02:04:25 -03:00
|
|
|
void Tracker::update_GPS(void)
|
2013-10-13 04:14:13 -03:00
|
|
|
{
|
2014-03-31 04:32:14 -03:00
|
|
|
gps.update();
|
2014-03-26 22:04:42 -03:00
|
|
|
|
2014-03-31 04:32:14 -03:00
|
|
|
static uint32_t last_gps_msg_ms;
|
2014-03-26 22:04:42 -03:00
|
|
|
static uint8_t ground_start_count = 5;
|
2014-03-31 04:32:14 -03:00
|
|
|
if (gps.last_message_time_ms() != last_gps_msg_ms &&
|
|
|
|
gps.status() >= AP_GPS::GPS_OK_FIX_3D) {
|
|
|
|
last_gps_msg_ms = gps.last_message_time_ms();
|
2014-03-26 22:04:42 -03:00
|
|
|
|
2016-12-13 22:06:30 -04:00
|
|
|
if (ground_start_count > 1) {
|
2014-03-26 22:04:42 -03:00
|
|
|
ground_start_count--;
|
|
|
|
} else if (ground_start_count == 1) {
|
|
|
|
// We countdown N number of good GPS fixes
|
|
|
|
// so that the altitude is more accurate
|
|
|
|
// -------------------------------------
|
2016-10-04 08:27:46 -03:00
|
|
|
if (current_loc.lat == 0 && current_loc.lng == 0) {
|
2014-03-26 22:04:42 -03:00
|
|
|
ground_start_count = 5;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Now have an initial GPS position
|
|
|
|
// use it as the HOME position in future startups
|
2014-03-31 04:32:14 -03:00
|
|
|
current_loc = gps.location();
|
2019-02-20 21:43:55 -04:00
|
|
|
if (!set_home(current_loc)) {
|
|
|
|
// silently ignored
|
|
|
|
}
|
2014-03-26 22:04:42 -03:00
|
|
|
ground_start_count = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-13 04:14:13 -03:00
|
|
|
}
|
|
|
|
|
2018-03-01 23:38:30 -04:00
|
|
|
void Tracker::handle_battery_failsafe(const char* type_str, const int8_t action)
|
|
|
|
{
|
|
|
|
// NOP
|
|
|
|
// useful failsafes in the future would include actually recalling the vehicle
|
|
|
|
// that is tracked before the tracker loses power to continue tracking it
|
|
|
|
}
|