AUTO TUNE.docx
- 文档编号:26565633
- 上传时间:2023-06-20
- 格式:DOCX
- 页数:34
- 大小:22.60KB
AUTO TUNE.docx
《AUTO TUNE.docx》由会员分享,可在线阅读,更多相关《AUTO TUNE.docx(34页珍藏版)》请在冰豆网上搜索。
AUTOTUNE
///-*-tab-width:
4;Mode:
C++;c-basic-offset:
4;indent-tabs-mode:
nil-*-
#ifAUTOTUNE_ENABLED==ENABLED
/*
*control_autotune.pde-initandruncallsforautotuneflightmode
*
*Instructions:
*1)SetuponeflightmodeswitchpositiontobeAltHold.
*2)SettheCh7OptorCh8OpttoAutoTunetoallowyoutoturntheautotuningon/offwiththech7orch8switch.
*3)Ensurethech7orch8switchisintheLOWposition.
*4)Waitforacalmdayandgotoalargeopenarea.
*5)TakeoffandputthevehicleintoAltHoldmodeatacomfortablealtitude.
*6)Setthech7/ch8switchtotheHIGHpositiontoengageautotuning:
*a)Youwillseeittwitchabout20degreesleftandrightforafewminutes,thenitwillrepeatforwardandback.
*b)Usetherollandpitchstickatanytimetorepositionthecopterifitdriftsaway(itwillusetheoriginalPIDgainsduringrepositioningandbetweentests).
*Whenyoureleasethesticksitwillcontinueautotuningwhereitleftoff.
*c)Movethech7/ch8switchintotheLOWpositionatanytimetoabandontheautotuningandreturntotheoriginPIDs.
*d)Makesurethatyoudonothaveanytrimsetonyourtransmitterortheautotunemaynotgetthesignalthatthesticksarecentered.
*7)WhenthetunecompletesthevehiclewillchangebacktotheoriginalPIDgains.
*8)Putthech7/ch8switchintotheLOWpositionthenbacktotheHIGHpositiontotestthetunedPIDgains.
*9)Putthech7/ch8switchintotheLOWpositiontoflyusingtheoriginalPIDgains.
*10)IfyouarehappywiththeautotunedPIDgains,leavethech7/ch8switchintheHIGHposition,landanddisarmtosavethePIDspermanently.
*IfyouDONOTlikethenewPIDS,switchch7/ch8LOWtoreturntotheoriginalPIDs.Thegainswillnotbesavedwhenyoudisarm
*
*Whatit'sdoingduringeach"twitch":
*a)invokes90deg/secraterequest
*b)recordsmaximum"forward"rollrateandbouncebackrate
*c)whencopterreaches20degreesor1secondhaspassed,itcommandslevel
*d)triestokeepmaxrotationratebetween80%~100%ofrequestedrate(90deg/sec)byadjustingrateP
*e)increasesrateDuntilthebouncebackbecomesgreaterthan10%ofrequestedrate(90deg/sec)
*f)decreasesrateDuntilthebouncebackbecomeslessthan10%ofrequestedrate(90deg/sec)
*g)increasesratePuntilthemaxrotateratebecomesgreaterthantherequesterate(90deg/sec)
*h)invokesa20deganglerequestonrollorpitch
*i)increasesstabPuntilthemaximumanglebecomesgreaterthan110%oftherequestedangle(20deg)
*j)decreasesstabPby25%
*
*Notes:
AUTOTUNEshouldnotbeset-upasaflightmode,itshouldbeinvokedonlyfromthech7/ch8switch.
*
*/
#defineAUTOTUNE_PILOT_OVERRIDE_TIMEOUT_MS500//restarttuningifpilothasleftsticksinmiddlefor2seconds
#defineAUTOTUNE_TESTING_STEP_TIMEOUT_MS500//timeoutfortuningmode'stestingstep
#defineAUTOTUNE_TARGET_ANGLE_CD2000//targetangleduringTESTING_RATEstepthatwillcauseustomovetonextstep
#defineAUTOTUNE_TARGET_RATE_CDS9000//targetroll/pitchrateduringAUTOTUNE_STEP_TWITCHINGstep
#defineAUTOTUNE_LEVEL_ANGLE_CD300//anglewhichqualifiesaslevel
#defineAUTOTUNE_REQUIRED_LEVEL_TIME_MS250//timewerequirethecoptertobelevel
#defineAUTOTUNE_AGGRESSIVENESS0.1f//tuningfor10%overshoot
#defineAUTOTUNE_RD_STEP0.0005f//minimumincrementwhenincreasing/decreasingRateDterm
#defineAUTOTUNE_RP_STEP0.005f//minimumincrementwhenincreasing/decreasingRatePterm
#defineAUTOTUNE_SP_STEP0.5f//minimumincrementwhenincreasing/decreasingStabPterm
#defineAUTOTUNE_SP_BACKOFF0.75f//StabPgainsarereducedto75%oftheirmaximumvaluediscoveredduringtuning
#defineAUTOTUNE_PI_RATIO_FOR_TESTING0.1f//Iisset10xsmallerthanPduringtesting
#defineAUTOTUNE_RP_RATIO_FINAL1.0f//Iisset1xPaftertesting
#defineAUTOTUNE_RD_MIN0.002f//minimumRateDvalue
#defineAUTOTUNE_RD_MAX0.015f//maximumRateDvalue
#defineAUTOTUNE_RP_MIN0.01f//minimumRatePvalue
#defineAUTOTUNE_RP_MAX0.25f//maximumRatePvalue
#defineAUTOTUNE_SP_MAX15.0f//maximumStabPvalue
#defineAUTOTUNE_SUCCESS_COUNT4//howmanysuccessfuliterationsweneedtofreezeatcurrentgains
//AutoTunemessageidsforgroundstation
#defineAUTOTUNE_MESSAGE_STARTED0
#defineAUTOTUNE_MESSAGE_STOPPED1
#defineAUTOTUNE_MESSAGE_SUCCESS2
#defineAUTOTUNE_MESSAGE_FAILED3
//autotunemodes(highlevelstates)
enumAutoTuneTuneMode{
AUTOTUNE_MODE_UNINITIALISED=0,//autotunehasneverbeenrun
AUTOTUNE_MODE_TUNING=1,//autotuneistestinggains
AUTOTUNE_MODE_SUCCESS=2,//tuninghascompleted,userisflighttestingthenewgains
AUTOTUNE_MODE_FAILED=3,//tuninghasfailed,userisflyingonoriginalgains
};
//stepsperformedwhileinthetuningmode
enumAutoTuneStepType{
AUTOTUNE_STEP_WAITING_FOR_LEVEL=0,//autotuneiswaitingforvehicletoreturntolevelbeforebeginningthenexttwitch
AUTOTUNE_STEP_TWITCHING=1,//autotunehasbegunatwitchandiswatchingtheresultingvehiclemovement
AUTOTUNE_STEP_UPDATE_GAINS=2//autotunehascompletedatwitchandisupdatingthegainsbasedontheresults
};
//thingsthatcanbetuned
enumAutoTuneAxisType{
AUTOTUNE_AXIS_ROLL=0,//rollaxisisbeingtuned(eitherangleorrate)
AUTOTUNE_AXIS_PITCH=1//pitchaxisisbeingtuned(eitherangleorrate)
};
//ministepsperformedwhileinTuningmode,Testingstep
enumAutoTuneTuneType{
AUTOTUNE_TYPE_RD_UP=0,//rateDisbeingtunedup
AUTOTUNE_TYPE_RD_DOWN=1,//rateDisbeingtuneddown
AUTOTUNE_TYPE_RP_UP=2,//ratePisbeingtunedup
AUTOTUNE_TYPE_SP_UP=3//anglePisbeingtunedup
};
//autotune_state_struct-holdstateflags
structautotune_state_struct{
AutoTuneTuneModemode:
2;//seeAutoTuneTuneModeforwhatmodesareallowed
uint8_tpilot_override:
1;//1=pilotisoverridingcontrolssowesuspendtuningtemporarily
AutoTuneAxisTypeaxis:
1;//seeAutoTuneAxisTypeforwhichthingscanbetuned
uint8_tpositive_direction:
1;//0=tuninginnegativedirection(i.e.leftforroll),1=positivedirection(i.e.rightforroll)
AutoTuneStepTypestep:
2;//seeAutoTuneStepTypeforwhatstepsareperformed
AutoTuneTuneTypetune_type:
2;//seeAutoTuneTuneType
}autotune_state;
//variables
staticuint32_tautotune_override_time;//thelasttimethepilotoverrodethecontrols
staticfloatautotune_test_min;//theminimumangularrateachievedduringTESTING_RATEstep
staticfloatautotune_test_max;//themaximumangularrateachievedduringTESTING_RATEstep
staticuint32_tautotune_step_start_time;//starttimeofcurrenttuningstep(usedfortimeoutchecks)
staticint8_tautotune_counter;//counterfortuninggains
staticfloatorig_roll_rp=0,orig_roll_ri,orig_roll_rd,orig_roll_sp;//backupofcurrentlybeingtunedparametervalues
staticfloatorig_pitch_rp=0,orig_pitch_ri,orig_pitch_rd,orig_pitch_sp;//backupofcurrentlybeingtunedparametervalues
staticfloattune_roll_rp,tune_roll_rd,tune_roll_sp;//currentlybeingtunedparametervalues
staticfloattune_pitch_rp,tune_pitch_rd,tune_pitch_sp;//currentlybeingtunedparametervalues
//autotune_start-shouldbecalledwhenthech7/ch8switchisswitchedON
staticvoidautotune_start()
{
switch(autotune_state.mode){
caseAUTOTUNE_MODE_FAILED:
//autotunehasbeenrunbutfailedsoresetstatetouninitialised
autotune_state.mode=AUTOTUNE_MODE_UNINITIALISED;
//nobreaktoallowfallthroughtorestartthetuning
caseAUTOTUNE_MODE_UNINITIALISED:
//autotunehasneverbeenrun
//switchintotheAUTOTUNEflightmode
if(set_mode(AUTOTUNE)){
//sostorecurrentgainsasoriginalgains
autotune_backup_gains_and_initialise();
//advancemodetotuning
autotune_state.mode=AUTOTUNE_MODE_TUNING;
//sendmessagetogroundstationthatwe'vestartedtuning
autotune_update_gcs(AUTOTUNE_MESSAGE_STARTED);
}
break;
caseAUTOTUNE_MODE_TUNING:
//wearerestartingtuningaftertheusermusthaveswitchedch7/ch8offsowerestarttuningwhereweleftoff
//set_modetoAUTOTUNE
if(set_mode(AUTOTUNE)){
//resetgainstotuning-startgains(i.e.lowIterm)
autotune_load_intra_test_gains();
//writedataflashlogevenandsendmessagetogroundstation
Log_Write_Event(DATA_AUTOTUNE_RESTART);
autotune_update_gcs(AUTOTUNE_MESSAGE_STARTED);
}
break;
caseAUTOTUNE_MODE_SUCCESS:
//wehavecompletedatuneandthepilotwishestotestthenewgainsinthecurrentflightmode
//sosimplyapplytuninggains(i.e.donotchangeflightmode)
autotune_load_tuned_gains();
Log_Write_Event(DATA_AUTOTUNE_PILOT_TESTING);
break;
}
}
//autotune_stop-shouldbecalledwhenthech7/ch8switchisswitchedOFF
staticvoidautotune_stop()
{
//setgainstotheiroriginalvalues
autotune_load_orig_gains();
//re-enableangle-to-raterequestlimits
attitude_control.limit_angle_to_rate_request(true);
//logoffeventandsendmessagetogroundstatoin
autotune_update_gcs(AUTOTUNE_MESSAGE_STOPPED);
Log_Write_Event(DATA_AUTOTUNE_OFF);
//Note:
weleavetheautotune_state.modeasitwassothatweknowhowtheautotuneended
//weexpectthecallerwillchangetheflightmodebacktotheflightmodeindicatedbytheflightmodeswitch
}
//autotune_init-initialiseautotuneflightmode
staticboolautotune_init(boolignore_checks)
{
//onlyallowflipfromStabilizeorAltHoldflightmodes
if(control_mode!
=STABILIZE&&control_mode!
=ALT_HOLD){
returnfalse;
}
//ensurethrottleisabovezero
if(g.rc_3.control_in<=0){
returnfalse;
}
//ensureweareflying
if(!
motors.armed()||!
ap.au
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- AUTO TUNE