2013-10-13 04:14:13 -03:00
|
|
|
/*
|
|
|
|
Lead developers: Matthew Ridley and Andrew Tridgell
|
|
|
|
|
2016-04-23 17:58:13 -03:00
|
|
|
Please contribute your ideas! See http://dev.ardupilot.org for details
|
2013-10-13 04:14:13 -03:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-06-01 02:04:25 -03:00
|
|
|
#include "Tracker.h"
|
2017-09-12 15:25:20 -03:00
|
|
|
|
|
|
|
#define FORCE_VERSION_H_INCLUDE
|
2016-05-05 19:10:08 -03:00
|
|
|
#include "version.h"
|
2017-09-12 15:25:20 -03:00
|
|
|
#undef FORCE_VERSION_H_INCLUDE
|
2013-10-13 04:14:13 -03:00
|
|
|
|
2015-12-26 00:08:38 -04:00
|
|
|
#define SCHED_TASK(func, _interval_ticks, _max_time_micros) SCHED_TASK_CLASS(Tracker, &tracker, func, _interval_ticks, _max_time_micros)
|
2014-10-06 02:55:45 -03:00
|
|
|
|
2013-10-13 04:14:13 -03:00
|
|
|
/*
|
|
|
|
scheduler table - all regular tasks apart from the fast_loop()
|
|
|
|
should be listed here, along with how often they should be called
|
|
|
|
(in 20ms units) and the maximum time they are expected to take (in
|
|
|
|
microseconds)
|
|
|
|
*/
|
2015-10-25 14:03:46 -03:00
|
|
|
const AP_Scheduler::Task Tracker::scheduler_tasks[] = {
|
2015-12-26 00:08:38 -04:00
|
|
|
SCHED_TASK(update_ahrs, 50, 1000),
|
|
|
|
SCHED_TASK(read_radio, 50, 200),
|
|
|
|
SCHED_TASK(update_tracking, 50, 1000),
|
|
|
|
SCHED_TASK(update_GPS, 10, 4000),
|
|
|
|
SCHED_TASK(update_compass, 10, 1500),
|
2018-02-12 02:01:28 -04:00
|
|
|
SCHED_TASK_CLASS(AP_BattMonitor, &tracker.battery, read, 10, 1500),
|
2018-04-11 09:55:31 -03:00
|
|
|
SCHED_TASK_CLASS(AP_Baro, &tracker.barometer, update, 10, 1500),
|
2018-11-22 20:38:07 -04:00
|
|
|
SCHED_TASK_CLASS(GCS, (GCS*)&tracker._gcs, update_receive, 50, 1700),
|
|
|
|
SCHED_TASK_CLASS(GCS, (GCS*)&tracker._gcs, update_send, 50, 3000),
|
2018-02-12 02:01:28 -04:00
|
|
|
SCHED_TASK_CLASS(AP_Baro, &tracker.barometer, accumulate, 50, 900),
|
2015-12-27 03:05:14 -04:00
|
|
|
SCHED_TASK(ten_hz_logging_loop, 10, 300),
|
2018-04-20 20:18:04 -03:00
|
|
|
#if LOGGING_ENABLED == ENABLED
|
2019-01-18 00:23:42 -04:00
|
|
|
SCHED_TASK_CLASS(AP_Logger, &tracker.logger, periodic_tasks, 50, 300),
|
2018-04-20 20:18:04 -03:00
|
|
|
#endif
|
2018-02-12 02:01:28 -04:00
|
|
|
SCHED_TASK_CLASS(AP_InertialSensor, &tracker.ins, periodic, 50, 50),
|
|
|
|
SCHED_TASK_CLASS(AP_Notify, &tracker.notify, update, 50, 100),
|
2015-12-26 00:08:38 -04:00
|
|
|
SCHED_TASK(one_second_loop, 1, 3900),
|
|
|
|
SCHED_TASK(compass_cal_update, 50, 100),
|
2015-10-21 18:27:35 -03:00
|
|
|
SCHED_TASK(accel_cal_update, 10, 100)
|
2013-10-13 04:14:13 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
setup the sketch - called once on startup
|
|
|
|
*/
|
2015-06-01 02:04:25 -03:00
|
|
|
void Tracker::setup()
|
2013-10-13 04:14:13 -03:00
|
|
|
{
|
|
|
|
// load the default values of variables listed in var_info[]
|
|
|
|
AP_Param::setup_sketch_defaults();
|
|
|
|
|
|
|
|
init_tracker();
|
|
|
|
|
|
|
|
// initialise the main loop scheduler
|
2018-02-09 18:36:48 -04:00
|
|
|
scheduler.init(&scheduler_tasks[0], ARRAY_SIZE(scheduler_tasks), (uint32_t)-1);
|
2013-10-13 04:14:13 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
loop() is called continuously
|
|
|
|
*/
|
2015-06-01 02:04:25 -03:00
|
|
|
void Tracker::loop()
|
2013-10-13 04:14:13 -03:00
|
|
|
{
|
|
|
|
// wait for an INS sample
|
2014-10-15 20:33:36 -03:00
|
|
|
ins.wait_for_sample();
|
2013-10-13 04:14:13 -03:00
|
|
|
|
|
|
|
// tell the scheduler one tick has passed
|
|
|
|
scheduler.tick();
|
|
|
|
|
|
|
|
scheduler.run(19900UL);
|
|
|
|
}
|
|
|
|
|
2015-06-01 02:04:25 -03:00
|
|
|
void Tracker::one_second_loop()
|
2013-10-13 04:14:13 -03:00
|
|
|
{
|
|
|
|
// send a heartbeat
|
2017-07-07 23:02:52 -03:00
|
|
|
gcs().send_message(MSG_HEARTBEAT);
|
2013-10-13 04:14:13 -03:00
|
|
|
|
|
|
|
// make it possible to change orientation at runtime
|
|
|
|
ahrs.set_orientation();
|
|
|
|
|
|
|
|
// sync MAVLink system ID
|
|
|
|
mavlink_system.sysid = g.sysid_this_mav;
|
|
|
|
|
2018-09-05 05:47:35 -03:00
|
|
|
// update assigned functions and enable auxiliary servos
|
|
|
|
SRV_Channels::enable_aux_servos();
|
|
|
|
|
2014-09-29 07:40:25 -03:00
|
|
|
// updated armed/disarmed status LEDs
|
|
|
|
update_armed_disarmed();
|
|
|
|
|
2015-06-01 02:04:25 -03:00
|
|
|
one_second_counter++;
|
2013-10-13 04:14:13 -03:00
|
|
|
|
2015-06-01 02:04:25 -03:00
|
|
|
if (one_second_counter >= 60) {
|
2016-12-13 22:06:30 -04:00
|
|
|
if (g.compass_enabled) {
|
2013-10-13 04:14:13 -03:00
|
|
|
compass.save_offsets();
|
|
|
|
}
|
2015-06-01 02:04:25 -03:00
|
|
|
one_second_counter = 0;
|
2013-10-13 04:14:13 -03:00
|
|
|
}
|
2018-05-16 07:23:29 -03:00
|
|
|
|
|
|
|
if (!ahrs.home_is_set()) {
|
|
|
|
// set home to current location
|
|
|
|
Location temp_loc;
|
|
|
|
if (ahrs.get_location(temp_loc)) {
|
|
|
|
set_home(temp_loc);
|
|
|
|
}
|
|
|
|
}
|
2018-10-19 04:31:34 -03:00
|
|
|
|
|
|
|
// need to set "likely flying" when armed to allow for compass
|
|
|
|
// learning to run
|
|
|
|
ahrs.set_likely_flying(hal.util->get_soft_armed());
|
2013-10-13 04:14:13 -03:00
|
|
|
}
|
|
|
|
|
2015-12-27 03:05:14 -04:00
|
|
|
void Tracker::ten_hz_logging_loop()
|
|
|
|
{
|
|
|
|
if (should_log(MASK_LOG_IMU)) {
|
2019-01-18 00:24:08 -04:00
|
|
|
logger.Write_IMU();
|
2015-12-27 03:05:14 -04:00
|
|
|
}
|
|
|
|
if (should_log(MASK_LOG_ATTITUDE)) {
|
|
|
|
Log_Write_Attitude();
|
|
|
|
}
|
|
|
|
if (should_log(MASK_LOG_RCIN)) {
|
2019-01-18 00:24:08 -04:00
|
|
|
logger.Write_RCIN();
|
2015-12-27 03:05:14 -04:00
|
|
|
}
|
|
|
|
if (should_log(MASK_LOG_RCOUT)) {
|
2019-01-18 00:24:08 -04:00
|
|
|
logger.Write_RCOUT();
|
2015-12-27 03:05:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-16 17:22:11 -03:00
|
|
|
const AP_HAL::HAL& hal = AP_HAL::get_HAL();
|
2015-06-01 02:04:25 -03:00
|
|
|
|
|
|
|
Tracker::Tracker(void)
|
2019-01-18 00:23:42 -04:00
|
|
|
: logger(g.log_bitmask)
|
2015-06-08 01:14:10 -03:00
|
|
|
{
|
|
|
|
memset(&vehicle, 0, sizeof(vehicle));
|
|
|
|
}
|
2015-06-01 02:04:25 -03:00
|
|
|
|
|
|
|
Tracker tracker;
|
|
|
|
|
2015-10-19 15:32:37 -03:00
|
|
|
AP_HAL_MAIN_CALLBACKS(&tracker);
|