Ardupilot 飞控代码解锁流程分析

摘要

本文档只有记录分析ardupilot飞控代码解锁的过程,如果有分析不到的地方,欢迎批评指导,谢谢,联系方式:微信lxw15982962929


**重点标志变量:
_flags.armed=0表示没有解锁,
_flags.armed=1表示解锁
arming_counter解锁上锁计数标志位
channel_yaw->get_control_in(); //获得偏航值,传递给tmp变量,这个值通过pwm转换的角度范围是-4500到+4500

解锁上锁思路整理:首先判断油门控制量的值是否大于0,如果大于0,不进行任何计数操作,直接返回,然后进行偏航通道的判断,以美国手为例,偏航在最右边进行解锁操作,偏航在最左边进行解锁操作,偏航在中间不进行操作。细节看visio流程图。

目录

1.代码分析

(1)首先上传需要看的代码


void Copter::arm_motors_check()
{
    static int16_t arming_counter;
    // 确保油门值比较低--------------------------------------ensure throttle is down
    if (channel_throttle->get_control_in() > 0) //获得三通道油门值,如果大于0,直接返回,不进行解锁操作
    {
        arming_counter = 0;
        return;
    }
    int16_t tmp = channel_yaw->get_control_in(); //获得偏航值,传递给tmp变量,这个值通过pwm转换的角度范围是-4500到+4500
    // 航向打大右边
    if (tmp > 4000)
    {
        // 增加arm解锁计数----------------------------------increase the arming counter to a maximum of 1 beyond the auto trim counter
        if( arming_counter <= AUTO_TRIM_DELAY )  //小于10s
        {
            arming_counter++;
        }
        //开始做准备解锁的工作,此时准备解锁电机,开始配置飞行------arm the motors and configure for flight
        if (arming_counter == ARM_DELAY && !motors->armed())  //计数到2s,并且没有解了,这个时候arming_counter=0开始做清零
        {
            //解除保险解除计数器------------------------------reset arming counter if arming fail
            if (!init_arm_motors(false)) //返回0,解锁失败,返回1解锁成功
            {
                arming_counter = 0;
            }
        }
        //解锁电机,开始配置飞行-------------------------------arm the motors and configure for flight
        if (arming_counter == AUTO_TRIM_DELAY && motors->armed() && control_mode == STABILIZE) //等于10s,解锁了,控制模式是自稳模式
        {
            auto_trim_counter = 250;
            //确保自动解锁不触发------------------------------ensure auto-disarm doesn't trigger immediately
            auto_disarm_begin = millis();
        }
    // 全部打到左边
    }else if (tmp < -4000)
    {
        if (!mode_has_manual_throttle(control_mode) && !ap.land_complete) //如果不是自稳模式,也不是速率模式,也没有着落
        {
            arming_counter = 0; //立即发挥
            return;
        }
        //增加计数器到解除武器延迟的最大值1------- increase the counter to a maximum of 1 beyond the disarm delay
        if( arming_counter <= DISARM_DELAY ) //上锁计数2s
        {
            arming_counter++;
        }
        //上锁电机----------------------------disarm the motors
        if (arming_counter == DISARM_DELAY && motors->armed()) //本来是上锁的,并且这个时候已经计数到2s,
        {
            init_disarm_motors();
        }

    // 如果偏航是在中间的话,我们不进行计数处理
    }else
    {
        arming_counter = 0;
    }
}

2.代码截图

ardupilot电机解锁代码分析
ardupilot电机解锁代码分析

3.visio流程图分析

流程图分析解锁过程

猜你喜欢

转载自blog.csdn.net/lixiaoweimashixiao/article/details/80648569