AP_HAL_ChibiOS: added NxtPX4v2
[ardupilot.git] / AntennaTracker / sensors.cpp
blob72094fe15aa6d4cea7792b1c5e1a0846243589cf
1 #include "Tracker.h"
3 /*
4 update INS and attitude
5 */
6 void Tracker::update_ahrs()
8 ahrs.update();
12 read and update compass
14 void Tracker::update_compass(void)
16 compass.read();
19 // Save compass offsets
20 void Tracker::compass_save() {
21 if (AP::compass().available() &&
22 compass.get_learn_type() >= Compass::LEARN_INTERNAL &&
23 !hal.util->get_soft_armed()) {
24 compass.save_offsets();
29 read the GPS
31 void Tracker::update_GPS(void)
33 gps.update();
35 static uint32_t last_gps_msg_ms;
36 static uint8_t ground_start_count = 5;
37 if (gps.last_message_time_ms() != last_gps_msg_ms &&
38 gps.status() >= AP_GPS::GPS_OK_FIX_3D) {
39 last_gps_msg_ms = gps.last_message_time_ms();
41 if (ground_start_count > 1) {
42 ground_start_count--;
43 } else if (ground_start_count == 1) {
44 // We countdown N number of good GPS fixes
45 // so that the altitude is more accurate
46 // -------------------------------------
47 if (current_loc.lat == 0 && current_loc.lng == 0) {
48 ground_start_count = 5;
50 } else {
51 // Now have an initial GPS position
52 // use it as the HOME position in future startups
53 current_loc = gps.location();
54 IGNORE_RETURN(set_home(current_loc, false));
55 ground_start_count = 0;
61 void Tracker::handle_battery_failsafe(const char* type_str, const int8_t action)
63 // NOP
64 // useful failsafes in the future would include actually recalling the vehicle
65 // that is tracked before the tracker loses power to continue tracking it