2013-10-13 04:14:13 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
2015-06-01 02:04:25 -03:00
|
|
|
#include "Tracker.h"
|
|
|
|
|
2016-05-23 22:31:41 -03:00
|
|
|
void Tracker::init_barometer(bool full_calibration)
|
2013-10-13 04:14:13 -03:00
|
|
|
{
|
2015-11-03 20:57:18 -04:00
|
|
|
gcs_send_text(MAV_SEVERITY_INFO, "Calibrating barometer");
|
2016-05-23 22:31:41 -03:00
|
|
|
if (full_calibration) {
|
|
|
|
barometer.calibrate();
|
|
|
|
} else {
|
|
|
|
barometer.update_calibration();
|
|
|
|
}
|
2015-11-18 14:47:45 -04:00
|
|
|
gcs_send_text(MAV_SEVERITY_INFO, "Barometer calibration complete");
|
2013-10-13 04:14:13 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// read the barometer and return the updated altitude in meters
|
2015-06-01 02:04:25 -03:00
|
|
|
void Tracker::update_barometer(void)
|
2013-10-13 04:14:13 -03:00
|
|
|
{
|
2015-01-05 07:27:54 -04:00
|
|
|
barometer.update();
|
2015-12-27 03:05:14 -04:00
|
|
|
if (should_log(MASK_LOG_IMU)) {
|
|
|
|
Log_Write_Baro();
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
if (g.compass_enabled && compass.read()) {
|
|
|
|
ahrs.set_compass(&compass);
|
2014-02-15 22:21:58 -04:00
|
|
|
compass.learn_offsets();
|
2015-12-27 03:05:14 -04:00
|
|
|
if (should_log(MASK_LOG_COMPASS)) {
|
|
|
|
DataFlash.Log_Write_Compass(compass);
|
|
|
|
}
|
2013-10-13 04:14:13 -03:00
|
|
|
} else {
|
|
|
|
ahrs.set_compass(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
if the compass is enabled then try to accumulate a reading
|
|
|
|
*/
|
2015-06-01 02:04:25 -03:00
|
|
|
void Tracker::compass_accumulate(void)
|
2013-10-13 04:14:13 -03:00
|
|
|
{
|
|
|
|
if (g.compass_enabled) {
|
|
|
|
compass.accumulate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
try to accumulate a baro reading
|
|
|
|
*/
|
2015-06-01 02:04:25 -03:00
|
|
|
void Tracker::barometer_accumulate(void)
|
2013-10-13 04:14:13 -03:00
|
|
|
{
|
|
|
|
barometer.accumulate();
|
|
|
|
}
|
|
|
|
|
2015-07-31 02:52:02 -03:00
|
|
|
/*
|
|
|
|
calibrate compass
|
|
|
|
*/
|
|
|
|
void Tracker::compass_cal_update() {
|
|
|
|
if (!hal.util->get_soft_armed()) {
|
|
|
|
compass.compass_cal_update();
|
|
|
|
}
|
|
|
|
}
|
2013-10-13 04:14:13 -03:00
|
|
|
|
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;
|
|
|
|
if(ins.get_new_trim(trim_roll, trim_pitch)) {
|
|
|
|
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
|
|
|
|
|
|
|
if(ground_start_count > 1) {
|
|
|
|
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();
|
2014-03-26 22:04:42 -03:00
|
|
|
set_home(current_loc);
|
|
|
|
|
|
|
|
// set system clock for log timestamps
|
2016-01-21 02:57:52 -04:00
|
|
|
uint64_t gps_timestamp = gps.time_epoch_usec();
|
|
|
|
|
|
|
|
hal.util->set_system_clock(gps_timestamp);
|
|
|
|
|
|
|
|
// update signing timestamp
|
|
|
|
GCS_MAVLINK::update_signing_timestamp(gps_timestamp);
|
2014-03-26 22:04:42 -03:00
|
|
|
|
|
|
|
if (g.compass_enabled) {
|
|
|
|
// Set compass declination automatically
|
2014-03-31 04:32:14 -03:00
|
|
|
compass.set_initial_location(gps.location().lat, gps.location().lng);
|
2014-03-26 22:04:42 -03:00
|
|
|
}
|
|
|
|
ground_start_count = 0;
|
|
|
|
}
|
|
|
|
}
|
2015-12-27 03:05:14 -04:00
|
|
|
|
|
|
|
// log GPS data
|
|
|
|
if (should_log(MASK_LOG_GPS)) {
|
2016-05-03 19:26:39 -03:00
|
|
|
DataFlash.Log_Write_GPS(gps, 0);
|
2015-12-27 03:05:14 -04:00
|
|
|
}
|
2014-03-26 22:04:42 -03:00
|
|
|
}
|
2013-10-13 04:14:13 -03:00
|
|
|
}
|
|
|
|
|