APM飞控程序解读Word格式.docx
《APM飞控程序解读Word格式.docx》由会员分享,可在线阅读,更多相关《APM飞控程序解读Word格式.docx(66页珍藏版)》请在冰豆网上搜索。
*LeadDeveloper:
RandyMackay
*BasedoncodeandideasfromtheArducopterteam:
PatHickey,JoseJulio,JaniHirvinen,AndrewTridgell,JustinBeech,AdamRivera,Jean-LouisNaudin,RobertoNavoni
*Thanksto:
ChrisAnderson,MikeSmith,JordiMunoz,DougWeibel,JamesGoppert,BenjaminPelletier,RobertLefebvre,MarcoRobustini
*
*SpecialThanksforContributors(inalphabeticalorderbyfirstname):
*AdamMRivera:
AutoCompassDeclination
*AmilcarLucas:
Cameramountlibrary
*AndrewTridgell:
Generaldevelopment,MavlinkSupport
*AngelFernandez:
Alphatesting
*DougWeibel:
Libraries
*ChristofSchmid:
*DaniSaez:
VOctoSupport
*GregoryFletcher:
Cameramountorientationmath
*Guntars:
Armingsafetysuggestion
*HappyKillmore:
MavlinkGCS
*HeinHollander:
OctoSupport
*IgorvanAirde:
ControlLawoptimization
*LeonardHall:
FlightDynamics,Throttle,LoiterandNavigationControllers
*JonathanChallinger:
InertialNavigation
*Jean-LouisNaudin:
AutoLanding
*MaxLevine:
TriSupport,Graphics
*JackDunkle:
*JamesGoppert:
MavlinkSupport
*JaniHiriven:
Testingfeedback
*JohnArneBirkeland:
PPMEncoder
*JoseJulio:
StabilizationControllaws
*MarcoRobustini:
Leadtester
*MichaelOborne:
MissionPlannerGCS
*MikeSmith:
Libraries,Codingsupport
*Oliver:
Piezosupport
*OlivierAdler:
*RobertLefebvre:
HeliSupport&
LEDs
*SandroBenigno:
Camerasupport
*AndmuchmoresoPLEASEPMmeonDIYDRONEStoaddyourcontributiontotheList
*Requiresmodified"
mrelax"
versionofArduino,whichcanbefoundhere:
*
////////////////////////////////////////////////////////////////////////////////
//Headerincludes
#include<
math.h>
stdio.h>
stdarg.h>
//Commondependencies
AP_Common.h>
AP_Progmem.h>
AP_Menu.h>
AP_Param.h>
//AP_HAL
AP_HAL.h>
AP_HAL_AVR.h>
AP_HAL_AVR_SITL.h>
AP_HAL_PX4.h>
AP_HAL_FLYMAPLE.h>
AP_HAL_Linux.h>
AP_HAL_Empty.h>
//Applicationdependencies
GCS_MAVLink.h>
//MAVLinkGCS定义
AP_GPS.h>
//ArduPilotGPSlibrary
AP_GPS_Glitch.h>
//全球定位系统干扰保护库
DataFlash.h>
//ArduPilotMegaFlashMemoryLibrary
AP_ADC.h>
//ArduPilotMegaAnalogtoDigitalConverterLibrary
AP_ADC_AnalogSource.h>
AP_Baro.h>
AP_Compass.h>
//ArduPilotMegaMagnetometerLibrary
AP_Math.h>
//ArduPilotMegaVector/MatrixmathLibrary
AP_Curve.h>
//Curveusedtolinearlisethrottlepwmtothrust
AP_InertialSensor.h>
//ArduPilotMegaInertialSensor(accel&
gyro)Library
AP_AHRS.h>
APM_PI.h>
//PIlibrary
AC_PID.h>
//PIDlibrary
RC_Channel.h>
//遥控通道库
AP_Motors.h>
//APMotorslibrary
AP_RangeFinder.h>
//Rangefinderlibrary
AP_OpticalFlow.h>
//OpticalFlowlibrary
Filter.h>
//Filterlibrary
AP_Buffer.h>
//APMFIFOBuffer
AP_Relay.h>
//APMrelay
AP_Camera.h>
//Photoorvideocamera
AP_Mount.h>
//Camera/Antennamount
AP_Airspeed.h>
//neededforAHRSbuild
AP_Vehicle.h>
AP_InertialNav.h>
//ArduPilotMegainertial导航library
AC_WPNav.h>
//ArduCopterwaypointnavigationlibrary
AP_Declination.h>
//ArduPilotMegaDeclinationHelperLibrary
AC_Fence.h>
//ArducopterFencelibrary
memcheck.h>
//memorylimitchecker
SITL.h>
//softwareintheloopsupport
AP_Scheduler.h>
//主循环调度程序
AP_RCMapper.h>
//RCinputmappinglibrary
AP_Notify.h>
//Notifylibrary
AP_BattMonitor.h>
//Batterymonitorlibrary
#ifSPRAYER==ENABLED
AC_Sprayer.h>
//cropsprayerlibrary
#endif
//AP_HALArduino兼容性层#include"
compat.h"
//配置
#include"
defines.h"
config.h"
config_channels.h"
//Localmodules
Parameters.h"
GCS.h"
//cliSerial
//cliSerialisn'
tstrictlynecessary-itisanaliasforhal.console.Itmay
//bedeprecatedinfavorofhal.consoleinlaterreleases.
staticAP_HAL:
:
BetterStream*cliSerial;
//N.B.weneedtokeepastaticdeclarationwhichisn'
tguardedbymacros
//atthetoptocooperatewiththeprototypemangler.
//AP_HALinstance
constAP_HAL:
HAL&
hal=AP_HAL_BOARD_DRIVER;
//Parameters
//
//Globalparametersareallcontainedwithinthe'
g'
class.
staticParametersg;
//mainloopscheduler
staticAP_Schedulerscheduler;
//AP_Notifyinstance
staticAP_Notifynotify;
//prototypes
staticvoidupdate_events(void);
staticvoidprint_flight_mode(AP_HAL:
BetterStream*port,uint8_tmode);
//Dataflash
#ifCONFIG_HAL_BOARD==HAL_BOARD_APM2
staticDataFlash_APM2DataFlash;
#elifCONFIG_HAL_BOARD==HAL_BOARD_APM1
staticDataFlash_APM1DataFlash;
#elifCONFIG_HAL_BOARD==HAL_BOARD_AVR_SITL
//staticDataFlash_FileDataFlash("
/tmp/APMlogs"
);
staticDataFlash_SITLDataFlash;
#elifCONFIG_HAL_BOARD==HAL_BOARD_PX4
staticDataFlash_FileDataFlash("
/fs/microsd/APM/logs"
#elifCONFIG_HAL_BOARD==HAL_BOARD_LINUX
logs"
#else
staticDataFlash_EmptyDataFlash;
//运行主循环////////////////////////////////////////////////////////////////////////////////
静态常量AP_InertialSensor:
Sample_rateins_sample_rate=AP_InertialSensor:
RATE_100HZ;
//Sensors
//Therearethreebasicoptionsrelatedtoflightsensorselection.
//-Normalflightmode.Realsensorsareused.
//-HILAttitudemode.Mostsensorsaredisabled,astheHIL
//protocolsuppliesattitudeinformationdirectly.
//-HILSensorsmode.Syntheticsensorsareconfiguredthat
//supplydatafromthesimulation.
//AllGPSaccessshouldbethroughthispointer.
staticGPS*g_gps;
staticGPS_Glitchgps_glitch(g_gps);
//flightmodesconveniencearray
staticAP_Int8*flight_modes=&
g.flight_mode1;
#ifHIL_MODE==HIL_MODE_DISABLED
#ifCONFIG_ADC==ENABLED
staticAP_ADC_ADS7844adc;
#endif
#ifCONFIG_IMU_TYPE==CONFIG_IMU_MPU6000
staticAP_InertialSensor_MPU6000ins;
#elifCONFIG_IMU_TYPE==CONFIG_IMU_OILPAN
staticAP_InertialSensor_Oilpanins(&
adc);
#elifCONFIG_IMU_TYPE==CONFIG_IMU_SITL
staticAP_InertialSensor_HILins;
#elifCONFIG_IMU_TYPE==CONFIG_IMU_PX4
staticAP_InertialSensor_PX4ins;
#elifCONFIG_IMU_TYPE==CONFIG_IMU_FLYMAPLE
AP_InertialSensor_Flymapleins;
#elifCONFIG_IMU_TYPE==CONFIG_IMU_L3G4200D
AP_InertialSensor_L3G4200Dins;
#ifCONFIG_HAL_BOARD==HAL_BOARD_AVR_SITL
//WhenbuildingforSITLweusetheHILbarometerandcompassdrivers
staticAP_Baro_HILbarometer;
staticAP_Compass_HILcompass;
staticSITLsitl;
#else
//Otherwise,instantiatearealbarometerandcompassdriver
#ifCONFIG_BARO==AP_BARO_BMP085
staticAP_Baro_BMP085barometer;
#elifCONFIG_BARO==AP_BARO_PX4
staticAP_Baro_PX4barometer;
#elifCONFIG_BARO==AP_BARO_MS5611
#ifCONFIG_MS5611_SERIAL==AP_BARO_MS5611_SPI
staticAP_Baro_MS5611barometer(&
AP_Baro_MS5611:
spi);
#elifCONFIG_MS5611_SERIAL==AP_BARO_MS5611_I2C
i2c);
#errorUnrecognizedCONFIG_MS5611_SERIALsetting.
#ifCONFIG_HAL_BOARD==HAL_BOARD_PX4
staticAP_Compass_PX4compass;
staticAP_Compass_HMC5843compass;
//realGPSselection
#ifGPS_PROTOCOL==GPS_PROTOCOL_AUTO
AP_GPS_Autog_gps_driver(&
g_gps);
#elifGPS_PROTOCOL==GPS_PROTOCOL_NMEA
AP_GPS_NMEAg_gps_driver;
#elifGPS_PROTOCOL==GPS_PROTOCOL_SIRF
AP_GPS_SIRFg_gps_driver;
#elifGPS_PROTOCOL==GPS_P