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),
|
2017-11-26 21:51:11 -04:00
|
|
|
SCHED_TASK(update_battery, 10, 1500),
|
2015-12-26 00:08:38 -04:00
|
|
|
SCHED_TASK(update_barometer, 10, 1500),
|
|
|
|
SCHED_TASK(gcs_update, 50, 1700),
|
|
|
|
SCHED_TASK(gcs_data_stream_send, 50, 3000),
|
|
|
|
SCHED_TASK(compass_accumulate, 50, 1500),
|
|
|
|
SCHED_TASK(barometer_accumulate, 50, 900),
|
2015-12-27 03:05:14 -04:00
|
|
|
SCHED_TASK(ten_hz_logging_loop, 10, 300),
|
|
|
|
SCHED_TASK(dataflash_periodic, 50, 300),
|
2017-10-03 21:13:23 -03:00
|
|
|
SCHED_TASK(ins_periodic, 50, 50),
|
2015-12-26 00:08:38 -04:00
|
|
|
SCHED_TASK(update_notify, 50, 100),
|
|
|
|
SCHED_TASK(check_usb_mux, 10, 300),
|
|
|
|
SCHED_TASK(gcs_retry_deferred, 50, 1000),
|
|
|
|
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
|
2015-07-06 12:30:40 -03:00
|
|
|
scheduler.init(&scheduler_tasks[0], ARRAY_SIZE(scheduler_tasks));
|
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-12-27 03:05:14 -04:00
|
|
|
void Tracker::dataflash_periodic(void)
|
|
|
|
{
|
|
|
|
DataFlash.periodic_tasks();
|
|
|
|
}
|
|
|
|
|
2017-10-03 21:13:23 -03:00
|
|
|
void Tracker::ins_periodic()
|
|
|
|
{
|
|
|
|
ins.periodic();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-27 03:05:14 -04:00
|
|
|
void Tracker::ten_hz_logging_loop()
|
|
|
|
{
|
|
|
|
if (should_log(MASK_LOG_IMU)) {
|
|
|
|
DataFlash.Log_Write_IMU(ins);
|
|
|
|
}
|
|
|
|
if (should_log(MASK_LOG_ATTITUDE)) {
|
|
|
|
Log_Write_Attitude();
|
|
|
|
}
|
|
|
|
if (should_log(MASK_LOG_RCIN)) {
|
|
|
|
DataFlash.Log_Write_RCIN();
|
|
|
|
}
|
|
|
|
if (should_log(MASK_LOG_RCOUT)) {
|
|
|
|
DataFlash.Log_Write_RCOUT();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
2017-12-12 21:06:15 -04:00
|
|
|
: DataFlash(fwver.fw_string, g.log_bitmask)
|
2015-06-08 01:14:10 -03:00
|
|
|
{
|
|
|
|
memset(¤t_loc, 0, sizeof(current_loc));
|
|
|
|
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);
|