本次以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進行后續的開發作業,目前先研究到這~
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/180241.html
標籤:其他
上一篇:百度文字轉語音網址直鏈
