void Copter::get_scheduler_tasks(const AP_Scheduler::Task *&tasks, uint8_t &task_count, uint32_t &log_bit)
{
tasks = &scheduler_tasks[0];
task_count = ARRAY_SIZE(scheduler_tasks);
log_bit = MASK_LOG_PM;
}
这段代码是ArduPilot的Copter类中的一个函数,用于获取调度器任务的信息。具体功能如下:
tasks
是一个指向AP_Scheduler::Task
结构体数组的指针,用于存储调度器任务的信息。通过tasks = &scheduler_tasks[0];
将scheduler_tasks
数组的地址赋值给tasks
指针,从而获取任务数组的起始地址。task_count
是一个uint8_t类型的引用,用于存储任务数量。通过task_count = ARRAY_SIZE(scheduler_tasks);
将scheduler_tasks
数组的大小赋值给task_count
,从而获取任务数组的元素数量。log_bit
是一个uint32_t类型的引用,用于存储日志位掩码。通过log_bit = MASK_LOG_PM;
将MASK_LOG_PM
的值赋值给log_bit
,从而获取日志位掩码的数值。
该函数的目的是将调度器任务的信息返回给调用方,以供其他操作或日志记录使用。
// 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();
}
这段代码是ArduPilot的Copter类中的fast_loop()
函数,主要用于执行主循环中的高频率任务。下面是每个步骤的功能说明:
ins.update()
:立即更新INS(惯性导航系统)以获取当前的陀螺仪数据。attitude_control->rate_controller_run()
:运行只需要IMU数据的低级速率控制器。motors_output()
:立即将输出发送给电机库。read_AHRS()
:运行EKF(扩展卡尔曼滤波器)状态估计器。update_heli_control_dynamics()
(仅适用于直升机):更新直升机控制动力学。heli_update_autorotation()
(仅适用于直升机):更新直升机自转。read_inertia()
:惯性导航更新。check_ekf_reset()
:检查EKF是否重置目标航向或位置。update_flight_mode()
:更新飞行模式。update_home_from_EKF()
:从EKF更新Home位置。update_land_and_crash_detectors()
:更新着陆和碰撞检测器。camera_mount.update_fast()
(如果启用相机挂载):相机挂载的快速更新。Log_Sensor_Health()
:记录传感器健康状态。AP_Vehicle::fast_loop()
:执行父类AP_Vehicle的fast_loop()
函数。
该函数在主循环中以400Hz的频率运行,用于处理实时的飞行控制任务,包括姿态控制、状态估计、导航更新等。不同的飞行器类型(如直升机)可能会有一些特定的操作。