PixHawk折腾日志_APM固件_1_如何新建一种飞行模式

来源:互联网 发布:电子商务美工面试校招 编辑:程序博客网 时间:2024/06/06 21:06

一.开发环境

Ubuntu Kylin 14.04

代码查阅工具

Qt Creator 以及Vim

二.具体步骤

官网永远是一个埋藏着宝藏的地方,在官网中给出了如何添加一种新的飞行模式

http://www.ardupilot.org/dev/docs/apmcopter-adding-a-new-flight-mode.html

但是由于固件不断在更新,所以添加一种新的飞行模式与官网的介绍稍微有一些不同

(1)首先是在define.h中添加一个新的宏定义如:

    POSHOLD =      16,  // automatic position hold with manual override, with automatic throttle    BRAKE =        17,  // full-brake using inertial/GPS system, no pilot input    THROW =        18,   // throw to launch mode using inertial/GPS system, no pilot input   NEWFLIGHTMODE = 19
(2)
新建一个control_xxxx.cpp的文件中,在文件中包含Copter.h头文件

文件中主要是一个xxxx_init()和xxxx_run()函数

/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-#include "Copter.h"/* * control_newflightmode.cpp - init and run calls for new flight mode *///code of fxf // newflightmode_init - initialise flight modebool Copter::newflightmode_init(bool ignore_checks){    // do any required initialisation of the flight mode here    // this code will be called whenever the operator switches into this mode    // return true initialisation is successful, false if it fails    // if false is returned here the vehicle will remain in the previous flight mode    return true;}// newflightmode_run - runs the main controller// will be called at 100hz or more void Copter::newflightmode_run(){}
上面省略了一些内容,基本是空的

(3)在Copter.h中添加之前定义的xxxx_run和xxxx_run()的声明

    //code of fxf    bool newflightmode_init(bool ignore_checks);    void newflightmode_run();    //end    bool auto_init(bool ignore_checks);    void auto_run();
位置我的是放在了auto模式定义之前
(4)在flight_mode.cpp里面的set_mode()函数里面添加一种情况,也就是上面的xxxx_init()函数

        case BRAKE:            success = brake_init(ignore_checks);            break;        case THROW:            success = throw_init(ignore_checks);            break;       //code of fxf         case NEWFLIGHTMODE:        success=newflightmode_init(ignore_checks);        break;

(5)在flight_mode.cpp里面的update_flight_mode()函数里面添加一种情况,也就是上面的xxxx_run()函数

        case BRAKE:            brake_run();            break;        case THROW:            throw_run();            break;            //code of fxf       case NEWFLIGHTMODE:             newflightmode_run();             break;
(6)在flight_mode.cpp里面的print_flight_mode()函数里面添加一种情况,也就是自己定义的飞行模式的名称

    case BRAKE:        port->print("BRAKE");        break;    case THROW:        port->print("THROW");        break;         //code of fxf   case NEWFLIGHTMODE:        port->print("NEWFLIGHTMODE");        break;
(7)在Parameters.cpp注释项里面@Value列表里面添加新的飞行模式(一共有6个FLTMODE1~FLTMODE6,下面仅为示意)

// @Param: FLTMODE1    // @DisplayName: Flight Mode 1    // @Description: Flight mode when Channel 5 pwm is <= 1230    // @Values: 0:Stabilize,1:Acro,2:AltHold,3:Auto,4:Guided,5:Loiter,6:RTL,7:Circle,9:Land,11:Drift,13:Sport,14:Flip,15:AutoTune,16:PosHold,17:Brake,18:Throw,19:NewFlightMode    // @User: Standard    GSCALAR(flight_mode1, "FLTMODE1",               FLIGHT_MODE_1),    // @Param: FLTMODE2    // @DisplayName: Flight Mode 2    // @Description: Flight mode when Channel 5 pwm is >1230, <= 1360    // @Values: 0:Stabilize,1:Acro,2:AltHold,3:Auto,4:Guided,5:Loiter,6:RTL,7:Circle,9:Land,11:Drift,13:Sport,14:Flip,15:AutoTune,16:PosHold,17:Brake,18:Throw,19:NewFlightMode    // @User: Standard    GSCALAR(flight_mode2, "FLTMODE2",               FLIGHT_MODE_2),    // @Param: FLTMODE3    // @DisplayName: Flight Mode 3    // @Description: Flight mode when Channel 5 pwm is >1360, <= 1490    // @Values: 0:Stabilize,1:Acro,2:AltHold,3:Auto,4:Guided,5:Loiter,6:RTL,7:Circle,9:Land,11:Drift,13:Sport,14:Flip,15:AutoTune,16:PosHold,17:Brake,18:Throw,19:NewFlightMode    // @User: Standard    GSCALAR(flight_mode3, "FLTMODE3",               FLIGHT_MODE_3),
(8)编译

打开自己下代码的地方,如

cd ardupilot/ArduCopter

然后make一下

make px4-v2

等待,有:







0 0
原创粉丝点击