向Ardupilot中添加新的飞行模式(以ArduSub为例) - 新闻资讯 - 云南小程序开发|云南软件开发|云南网站建设-昆明葵宇信息科技有限公司

159-8711-8523

云南网建设/小程序开发/软件开发

知识

不管是网站,软件还是小程序,都要直接或间接能为您产生价值,我们在追求其视觉表现的同时,更侧重于功能的便捷,营销的便利,运营的高效,让网站成为营销工具,让软件能切实提升企业内部管理水平和效率。优秀的程序为后期升级提供便捷的支持!

您当前位置>首页 » 新闻资讯 » 技术分享 >

向Ardupilot中添加新的飞行模式(以ArduSub为例)

发表时间:2020-10-19

发布人:葵宇科技

浏览次数:84

本次以ArduSub为例介绍若何向APM固件中添加新的飞翔模式以便利后续开辟,其他车辆类型操作类似,本篇也可用作参考。

参考材料:

Adding a New Flight Mode

Creating newflight mode in Ardusub


起首在ardupilot/ArduSub/文件路径下,新建一个用于添加新的飞翔模式的文件control_newMode.cpp。然后,向内部添加代码如下:

#include "Sub.h"

bool Sub::newmode_init()
{
	return true;
}

void Sub::newmode_init()
{

}

保存退出之后,进入ardupilot/libraries/AP_JSButton/AP_JSBottton.h,找到k_mode_xxx情势的模式定义如下:

        k_mode_manual           = 5,            ///< enter enter manual mode
        k_mode_stabilize        = 6,            ///< enter stabilize mode
        k_mode_depth_hold       = 7,            ///< enter depth hold mode
        k_mode_poshold          = 8,            ///< enter poshold mode
        k_mode_auto             = 9,            ///< enter auto mode
        k_mode_circle           = 10,           ///< enter circle mode
        k_mode_guided           = 11,           ///< enter guided mode
        k_mode_acro             = 12,           ///< enter acro mode
        k_mode_newmode			= 13,			///...

在最后添加你的新模式,我这里选择的数字为13(只要不跨越后面参数的值21即可)。然后添加你对应的备注。

回到ardupilot/ArduSub/defines.h文件中,找到control_mode_t列举类型定义,在最后面添加你的新模式,并添加备注描述

// Auto Pilot Modes enumeration
enum control_mode_t {
    STABILIZE =     0,  // manual angle with manual depth/throttle
    ACRO =          1,  // manual body-frame angular rate with manual depth/throttle
    ALT_HOLD =      2,  // manual angle with automatic depth/throttle
    AUTO =          3,  // fully automatic waypoint control using mission commands
    GUIDED =        4,  // fully automatic fly to coordinate or fly at velocity/direction using GCS immediate commands
    CIRCLE =        7,  // automatic circular flight with automatic throttle
    SURFACE =       9,  // automatically return to surface, pilot maintains horizontal control
    POSHOLD =      16,  // automatic position hold with manual override, with automatic throttle
    MANUAL =       19,  // Pass-through input with no stabilization
    MOTOR_DETECT = 20,  // Automatically detect motors orientation
	NEWMODE =	   21	// ...
};

再进入ardupilot/ArduSub/Sub.h,向内部添加代码段如下(理论上是可以在随便率性地位,然则最好添加在其余飞翔模式的旁边)

bool newmode_init(void);
void newmode_run();

然后在ardupilot/ArduSub/flight_mode.cpp中,对set_mode()和update_flight_mode()办法进行修改,具体就是在switch函数下面添加对应的case情况函数。

// 在set_mode()办法中
    case NEWMODE:
    	success = newmode_init();
    	break;
...
///在update_flight_mode()办法中
    case NEWMODE:
    	success = newmode_run();
    	break;

最后,在ardupilot/ArduSub/joystick.cpp中,找到

void Sub::handle_jsbutton_press(uint8_t button, bool shift, bool held)

在个中的switch-case语句中的default前添加

    case JSButton::button_function_t::k_mode_newmode:
    	set_mode(NEWMODE, MODE_REASON_TX_COMMAND);

然后保存退出即可。


编译

cd ardupilot/
rm -rf build/
./waf configure --board Pixhawk1
./waf sub

编译成功!

在这里插入图片描述
后续工作是若何使QGC可以或许辨认出新的飞翔模式,今朝尚在研究中。也可推敲应用mavros或者pymavlink进行后续的开辟生发火业。今朝先研究到这~

相关案例查看更多