//www.gnu.org/licenses/>.
*/
/*
*ArduCopterVersion3.0
*Creator:
JasonShort
*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:
Alphatesting
*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:
Alphatesting
*JamesGoppert:
MavlinkSupport
*JaniHiriven:
Testingfeedback
*JohnArneBirkeland:
PPMEncoder
*JoseJulio:
StabilizationControllaws
*MarcoRobustini:
Leadtester
*MichaelOborne:
MissionPlannerGCS
*MikeSmith:
Libraries,Codingsupport
*Oliver:
Piezosupport
*OlivierAdler:
PPMEncoder
*RobertLefebvre:
HeliSupport&LEDs
*SandroBenigno:
Camerasupport
*
*AndmuchmoresoPLEASEPMmeonDIYDRONEStoaddyourcontributiontotheList
*
*Requiresmodified"mrelax"versionofArduino,whichcanbefoundhere:
*
*
*/
////////////////////////////////////////////////////////////////////////////////
//Headerincludes
////////////////////////////////////////////////////////////////////////////////
#include
#include
#include
//Commondependencies
#include
#include
#include
#include
//AP_HAL
#include
#include
#include
#include
#include
#include
#include
//Applicationdependencies
#include//MAVLinkGCSdefinitions
#include//ArduPilotGPSlibrary
#include//全球定位系统干扰保护库
#include//ArduPilotMegaFlashMemoryLibrary
#include//ArduPilotMegaAnalogtoDigitalConverterLibrary
#include
#include
#include//ArduPilotMegaMagnetometerLibrary
#include//ArduPilotMegaVector/MatrixmathLibrary
#include//Curveusedtolinearlisethrottlepwmtothrust
#include//ArduPilotMegaInertialSensor(accel&gyro)Library
#include
#include//PIlibrary
#include//PIDlibrary
#include//遥控通道库
#include//APMotorslibrary
#include//Rangefinderlibrary
#include//OpticalFlowlibrary
#include//Filterlibrary
#include//APMFIFOBuffer
#include//APMrelay
#include//Photoorvideocamera
#include//Camera/Antennamount
#include//neededforAHRSbuild
#include//neededforAHRSbuild
#include//ArduPilotMegainertial导航library
#include//ArduCopterwaypointnavigationlibrary
#include//ArduPilotMegaDeclinationHelperLibrary
#include//ArducopterFencelibrary
#include//memorylimitchecker
#include//softwareintheloopsupport
#include//主循环调度程序
#include//RCinputmappinglibrary
#include//Notifylibrary
#include//Batterymonitorlibrary
#ifSPRAYER==ENABLED
#include//cropsprayerlibrary
#endif
//AP_HALtoArduinocompatibilitylayer
#include"compat.h"
//Configuration
#include"defines.h"
#include"config.h"
#include"config_channels.h"
//Localmodules
#include"Parameters.h"
#include"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
staticDataFlash_FileDataFlash("logs");
#else
staticDataFlash_EmptyDataFlash;
#endif
////////////////////////////////////////////////////////////////////////////////
//theratewerunthemainloopat
////////////////////////////////////////////////////////////////////////////////
staticconstAP_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;
#endif
#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
staticAP_Baro_MS5611barometer(&AP_Baro_MS5611:
:
i2c);
#else
#errorUnrecognizedCONFIG_MS5611_SERIALsetting.
#endif
#endif
#ifCONFIG_HAL_BOARD==HAL_BOARD_PX4
staticAP_Compass_PX4compass;
#else
staticAP_Compass_HMC5843compass;
#endif
#endif
//realGPSselection
#ifGPS_PROTOCOL==GPS_PROTOCOL_AUTO
AP_GPS_Autog_gps_driver(&g_gps);
#elifGPS_PROTOCOL==GPS_PROTOCOL_NMEA
AP_GPS_NMEAg_gps_driver;
#elifGPS_PRO