2014-11-27 21:59:47 -04:00
|
|
|
//
|
|
|
|
// Simple test for the AP_Scheduler interface
|
|
|
|
//
|
|
|
|
|
2015-08-11 03:28:45 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include <AP_InertialSensor/AP_InertialSensor.h>
|
2021-02-08 10:05:31 -04:00
|
|
|
#include <AP_ExternalAHRS/AP_ExternalAHRS.h>
|
2015-08-11 03:28:45 -03:00
|
|
|
#include <AP_Scheduler/AP_Scheduler.h>
|
2016-10-04 05:07:21 -03:00
|
|
|
#include <AP_BoardConfig/AP_BoardConfig.h>
|
2019-01-18 00:23:42 -04:00
|
|
|
#include <AP_Logger/AP_Logger.h>
|
2014-11-27 21:59:47 -04:00
|
|
|
|
2015-10-16 17:22:11 -03:00
|
|
|
const AP_HAL::HAL& hal = AP_HAL::get_HAL();
|
2014-11-27 21:59:47 -04:00
|
|
|
|
2017-11-13 03:11:27 -04:00
|
|
|
AP_Int32 log_bitmask;
|
2019-01-18 00:23:42 -04:00
|
|
|
AP_Logger AP_Logger{log_bitmask};
|
2017-11-13 03:11:27 -04:00
|
|
|
|
2015-06-01 04:42:32 -03:00
|
|
|
class SchedTest {
|
|
|
|
public:
|
|
|
|
void setup();
|
|
|
|
void loop();
|
2014-11-27 21:59:47 -04:00
|
|
|
|
2015-06-01 04:42:32 -03:00
|
|
|
private:
|
2014-11-27 21:59:47 -04:00
|
|
|
|
2017-12-12 21:06:14 -04:00
|
|
|
AP_InertialSensor ins;
|
2021-02-08 10:05:31 -04:00
|
|
|
#if HAL_EXTERNAL_AHRS_ENABLED
|
|
|
|
AP_ExternalAHRS eAHRS;
|
|
|
|
#endif // HAL_EXTERNAL_AHRS_ENABLED
|
2022-04-01 16:57:03 -03:00
|
|
|
AP_Scheduler scheduler;
|
2015-06-01 04:42:32 -03:00
|
|
|
|
|
|
|
uint32_t ins_counter;
|
|
|
|
static const AP_Scheduler::Task scheduler_tasks[];
|
|
|
|
|
|
|
|
void ins_update(void);
|
|
|
|
void one_hz_print(void);
|
|
|
|
void five_second_call(void);
|
|
|
|
};
|
|
|
|
|
2017-12-12 21:06:14 -04:00
|
|
|
static AP_BoardConfig board_config;
|
2015-06-01 04:42:32 -03:00
|
|
|
static SchedTest schedtest;
|
|
|
|
|
2021-11-13 23:18:09 -04:00
|
|
|
#define SCHED_TASK(func, _interval_ticks, _max_time_micros, _priority) SCHED_TASK_CLASS(SchedTest, &schedtest, func, _interval_ticks, _max_time_micros, _priority)
|
2014-11-27 21:59:47 -04:00
|
|
|
|
|
|
|
/*
|
2021-11-13 23:18:09 -04:00
|
|
|
scheduler table - all regular tasks should be listed here.
|
|
|
|
|
|
|
|
All entries in this table must be ordered by priority.
|
|
|
|
|
|
|
|
This table is interleaved with the table in AP_Vehicle to determine
|
|
|
|
the order in which tasks are run. Convenience methods SCHED_TASK
|
|
|
|
and SCHED_TASK_CLASS are provided to build entries in this structure:
|
|
|
|
|
|
|
|
SCHED_TASK arguments:
|
|
|
|
- name of static function to call
|
|
|
|
- rate (in Hertz) at which the function should be called
|
|
|
|
- expected time (in MicroSeconds) that the function should take to run
|
|
|
|
- priority (0 through 255, lower number meaning higher priority)
|
|
|
|
|
|
|
|
SCHED_TASK_CLASS arguments:
|
|
|
|
- class name of method to be called
|
|
|
|
- instance on which to call the method
|
|
|
|
- method to call on that instance
|
|
|
|
- rate (in Hertz) at which the method should be called
|
|
|
|
- expected time (in MicroSeconds) that the method should take to run
|
|
|
|
- priority (0 through 255, lower number meaning higher priority)
|
|
|
|
|
2014-11-27 21:59:47 -04:00
|
|
|
*/
|
2015-10-25 14:03:46 -03:00
|
|
|
const AP_Scheduler::Task SchedTest::scheduler_tasks[] = {
|
2021-11-13 23:18:09 -04:00
|
|
|
SCHED_TASK(ins_update, 50, 1000, 3),
|
|
|
|
SCHED_TASK(one_hz_print, 1, 1000, 6),
|
|
|
|
SCHED_TASK(five_second_call, 0.2, 1800, 9),
|
2014-11-27 21:59:47 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-06-01 04:42:32 -03:00
|
|
|
void SchedTest::setup(void)
|
2014-11-27 21:59:47 -04:00
|
|
|
{
|
2016-10-04 05:07:21 -03:00
|
|
|
|
2017-08-28 21:45:57 -03:00
|
|
|
board_config.init();
|
2016-10-04 05:07:21 -03:00
|
|
|
|
2015-11-30 15:59:07 -04:00
|
|
|
ins.init(scheduler.get_loop_rate_hz());
|
2014-11-27 21:59:47 -04:00
|
|
|
|
|
|
|
// initialise the scheduler
|
2017-11-13 03:11:27 -04:00
|
|
|
scheduler.init(&scheduler_tasks[0], ARRAY_SIZE(scheduler_tasks), (uint32_t)-1);
|
2014-11-27 21:59:47 -04:00
|
|
|
}
|
|
|
|
|
2015-06-01 04:42:32 -03:00
|
|
|
void SchedTest::loop(void)
|
2014-11-27 21:59:47 -04:00
|
|
|
{
|
2017-11-13 03:11:27 -04:00
|
|
|
// run all tasks
|
|
|
|
scheduler.loop();
|
2014-11-27 21:59:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
update inertial sensor, reading data
|
|
|
|
*/
|
2015-06-01 04:42:32 -03:00
|
|
|
void SchedTest::ins_update(void)
|
2014-11-27 21:59:47 -04:00
|
|
|
{
|
|
|
|
ins_counter++;
|
|
|
|
ins.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
print something once a second
|
|
|
|
*/
|
2015-06-01 04:42:32 -03:00
|
|
|
void SchedTest::one_hz_print(void)
|
2014-11-27 21:59:47 -04:00
|
|
|
{
|
2015-11-19 23:14:32 -04:00
|
|
|
hal.console->printf("one_hz: t=%lu\n", (unsigned long)AP_HAL::millis());
|
2014-11-27 21:59:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
print something every 5 seconds
|
|
|
|
*/
|
2015-06-01 04:42:32 -03:00
|
|
|
void SchedTest::five_second_call(void)
|
2014-11-27 21:59:47 -04:00
|
|
|
{
|
2018-05-03 22:40:57 -03:00
|
|
|
hal.console->printf("five_seconds: t=%lu ins_counter=%u\n", (unsigned long)AP_HAL::millis(), (unsigned)ins_counter);
|
2014-11-27 21:59:47 -04:00
|
|
|
}
|
|
|
|
|
2015-06-01 04:42:32 -03:00
|
|
|
/*
|
|
|
|
compatibility with old pde style build
|
|
|
|
*/
|
|
|
|
void setup(void);
|
|
|
|
void loop(void);
|
|
|
|
|
|
|
|
void setup(void)
|
|
|
|
{
|
|
|
|
schedtest.setup();
|
|
|
|
}
|
|
|
|
void loop(void)
|
|
|
|
{
|
|
|
|
schedtest.loop();
|
|
|
|
}
|
2014-11-27 21:59:47 -04:00
|
|
|
AP_HAL_MAIN();
|