2 Lead developers: Matthew Ridley and Andrew Tridgell
4 Please contribute your ideas! See https://ardupilot.org/dev for details
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #define FORCE_VERSION_H_INCLUDE
24 #undef FORCE_VERSION_H_INCLUDE
26 #define SCHED_TASK(func, _interval_ticks, _max_time_micros, _prio) SCHED_TASK_CLASS(Tracker, &tracker, func, _interval_ticks, _max_time_micros, _prio)
29 All entries in this table must be ordered by priority.
31 This table is interleaved with the table in AP_Vehicle to determine
32 the order in which tasks are run. Convenience methods SCHED_TASK
33 and SCHED_TASK_CLASS are provided to build entries in this structure:
36 - name of static function to call
37 - rate (in Hertz) at which the function should be called
38 - expected time (in MicroSeconds) that the function should take to run
39 - priority (0 through 255, lower number meaning higher priority)
41 SCHED_TASK_CLASS arguments:
42 - class name of method to be called
43 - instance on which to call the method
44 - method to call on that instance
45 - rate (in Hertz) at which the method should be called
46 - expected time (in MicroSeconds) that the method should take to run
47 - priority (0 through 255, lower number meaning higher priority)
50 const AP_Scheduler::Task
Tracker::scheduler_tasks
[] = {
51 SCHED_TASK(update_ahrs
, 50, 1000, 5),
52 SCHED_TASK(read_radio
, 50, 200, 10),
53 SCHED_TASK(update_tracking
, 50, 1000, 15),
54 SCHED_TASK(update_GPS
, 10, 4000, 20),
55 SCHED_TASK(update_compass
, 10, 1500, 25),
56 SCHED_TASK(compass_save
, 0.02, 200, 30),
57 SCHED_TASK_CLASS(AP_BattMonitor
, &tracker
.battery
, read
, 10, 1500, 35),
58 SCHED_TASK_CLASS(AP_Baro
, &tracker
.barometer
, update
, 10, 1500, 40),
59 SCHED_TASK_CLASS(GCS
, (GCS
*)&tracker
._gcs
, update_receive
, 50, 1700, 45),
60 SCHED_TASK_CLASS(GCS
, (GCS
*)&tracker
._gcs
, update_send
, 50, 3000, 50),
61 #if HAL_LOGGING_ENABLED
62 SCHED_TASK(ten_hz_logging_loop
, 10, 300, 60),
63 SCHED_TASK_CLASS(AP_Logger
, &tracker
.logger
, periodic_tasks
, 50, 300, 65),
65 SCHED_TASK_CLASS(AP_InertialSensor
, &tracker
.ins
, periodic
, 50, 50, 70),
66 SCHED_TASK(one_second_loop
, 1, 3900, 80),
67 SCHED_TASK(stats_update
, 1, 200, 90),
70 void Tracker::get_scheduler_tasks(const AP_Scheduler::Task
*&tasks
,
74 tasks
= &scheduler_tasks
[0];
75 task_count
= ARRAY_SIZE(scheduler_tasks
);
76 log_bit
= (uint32_t)-1;
79 void Tracker::one_second_loop()
81 // sync MAVLink system ID
82 mavlink_system
.sysid
= g
.sysid_this_mav
;
84 // update assigned functions and enable auxiliary servos
85 SRV_Channels::enable_aux_servos();
87 // updated armed/disarmed status LEDs
88 update_armed_disarmed();
90 if (!ahrs
.home_is_set()) {
91 // set home to current location
93 if (ahrs
.get_location(temp_loc
)) {
94 if (!set_home(temp_loc
, false)) {
100 // need to set "likely flying" when armed to allow for compass
102 set_likely_flying(hal
.util
->get_soft_armed());
104 AP_Notify::flags
.flying
= hal
.util
->get_soft_armed();
106 g
.pidYaw2Srv
.set_notch_sample_rate(AP::scheduler().get_filtered_loop_rate_hz());
109 #if HAL_LOGGING_ENABLED
110 void Tracker::ten_hz_logging_loop()
112 if (should_log(MASK_LOG_IMU
)) {
113 AP::ins().Write_IMU();
115 if (should_log(MASK_LOG_ATTITUDE
)) {
116 Log_Write_Attitude();
118 if (should_log(MASK_LOG_RCIN
)) {
121 if (should_log(MASK_LOG_RCOUT
)) {
122 logger
.Write_RCOUT();
127 Mode
*Tracker::mode_from_mode_num(const Mode::Number num
)
131 case Mode::Number::MANUAL
:
134 case Mode::Number::STOP
:
137 case Mode::Number::SCAN
:
140 case Mode::Number::GUIDED
:
143 case Mode::Number::SERVOTEST
:
144 ret
= &mode_servotest
;
146 case Mode::Number::AUTO
:
149 case Mode::Number::INITIALISING
:
150 ret
= &mode_initialising
;
159 void Tracker::stats_update(void)
161 AP::stats()->set_flying(hal
.util
->get_soft_armed());
164 const AP_HAL::HAL
& hal
= AP_HAL::get_HAL();
167 AP_Vehicle
& vehicle
= tracker
;
169 AP_HAL_MAIN_CALLBACKS(&tracker
);