APM的解锁(ARM)流程

  • 解锁检测函数

              解锁检测函数是arm_motors_check(),作为scheduler每秒运行10此,定义在motors.cpp中,定义如下

#define ARM_DELAY               20  // called at 10hz so 2 seconds
#define DISARM_DELAY            20  // called at 10hz so 2 seconds
#define AUTO_TRIM_DELAY         100 // called at 10hz so 10 seconds
#define LOST_VEHICLE_DELAY      10  // called at 10hz so 1 second

static uint8_t auto_disarming_counter;

// arm_motors_check - checks for pilot input to arm or disarm the copter
// called at 10hz
void Copter::arm_motors_check()
{
    static int16_t arming_counter;

    // ensure throttle is down
    if (channel_throttle->control_in > 0) {
        arming_counter = 0;
        return;
    }

    int16_t tmp = channel_yaw->control_in;

    // full right
    if (tmp > 4000) {

        // increase the arming counter to a maximum of 1 beyond the auto trim counter
        if( arming_counter <= AUTO_TRIM_DELAY ) {
            arming_counter++;
        }

        // arm the motors and configure for flight
        if (arming_counter == ARM_DELAY && !motors.armed()) {
            // reset arming counter if arming fail
            if (!init_arm_motors(false)) {
                arming_counter = 0;
            }
        }

        // arm the motors and configure for flight
        if (arming_counter == AUTO_TRIM_DELAY && motors.armed() && control_mode == STABILIZE) {
            auto_trim_counter = 250;
            // ensure auto-disarm doesn't trigger immediately
            auto_disarming_counter = 0;
        }

    // full left
    }else if (tmp < -4000) {
        if (!mode_has_manual_throttle(control_mode) && !ap.land_complete) {
            arming_counter = 0;
            return;
        }

        // increase the counter to a maximum of 1 beyond the disarm delay
        if( arming_counter <= DISARM_DELAY ) {
            arming_counter++;
        }

        // disarm the motors
        if (arming_counter == DISARM_DELAY && motors.armed()) {
            init_disarm_motors();
        }

    // Yaw is centered so reset arming counter
    }else{
        arming_counter = 0;
    }
}

函数释义:

定义静态变量arming_counter,做计数器用;

如果油门输入大于0,则不进行解锁操作,arming_counter置0,直接返回;

将航向角控制通道的值赋给临时变量tmp,这个值是经过pwm转成的角度值,在-4500到4500之间;

如果tmp大于4000,即航向杆打到右侧:

如果计数器arming_counter小于等于AUTO_TRIM_DELAY(100),

        则arming_counter++;

判断计数器arming_counter等于ARM_DELAY(20),同时motors.armed()的值为0,即disarm状态,

        则调用init_arm_motors,进行arm操作,

        如果arm失败,即init_arm_motors返回0,

                 则将arming_counter置为0;

如果计数器arming_counter等于AUTO_TRIM_DELAY(100),同时motors.armed()的值为1,及ARMED状态,同时当前控制模式为姿态模式

        则 auto_trim_counter = 250;

             auto_disarming_counter = 0;

如果tmp小于-4000,即航向杆打到左侧:

如果mode_has_manual_throttle返回0,同时ap.land_complete也为0,(即当前飞控模式不是手动油门,即不是ACRO和STABILIZE模式,同时没有检测到land)

        则arming_counter=0,并立即返回;

如果arming_counter小于等于DISARM_DELAY(20),

        则arming_counter++;

如果arming_counter等于DISARM_DELAY(20)同时motors.armed()返回1,即是ARMED状态:

        则执行init_disarm_motors()函数,进行解锁操作

如果tmp既不大于4000,也不小于-4000,即在-4000到4000之间:

则arming_counter=0;

你可能感兴趣的:(APM的解锁(ARM)流程)