mirror of https://github.com/ArduPilot/ardupilot
Copter: use new Task infrastructure for the fast loop
add helper for running rate controller add fast_loop documentation.
This commit is contained in:
parent
785615de2f
commit
01766eee01
|
@ -83,10 +83,10 @@
|
|||
const AP_HAL::HAL& hal = AP_HAL::get_HAL();
|
||||
|
||||
#define SCHED_TASK(func, _interval_ticks, _max_time_micros, _prio) SCHED_TASK_CLASS(Copter, &copter, func, _interval_ticks, _max_time_micros, _prio)
|
||||
#define FAST_TASK(func) FAST_TASK_CLASS(Copter, &copter, func)
|
||||
|
||||
/*
|
||||
scheduler table - all regular tasks apart from the fast_loop()
|
||||
should be listed here.
|
||||
scheduler table - all tasks should be listed here.
|
||||
|
||||
All entries in this table must be ordered by priority.
|
||||
|
||||
|
@ -110,6 +110,38 @@ SCHED_TASK_CLASS arguments:
|
|||
|
||||
*/
|
||||
const AP_Scheduler::Task Copter::scheduler_tasks[] = {
|
||||
// update INS immediately to get current gyro data populated
|
||||
FAST_TASK_CLASS(AP_InertialSensor, &copter.ins, update),
|
||||
// run low level rate controllers that only require IMU data
|
||||
FAST_TASK(run_rate_controller),
|
||||
// send outputs to the motors library immediately
|
||||
FAST_TASK(motors_output),
|
||||
// run EKF state estimator (expensive)
|
||||
FAST_TASK(read_AHRS),
|
||||
#if FRAME_CONFIG == HELI_FRAME
|
||||
FAST_TASK(update_heli_control_dynamics),
|
||||
#if MODE_AUTOROTATE_ENABLED == ENABLED
|
||||
FAST_TASK(heli_update_autorotation),
|
||||
#endif
|
||||
#endif //HELI_FRAME
|
||||
// Inertial Nav
|
||||
FAST_TASK(read_inertia),
|
||||
// check if ekf has reset target heading or position
|
||||
FAST_TASK(check_ekf_reset),
|
||||
// run the attitude controllers
|
||||
FAST_TASK(update_flight_mode),
|
||||
// update home from EKF if necessary
|
||||
FAST_TASK(update_home_from_EKF),
|
||||
// check if we've landed or crashed
|
||||
FAST_TASK(update_land_and_crash_detectors),
|
||||
#if HAL_MOUNT_ENABLED
|
||||
// camera mount's fast update
|
||||
FAST_TASK_CLASS(AP_Mount, &copter.camera_mount, update_fast),
|
||||
#endif
|
||||
// log sensor health
|
||||
FAST_TASK(Log_Sensor_Health),
|
||||
FAST_TASK(Log_Video_Stabilisation),
|
||||
|
||||
SCHED_TASK(rc_loop, 100, 130, 3),
|
||||
SCHED_TASK(throttle_loop, 50, 75, 6),
|
||||
SCHED_TASK_CLASS(AP_GPS, &copter.gps, update, 50, 200, 9),
|
||||
|
@ -237,62 +269,6 @@ void Copter::get_scheduler_tasks(const AP_Scheduler::Task *&tasks,
|
|||
|
||||
constexpr int8_t Copter::_failsafe_priorities[7];
|
||||
|
||||
// Main loop - 400hz
|
||||
void Copter::fast_loop()
|
||||
{
|
||||
// update INS immediately to get current gyro data populated
|
||||
ins.update();
|
||||
|
||||
// run low level rate controllers that only require IMU data
|
||||
attitude_control->rate_controller_run();
|
||||
|
||||
// send outputs to the motors library immediately
|
||||
motors_output();
|
||||
|
||||
// run EKF state estimator (expensive)
|
||||
// --------------------
|
||||
read_AHRS();
|
||||
|
||||
#if FRAME_CONFIG == HELI_FRAME
|
||||
update_heli_control_dynamics();
|
||||
#if MODE_AUTOROTATE_ENABLED == ENABLED
|
||||
heli_update_autorotation();
|
||||
#endif
|
||||
#endif //HELI_FRAME
|
||||
|
||||
// Inertial Nav
|
||||
// --------------------
|
||||
read_inertia();
|
||||
|
||||
// check if ekf has reset target heading or position
|
||||
check_ekf_reset();
|
||||
|
||||
// run the attitude controllers
|
||||
update_flight_mode();
|
||||
|
||||
// update home from EKF if necessary
|
||||
update_home_from_EKF();
|
||||
|
||||
// check if we've landed or crashed
|
||||
update_land_and_crash_detectors();
|
||||
|
||||
#if HAL_MOUNT_ENABLED
|
||||
// camera mount's fast update
|
||||
camera_mount.update_fast();
|
||||
#endif
|
||||
|
||||
// log sensor health
|
||||
if (should_log(MASK_LOG_ANY)) {
|
||||
Log_Sensor_Health();
|
||||
}
|
||||
|
||||
AP_Vehicle::fast_loop();
|
||||
|
||||
if (should_log(MASK_LOG_VIDEO_STABILISATION)) {
|
||||
ahrs.write_video_stabilisation();
|
||||
}
|
||||
}
|
||||
|
||||
#if AP_SCRIPTING_ENABLED
|
||||
// start takeoff to given altitude (for use by scripting)
|
||||
bool Copter::start_takeoff(float alt)
|
||||
|
|
|
@ -640,7 +640,6 @@ private:
|
|||
void get_scheduler_tasks(const AP_Scheduler::Task *&tasks,
|
||||
uint8_t &task_count,
|
||||
uint32_t &log_bit) override;
|
||||
void fast_loop() override;
|
||||
#if AP_SCRIPTING_ENABLED
|
||||
bool start_takeoff(float alt) override;
|
||||
bool set_target_location(const Location& target_loc) override;
|
||||
|
@ -680,6 +679,7 @@ private:
|
|||
void set_accel_throttle_I_from_pilot_throttle();
|
||||
void rotate_body_frame_to_NE(float &x, float &y);
|
||||
uint16_t get_pilot_speed_dn() const;
|
||||
void run_rate_controller() { attitude_control->rate_controller_run(); }
|
||||
|
||||
// avoidance.cpp
|
||||
void low_alt_avoidance();
|
||||
|
@ -802,6 +802,7 @@ private:
|
|||
void Log_Write_Data(LogDataID id, float value);
|
||||
void Log_Write_Parameter_Tuning(uint8_t param, float tuning_val, float tune_min, float tune_max);
|
||||
void Log_Sensor_Health();
|
||||
void Log_Video_Stabilisation();
|
||||
#if FRAME_CONFIG == HELI_FRAME
|
||||
void Log_Write_Heli(void);
|
||||
#endif
|
||||
|
|
|
@ -223,6 +223,10 @@ void Copter::Log_Write_Parameter_Tuning(uint8_t param, float tuning_val, float t
|
|||
// logs when baro or compass becomes unhealthy
|
||||
void Copter::Log_Sensor_Health()
|
||||
{
|
||||
if (!should_log(MASK_LOG_ANY)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// check baro
|
||||
if (sensor_health.baro != barometer.healthy()) {
|
||||
sensor_health.baro = barometer.healthy();
|
||||
|
@ -237,6 +241,14 @@ void Copter::Log_Sensor_Health()
|
|||
}
|
||||
}
|
||||
|
||||
void Copter::Log_Video_Stabilisation()
|
||||
{
|
||||
if (!should_log(MASK_LOG_VIDEO_STABILISATION)) {
|
||||
return;
|
||||
}
|
||||
ahrs.write_video_stabilisation();
|
||||
}
|
||||
|
||||
struct PACKED log_SysIdD {
|
||||
LOG_PACKET_HEADER;
|
||||
uint64_t time_us;
|
||||
|
|
Loading…
Reference in New Issue