Prof Greg Egan / Mbed 2 deprecated UAVXArm-GKE

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers menu.c Source File

menu.c

00001 // ===============================================================================================
00002 // =                              UAVXArm Quadrocopter Controller                                =
00003 // =                           Copyright (c) 2008 by Prof. Greg Egan                             =
00004 // =                 Original V3.15 Copyright (c) 2007 Ing. Wolfgang Mahringer                   =
00005 // =                           http://code.google.com/p/uavp-mods/                               =
00006 // ===============================================================================================
00007 
00008 //    This is part of UAVXArm.
00009 
00010 //    UAVXArm is free software: you can redistribute it and/or modify it under the terms of the GNU
00011 //    General Public License as published by the Free Software Foundation, either version 3 of the
00012 //    License, or (at your option) any later version.
00013 
00014 //    UAVXArm is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without
00015 //    even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016 //    See the GNU General Public License for more details.
00017 
00018 //    You should have received a copy of the GNU General Public License along with this program.
00019 //    If not, see http://www.gnu.org/licenses/
00020 
00021 #include "UAVXArm.h"
00022 
00023 void ShowPrompt(void);
00024 void ShowRxSetup(void);
00025 void ShowSetup(boolean);
00026 uint8 MakeUpper(uint8);
00027 void ProcessCommand(void);
00028 
00029 const uint8 SerHello[] = "UAVXArm "
00030                          " Copyright 2008 G.K. Egan & 2007 W. Mahringer\r\n"
00031                          "This is FREE SOFTWARE and comes with ABSOLUTELY NO WARRANTY "
00032                          "see http://www.gnu.org/licenses/!\r\n";
00033 const uint8 SerHelp[] = "\r\nCommands:\r\n"
00034                         "A..Attitude test\r\n"
00035                         "C..Compass test\r\n"
00036                         "D..Load default parameter set\r\n"
00037                         "G..GPS test\r\n"
00038                         "H..Barometer/Rangefinder test\r\n"
00039                         "I..I2C bus scan\r\n"
00040                         "K..Calibrate compass scan\r\n"
00041 //    "M..Modify parameters\r\n"
00042                         "P..Rx test\r\n"
00043                         "S..Setup\r\n"
00044                         "T..All LEDs and buzzer test\r\n"
00045                         "V..Battery test\r\n"
00046                         "X..Flight stats\r\n"
00047                         "Y..Program YGE I2C ESC\r\n"
00048                         "1-8..Individual LED/buzzer test\r\n"; // last line must be in this form for UAVPSet
00049 
00050 const uint8 RxChMnem[] = "TAERG12";
00051 
00052 uint8 MakeUpper(uint8 ch) {
00053     if ( ( ch >='a') && ( ch <='z' ) )
00054         ch = (ch - 'a') + 'A';
00055 
00056     return (ch);
00057 } // MakeUpper
00058 
00059 void ShowPrompt(void) {
00060     TxString("\r\n>");
00061 } // ShowPrompt
00062 
00063 void ShowRxSetup(void) {
00064     if ( F.UsingSerialPPM )
00065         if ( PPMPosPolarity[P[TxRxType]] )
00066             TxString("Serial PPM frame (Positive Polarity)");
00067         else
00068             TxString("Serial PPM frame (Negative Polarity)");
00069     else
00070         TxString("Odd Rx Channels PPM");
00071 } // ShowRxSetup
00072 
00073 void ShowSetup(boolean h) {
00074     int8 i;
00075 
00076     TxNextLine();
00077     if ( h )
00078         ParamSet = 1;
00079 
00080     TxString(SerHello);
00081 
00082     UpdateRTC();
00083     i = 0;
00084     while ( RTCString[i] != NULL )
00085         TxChar(RTCString[i++]);
00086     TxNextLine();
00087 
00088     TxString("Clock: 92MHz LPC1768 (mbed)\r\n");
00089 
00090     TxString("Aircraft: ");
00091     switch ( UAVXAirframe ) {
00092         case QuadAF:
00093             TxString("QUADROCOPTER\r\n");
00094             break;
00095         case TriAF:
00096             TxString("TRICOPTER\r\n");
00097             break;
00098         case VTAF:
00099             TxString("VTCOPTER\r\n");
00100             break;
00101         case HeliAF:
00102             TxString("HELICOPTER\r\n");
00103             break;
00104         case ElevAF:
00105             TxString("FLYING WING\r\n");
00106             break;
00107         case AilAF:
00108             TxString("AILERON\r\n");
00109             break;
00110         default:
00111             TxString("UNKNOWN\r\n");
00112     }
00113 
00114     if ( F.CompassValid ) {
00115         TxString("Compass: ");
00116         ShowCompassType();
00117         TxString(" ( offset  ");
00118         TxVal32((int16)P[CompassOffsetQtr] * 90,0,0);
00119         TxString("deg. )\r\n");
00120     }
00121 
00122     TxString("Baro: ");
00123     ShowBaroType();
00124 
00125     TxString("Accelerometers: ");
00126     ShowAccType();
00127     TxNextLine();
00128 
00129     TxString("Gyros: ");
00130     ShowGyroType();
00131     TxNextLine();
00132 
00133     TxString("Motor ESCs: ");
00134     switch ( P[ESCType] ) {
00135         case ESCPPM:
00136             TxString("PPM ");
00137             break;
00138         case ESCHolger:
00139             TxString("Holger I2C {");
00140             break;
00141         case ESCX3D:
00142             TxString("X-3D I2C {");
00143             break;
00144         case ESCYGEI2C:
00145             TxString("YGE I2C {");
00146             break;
00147     }
00148 
00149     if ( P[ESCType] != ESCPPM ) {
00150         for ( i = 0; i < NoOfI2CESCOutputs; i++ )
00151             if ( ESCI2CFail[i] )
00152                 TxString(" Fail");
00153             else
00154                 TxString(" OK");
00155         TxString(" }");
00156     }
00157     TxNextLine();
00158     
00159     if ( F.HaveBatterySensor )
00160          TxString("External Volt/Amp Sensor Fitted\r\n");
00161 #ifdef RX6CH
00162     TxString("6 CHANNEL VERSION - 5 ACTIVE CHANNELS ONLY\r\n");
00163 #endif // RX6CH
00164 
00165     TxString("Tx/Rx: ");
00166 
00167     switch ( P[TxRxType] ) {
00168         case FutabaCh3:
00169             TxString("Futaba Th 3 {");
00170             break;
00171         case FutabaCh2:
00172             TxString("Futaba Th 2 {");
00173             break;
00174         case FutabaDM8:
00175             TxString("Futaba DM8 & AR7000 {");
00176             break;
00177         case JRPPM:
00178             TxString("JR PPM {");
00179             break;
00180         case JRDM9:
00181             TxString("JR DM9 & AR7000{");
00182             break;
00183         case JRDXS12:
00184             TxString("JR DSX12 & AR7000 {");
00185             break;
00186         case DX7AR7000:
00187             TxString("Spektrum DX7 & AR7000 {");
00188             break;
00189         case DX7AR6200:
00190             TxString("Spektrum DX7 & AR6200 {");
00191             break;
00192         case CustomTxRx:
00193             TxString("Custom {");
00194             break;
00195         case FutabaCh3_6_7:
00196             TxString("Futaba Th 2 Swap 6&7 {");
00197             break;
00198         case DX7AR6000:
00199             TxString("Spektrum DX7 & AR6000 {");
00200             break;
00201         case DX6iAR6200:
00202             TxString("Spektrum DX6i & AR6200 {");
00203             break;
00204         case FutabaCh3_R617FS:
00205             TxString("Futaba Th 3 & R617FS {");
00206             break;
00207         case GraupnerMX16s:
00208             TxString("Graupner MX16s {");
00209             break;
00210         case DX7aAR7000:
00211             TxString("Spektrum DX7a & AR7000 {");
00212             break;
00213         case FrSkyDJT_D8R:
00214             TxString("FrSky DJT & D8R-SP Composite {");
00215             break;
00216         case ExternalDecoder:
00217             TxString("External Decoder {");
00218             break;
00219         case UnknownTxRx:
00220             TxString("UNKNOWN {");
00221             break;
00222         default:
00223             ;
00224     }  // switch
00225 
00226     if ( F.UsingSerialPPM )
00227         ShowRxSetup();
00228     else
00229         if ( P[TxRxType] != UnknownTxRx ) {
00230             for ( i = 0; i < RC_CONTROLS; i++)
00231                 TxChar(RxChMnem[RMap[i]]);
00232 
00233             TxString("} connect {");
00234 
00235             for ( i = 0; i < RC_CONTROLS; i+=2) {
00236                 TxChar(RxChMnem[RMap[i]]);
00237                 TxChar(' ');
00238             }
00239         }
00240     TxChar('}');
00241     if (( P[TxRxType] == DX7AR6200 ) || ( P[TxRxType] == DX6iAR6200))
00242         TxString(" Mix Rudder to Aux1/Flaps ");
00243     if ( F.UsingTxMode2 )
00244         TxString(" Tx Mode 2");
00245     else
00246         TxString(" Tx Mode 1");
00247     TxNextLine();
00248 
00249     TxString("Selected parameter set: "); // must be exactly this string as UAVPSet expects it
00250     TxChar('0' + ParamSet);
00251     TxNextLine();
00252 
00253 #ifdef MULTICOPTER
00254     TxString("Forward Flight: ");
00255     TxVal32((int16)Orientation * 75L, 1, 0);
00256     TxString("deg CW from K1 motor(s)\r\n");
00257 #endif // MULTICOPTER
00258 
00259     if ( F.UsingAngleControl )
00260         TxString("\tSticks control roll/pitch angle directly\r\n");
00261     else
00262         TxString("\tSticks control rate of change of roll/pitch angle\r\n");
00263 
00264     if ( F.UsingRTHAutoDescend )
00265         TxString("\tAuto descend ENABLED\r\n");
00266     else
00267         TxString("\tAuto descend disabled\r\n");
00268 
00269     if ( F.AllowTurnToWP )
00270         TxString("\tTurn toward Way Point\r\n");
00271     else
00272         TxString("\tHold heading\r\n");
00273 
00274     if ( F.AllowNavAltitudeHold )
00275         TxString("\tAllow Nav altitude hold\r\n");
00276     else
00277         TxString("\tWARNING - Manual Nav altitude hold\r\n");
00278 
00279     if ( !F.SDCardValid )
00280         TxString("\tSD Card NOT loaded - DISCONNECT power and load card if required.\r\n");
00281 
00282     TxString("\r\nALARM (if any):\r\n");
00283     if ( P[TxRxType] == UnknownTxRx )
00284         TxString("\tTx/Rx TYPE not set\r\n");
00285 #ifdef TESTING
00286     TxString("\tTEST VERSION - No Motors\r\n");
00287 #endif // TESTING
00288 
00289     if ( !F.ParametersValid )
00290         TxString("\tINVALID flight parameters (PID)!\r\n");
00291 
00292     if ( !F.BaroAltitudeValid )
00293         TxString("\tBarometer OFFLINE\r\n");
00294     if ( BaroRetries >= BARO_INIT_RETRIES )
00295         TxString("\tBaro Init: FAILED\r\n");
00296 
00297     if ( !F.RangefinderAltitudeValid )
00298         TxString("\tRangefinder OFFLINE\r\n");
00299 
00300     if ( F.GyroFailure )
00301         TxString("\tGyro FAILURE\r\n");
00302 
00303     if ( !F.AccelerationsValid )
00304         TxString("\tAccelerometers OFFLINE\r\n");
00305 
00306     if ( !F.CompassValid )
00307         TxString("\tCompass OFFLINE\r\n");
00308 
00309     if ( !F.Signal )
00310         TxString("\tBad EPAs or Tx switched off?\r\n");
00311     if ( Armed && FirstPass )
00312         TxString("\tUAVX is armed - DISARM!\r\n");
00313 
00314     if ( F.Navigate || F.ReturnHome )
00315         TxString("\tNavigate/RTH is selected - DESELECT!\r\n");
00316 
00317     if ( InitialThrottle >= RC_THRES_START )
00318         TxString("\tThrottle may be open - CLOSE!\r\n");
00319         
00320     if ( !F.UsingLEDDriver )
00321         TxString("\tPCA Line Driver OFFLINE - no BUZZER warnings!\r\n");
00322         
00323     ShowPrompt();
00324 } // ShowSetup
00325 
00326 void ProcessCommand(void) {
00327     static int8  p;
00328     static uint8 ch;
00329     static int8 d;
00330 
00331     if ( 1 ) {//!Armed.read() ) {
00332         ch = PollRxChar();
00333         if ( ch != NUL   ) {
00334             ch = MakeUpper(ch);
00335 
00336             switch ( ch ) {
00337                 case 'D':
00338                     UseDefaultParameters();
00339                     InitParameters();
00340                     ShowPrompt();
00341                     break;
00342                 case 'L'  :    // List parameters
00343                     TxString("\r\nParameter list for set #");    // do not change (UAVPset!)
00344                     TxChar('0' + ParamSet);
00345                     ReadParameters();
00346                     for ( p = 0 ; p < MAX_PARAMETERS; p++ ) {
00347                         TxString("\r\nRegister ");
00348                         TxValU((uint8)(p+1));
00349                         TxString(" = ");
00350                         TxValS(P[p]);
00351                     }
00352                     ShowPrompt();
00353                     break;
00354                 case 'M'  : // modify parameters
00355                     // no reprogramming in flight!!!!!!!!!!!!!!!
00356                     LEDBlue_ON;
00357                     TxString("\r\nRegister ");
00358                     p = (uint16)(RxNumU()-1);
00359                     // Attempts to block use of old versions of UAVPSet not compatible with UAVX
00360                     // assumes parameters are written sequentially from 0..(MAX_PARAMETERS-1)
00361 
00362                     TxString(" = ");
00363                     d = RxNumS();
00364                     if ( p < MAX_PARAMETERS ) {
00365                         // Keep RAM based set up to date.
00366                         if ( ParamSet == (uint8)1 ) {
00367                             WritePX(p, d);
00368                             if ( DefaultParams[p][1] )
00369                                 WritePX(MAX_PARAMETERS + p, d);
00370                         } else {
00371                             if ( !DefaultParams[p][1] )
00372                                 WritePX(MAX_PARAMETERS + p, d);
00373                         }
00374                         ParametersChanged = true;
00375                     }
00376                     if ( p < (MAX_PARAMETERS-1) )
00377                         F.ParametersValid = false;
00378                     else
00379                         if ( p == (MAX_PARAMETERS-1) ) {
00380                             WritePXImagefile();
00381                             F.ParametersValid = true;     // ALL parameters must be written
00382                         }
00383                     LEDBlue_OFF;
00384                     ShowPrompt();
00385                     break;
00386                 case 'N' :    // neutral values
00387                     GetNeutralAccelerations();
00388                     TxString("\r\nNeutral    R:");
00389                     TxValS(NewAccNeutral[LR]);
00390 
00391                     TxString("    P:");
00392                     TxValS(NewAccNeutral[BF]);
00393                     
00394                     TxString("   V:");
00395                     TxValS(NewAccNeutral[UD]);
00396                     ShowPrompt();
00397                     break;
00398                 case 'Z' : // set Paramset
00399                     p = RxNumU();
00400                     if ( p != (int8)ParamSet ) {
00401                         ParamSet = p;
00402                         ParametersChanged = true;
00403                         ReadParameters();
00404                     }
00405                     break;
00406                 case 'W' :    // comms with UAVXNav utility NOT UAVPSet
00407                     UAVXNavCommand();
00408                     //ShowPrompt();
00409                     break;
00410                 case 'R':    // receiver values
00411                     TxString("\r\nT:");
00412                     TxValU(ToPercent(RC[ThrottleRC], RC_MAXIMUM));
00413                     TxString(",R:");
00414                     TxValS(ToPercent(((RC[RollRC]- RC_NEUTRAL) * 2L), RC_MAXIMUM));
00415                     TxString(",P:");
00416                     TxValS(ToPercent(((RC[PitchRC]- RC_NEUTRAL) * 2L), RC_MAXIMUM));
00417                     TxString(",Y:");
00418                     TxValS(ToPercent(((RC[YawRC]- RC_NEUTRAL) * 2L), RC_MAXIMUM));
00419                     TxString(",5:");
00420                     TxValU(ToPercent(RC[RTHRC], RC_MAXIMUM));
00421                     TxString(",6:");
00422                     TxValS(ToPercent(((RC[CamPitchRC] - RC_NEUTRAL) * 2L), RC_MAXIMUM));
00423                     TxString(",7:");
00424                     TxValU(ToPercent(RC[NavGainRC], RC_MAXIMUM));
00425                     ShowPrompt();
00426                     break;
00427                 case 'S' :    // show status
00428                     ShowSetup(false);
00429                     break;
00430                 case 'X' :    // flight stats
00431                     ShowStats();
00432                     ShowPrompt();
00433                     break;
00434                 case 'A' :    // linear sensor
00435                     AttitudeTest();
00436                     ShowPrompt();
00437                     break;
00438                 case 'G':    // GPS
00439                     GPSTest();
00440                     ShowPrompt();
00441                     break;
00442                 case 'H':    // barometer
00443                     BaroTest();
00444                     ShowPrompt();
00445                     break;
00446                 case 'I':
00447                     TxString("\r\nI2C devices ...\r\n");
00448                     TxVal32(ScanI2CBus(),0,0);
00449                     TxString(" device(s) found\r\n");
00450                     ShowPrompt();
00451                     break;
00452                 case 'P'  :    // Receiver test
00453                     ReceiverTest();
00454                     ShowPrompt();
00455                     break;
00456                 case 'C'  :    // Compass test
00457                     DoCompassTest();
00458                     ShowPrompt();
00459                     break;
00460 
00461                 case 'K'  :    //Calibrate compass
00462                     CalibrateCompass();
00463                     ShowPrompt();
00464                     break;
00465 
00466                 case 'Y':    // configure YGE30i EScs
00467                     ConfigureESCs();
00468                     ShowPrompt();
00469                     break;
00470                 case '1':
00471                 case '2':
00472                 case '3':
00473                 case '4':
00474                 case '5':
00475                 case '6':
00476                 case '7':
00477                 case '8':
00478                     TxString("\r\nOutput test\r\n");
00479                     TxChar(ch);
00480                     TxChar(':');
00481                     switch ( ch ) {
00482                         case '1':
00483                             TxString("Aux2");
00484                             break;
00485                         case '2':
00486                             TxString("Blue");
00487                             break;
00488                         case '3':
00489                             TxString("Red");
00490                             break;
00491                         case '4':
00492                             TxString("Green");
00493                             break;
00494                         case '5':
00495                             TxString("Aux1");
00496                             break;
00497                         case '6':
00498                             TxString("Yellow");
00499                             break;
00500                         case '7':
00501                             TxString("Aux3");
00502                             break;
00503                         case '8':
00504                             TxString("Beeper");
00505                             break;
00506                     }
00507                     TxNextLine();
00508                     PowerOutput(ch-'1');
00509                     ShowPrompt();
00510                     break;
00511                 case 'T':
00512                     LEDsAndBuzzer();
00513                     ShowPrompt();
00514                     break;
00515 
00516                 case 'V' :    // Battery test
00517                     BatteryTest();
00518                     ShowPrompt();
00519                     break;
00520                 case '?'  :  // help
00521                     TxString(SerHelp);
00522                     ShowPrompt();
00523                     break;
00524                 default:
00525                     break;
00526             }
00527         }
00528     }
00529 } // ProcessCommand
00530