Prof Greg Egan / Mbed 2 deprecated UAVXArm-GKE

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stats.c Source File

stats.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 ZeroStats(void);
00024 void ReadStatsPX(void);
00025 void WriteStatsPX(void);
00026 void ShowStats(void);
00027 
00028 int16     Stats[MAX_STATS];
00029 
00030 #define INIT_MIN 1000L
00031 
00032 void ZeroStats(void)
00033 {
00034     int8 s;
00035 
00036     for (s = 0 ; s < MAX_STATS ; s++ )
00037         Stats[s] = 0;
00038 
00039     Stats[MinHDiluteS] = INIT_MIN;
00040     Stats[MaxHDiluteS] = 0;
00041     Stats[MinROCS] = INIT_MIN;
00042     Stats[MaxROCS] = 0;
00043     Stats[GPSMinSatsS] = INIT_MIN;
00044     Stats[GPSMaxSatsS] = 0;
00045     Stats[MinTempS] = INIT_MIN;
00046     Stats[MaxTempS] = 0;
00047 
00048 } // ZeroStats
00049 
00050 void ReadStatsPX(void)
00051 {
00052     int8 s;
00053 
00054     for (s = 0 ; s < MAX_STATS ; s++ )
00055         Stats[s] = Read16PX(STATS_ADDR_PX + s*2);
00056 } // InitStats
00057 
00058 void WriteStatsPX()
00059 {
00060     int8 s, i;
00061     int16 Temp;
00062 
00063     if ( P[ESCType] != ESCPPM )
00064         for ( i = 0; i < NoOfI2CESCOutputs; i++ )
00065             Stats[ESCI2CFailS] += ESCI2CFail[i];
00066 
00067     for (s = 0 ; s < MAX_STATS ; s++ )
00068         Write16PX(STATS_ADDR_PX + s*2, Stats[s]);
00069 
00070     Temp = ToPercent(CruiseThrottle, OUT_MAXIMUM);
00071     WritePX(PercentCruiseThr, Temp);
00072 
00073 } // WriteStatsPX
00074 
00075 void ShowStats(void)
00076 {
00077     TxString("\r\nFlight Statistics\r\n");
00078 
00079     if ( Stats[BadS] != 0 )
00080     {
00081         TxString("Misc(gke):     \t");TxVal32((int32)Stats[BadS],0,' '); TxVal32((int32)Stats[BadNumS],0,' ');TxNextLine();
00082     }
00083 
00084     TxString("\r\nSensor/Rx Failures (Count)\r\n");
00085     TxString("I2CBus:   \t");TxVal32((int32)Stats[I2CFailS],0,0); TxNextLine();
00086     TxString("GPS:      \t");TxVal32((int32)Stats[GPSInvalidS],0,0); TxNextLine();
00087     TxString("Acc:      \t");TxVal32((int32)Stats[AccFailS], 0, 0); TxNextLine();
00088     TxString("Gyro:     \t");TxVal32((int32)Stats[GyroFailS], 0, 0); TxNextLine();
00089     TxString("Comp:     \t");TxVal32((int32)Stats[CompassFailS], 0, 0); TxNextLine();
00090     TxString("Baro:     \t");TxVal32((int32)Stats[BaroFailS],0 , 0); TxNextLine();
00091     if ( P[ESCType] != ESCPPM )
00092     {
00093         TxString("I2CESC:   \t");TxVal32((int32)Stats[ESCI2CFailS],0 , 0); TxNextLine();
00094     }
00095     TxString("Rx:       \t");TxVal32((int32)Stats[RCGlitchesS],0,' '); TxNextLine(); 
00096     TxString("Failsafes:\t");TxVal32((int32)Stats[RCFailsafesS],0,' '); TxNextLine();
00097     
00098     TxString("\r\nBaro\r\n"); // can only display to 3276M
00099     TxString("Alt:      \t");TxVal32((int32)Stats[BaroRelAltitudeS], 1, ' '); TxString("M \r\n");
00100     if ( Stats[MinROCS] < INIT_MIN )
00101     {
00102         TxString("ROC:      \t");TxVal32((int32)Stats[MinROCS], 1, ' '); 
00103                             TxVal32((int32)Stats[MaxROCS], 1, ' '); TxString("M/S\r\n");
00104     }
00105     
00106     if ( Stats[MinTempS] < INIT_MIN )
00107     {
00108         TxString("Ambient:  \t");TxVal32((int32)Stats[MinTempS], 1, ' '); 
00109                             TxVal32((int32)Stats[MaxTempS], 1, ' '); TxString("C\r\n");
00110     }
00111 
00112     TxString("\r\nGPS\r\n");
00113     TxString("Alt:      \t");TxVal32((int32)Stats[GPSAltitudeS], 1, ' '); TxString("M\r\n");
00114     #ifdef GPS_INC_GROUNDSPPXD 
00115     TxString("Vel:      \t");TxVal32(ConvertGPSToM((int32)Stats[GPSVelS]), 1, ' '); TxString("M/S\r\n"); 
00116     #endif // GPS_INC_GROUNDSPPXD
00117 
00118     if ( Stats[GPSMinSatsS] < INIT_MIN )
00119     {
00120         TxString("Sats:     \t");TxVal32((int32)Stats[GPSMinSatsS], 0, ' ');
00121         TxVal32((int32)Stats[GPSMaxSatsS], 0, 0); TxNextLine();
00122     }
00123 
00124     if ( Stats[MinHDiluteS] < INIT_MIN )
00125     {
00126         TxString("HDilute:  \t");TxVal32((int32)Stats[MinHDiluteS], 2, ' ');
00127         TxVal32((int32)Stats[MaxHDiluteS], 2, 0); TxNextLine();
00128     }
00129 
00130     if ( Stats[NavValidS] )
00131         TxString("Navigation ENABLED\r\n");    
00132     else
00133         TxString("Navigation DISABLED (No fix at launch)\r\n");
00134        
00135 } // ShowStats
00136 
00137