StoRC
Autonomous Payload Delivery System
debug.pde
Go to the documentation of this file.
00001 /***********************************************************
00002  * StoRC - Search to Rescue Craft
00003  * MEAM Senior Design 2011-2012
00004  * 
00005  * Authors:  Michael Posner (CIS, MEAM '12)
00006  * Timothy Hennelly (ESE '12)
00007  * Jacob Orloff (MEAM '12)
00008  * 
00009  * (some code from ArduPilot Mega project, found here:
00010  * http://code.google.com/p/ardupilot-mega/ )
00011  * 
00012  * Licensing:
00013  * 
00014  * This program is free software: you can redistribute it and/or modify 
00015  * it under the terms of the GNU General Public License as published by 
00016  * the Free Software Foundation, either version 3 of the License, or 
00017  * (at your option) any later version. 
00018  * 
00019  * This program is distributed in the hope that it will be useful, 
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
00022  * GNU General Public License for more details. 
00023  * 
00024  * You should have received a copy of the GNU General Public License 
00025  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00026  * 
00027  ***********************************************************/
00028 
00029 /**
00030  *  @file debug.pde
00031  *  @brief Useful debugging functions that print to Serial
00032  *  @author Michael Posner (CIS, MEAM '12)
00033  *  @author Timothy Hennelly (ESE '12)
00034  *  @author Jacob Orloff (MEAM '12)
00035  *  
00036  *  This file contains functions that print debugging information to Serial.  We don't
00037  *  want them cluttering up the main file, but they're definitely useful to have and to
00038  *  keep for sanity checks.
00039  */
00040 
00041 
00042 /**
00043  * Print GPS data for testing / debugging
00044  */
00045 void debug_gps(void) {
00046 
00047   Serial.print("gps->new_data = ");  
00048   Serial.println(gps->new_data);
00049   Serial.print("gps->status() = ");
00050   Serial.print(gps->status());
00051   Serial.println("  ( 0:No GPS  1:No FIX  2:GPS Lock )");
00052   Serial.print("Num Sats: ");
00053   Serial.println(gps->num_sats);
00054   Serial.print("time epoch: ");
00055   Serial.println(gps->epoch());
00056 
00057   if(gps->new_data) {
00058 
00059     //Print time stuff.  In theory the ArduPilot Library's epoch() command should return
00060     //  what time scale the GPS is currently using, but it's wrong.  this GPS returns
00061     //  number of milliseconds since the start of the current week.  this is used below.
00062     Serial.print(" Time: ");
00063     Serial.print(gps->time);
00064     Serial.println(" (GPS Millisecond time of the week)");
00065 
00066     //GPS Millisecond time of week -> HH:MM:SS
00067     long day = floor((gps->time/1000)/SEC_PER_DAY);
00068     long hour = floor(((gps->time/1000) - day*SEC_PER_DAY)/SEC_PER_HOUR);
00069     long minute = floor(((gps->time/1000) - day*SEC_PER_DAY - hour*SEC_PER_HOUR)/SEC_PER_MIN);
00070     long second = floor((gps->time/1000) - day*SEC_PER_DAY - hour*SEC_PER_HOUR - minute*SEC_PER_MIN);
00071 
00072     //convert to EST
00073     hour -= 5;
00074     if(hour < 0) {
00075       hour += 24;
00076     }
00077 
00078     Serial.print(" Time: ");
00079 
00080     switch(day) {
00081     case 0:
00082       Serial.print("Sun");
00083       break;
00084     case 1:
00085       Serial.print("Mon");
00086       break;
00087     case 2:
00088       Serial.print("Tues");
00089       break;
00090     case 3:
00091       Serial.print("Wed");
00092       break;
00093     case 4:
00094       Serial.print("Thurs");
00095       break;
00096     case 5:
00097       Serial.print("Fri");
00098       break;
00099     case 6:
00100       Serial.print("Sat");
00101       break;
00102     }
00103 
00104     Serial.print(" ");
00105     Serial.print(hour);
00106     Serial.print(":");
00107     Serial.print(minute);
00108     Serial.print(":");
00109     Serial.print(second);
00110     Serial.println(" (EST)");
00111 
00112 
00113     Serial.print(" Lat: ");
00114     Serial.print(gps->latitude);
00115     Serial.println(" (x10^7)");
00116     Serial.print(" Lon: ");
00117     Serial.print(gps->longitude);
00118     Serial.println(" (x10^7)");
00119     Serial.print(" Alt: ");
00120     Serial.print(gps->altitude/100.0);
00121     Serial.println(" (in m) ");
00122     Serial.print(" Ground Speed: ");
00123     Serial.print(gps->ground_speed/100.0);
00124     Serial.println(" (in m/s) ");
00125     Serial.print(" Ground Course: ");
00126     Serial.print(gps->ground_course/100.0);
00127     Serial.println(" (in deg)");
00128     Serial.println();
00129 
00130   }  //end if new_data
00131 
00132 }
00133 
00134 /**
00135  * Print barometer data to Serial
00136  */
00137 void debug_barometer(void) {
00138 
00139   Serial.println("Barometer Data ------");
00140   Serial.print("Temp: ");
00141   Serial.print(barometer.Temp*0.1 + 273.15);  //barometer returns in 0.1 deg C, print K
00142   Serial.println(" K");
00143   Serial.print("Pressure: ");
00144   Serial.print(barometer.Press/1000.0);  //barometer returns in Pa, print kPa
00145   Serial.println(" kPa");
00146 
00147 }
00148 
00149 /**
00150  * Print gyro data to Serial
00151  */
00152 void debug_gyro(void){
00153   Serial.print("Gyro x=");
00154   Serial.print(gyro.x);
00155   Serial.print("; y=");
00156   Serial.print(gyro.y);
00157   Serial.print("; z=");
00158   Serial.println(gyro.z);  
00159 }
00160 
00161 /**
00162  * Print acceleration data to Serial
00163  */
00164 void debug_accel(void){
00165   Serial.print("Accel x=");
00166   Serial.print(accel.x);
00167   Serial.print("; y=");
00168   Serial.print(accel.y);
00169   Serial.print("; z=");
00170   Serial.println(accel.z);
00171 }
00172 
00173 
00174 /**
00175  * Print airspeed data to Serial
00176  */
00177 void debug_airspeed(void) {
00178 
00179   Serial.print("Pitot Zero: ");
00180   Serial.print(pitot_pressure_offset);
00181   Serial.println(" kPa");
00182 
00183   Serial.print("Airspeed: ");
00184   Serial.print(airspeed);
00185   Serial.println(" m/s");
00186 
00187 }
00188 
00189 /**
00190  * Print RC data to Serial
00191  */
00192 void debug_rc(void) {
00193 
00194   Serial.print("RC:  CH1(E): ");
00195   Serial.print(rc_elevator);
00196   Serial.print(", CH2(R): ");
00197   Serial.print(rc_rudder);
00198   Serial.print(", CH3(T): ");
00199   Serial.print(rc_throttle);
00200   Serial.print(", CH4: ");
00201   Serial.print(rc_4);
00202   Serial.print(", CH5: ");
00203   Serial.print(rc_5);
00204   Serial.print(", CH6: ");
00205   Serial.print(rc_6);
00206   Serial.print(", CH7: ");
00207   Serial.print(rc_7);
00208   Serial.print(", CH8: ");
00209   Serial.println(rc_8);
00210 }
00211 
00212 /**
00213  * Print magnetometer values to Serial
00214  */
00215 void debug_magnetometer(void) {
00216   
00217   Serial.print("Magnetometer:  heading:");
00218   Serial.print(RAD2DEG(compass.heading));
00219   Serial.print(" deg   X: ");
00220   Serial.print(compass.mag_x);
00221   Serial.print(", Y: ");
00222   Serial.print(compass.mag_y);
00223   Serial.print(", Z: ");
00224   Serial.println(compass.mag_z);
00225 
00226 }
00227 
00228 /**
00229  * Print Controls variables and data to Serial
00230  */
00231 void debug_controls(void){
00232 
00233   Serial.print(" phi= ");
00234   Serial.print(dcm.roll_sensor/100);
00235   Serial.print(" dr_roll_comp= ");
00236   Serial.print(del_RUD);
00237   Serial.print(" kd_roll_comp_gm= ");
00238   Serial.print(kd_rud_gm);
00239   Serial.print(" kp_roll_comp_gm= ");
00240   Serial.print(kp_rud_gm);
00241   Serial.print(" delta_rudder= ");
00242   Serial.print(del_RUD);
00243   Serial.print(" rc_rudder= ");
00244   Serial.println(rc_rudder);
00245 
00246 
00247 }
00248 
00249 /**
00250 * Print data from DCM to Serial
00251 */
00252 void debug_dcm(void) {
00253   
00254   Serial.print("DCM:  ");
00255   Serial.print("roll: ");
00256   Serial.print(dcm.roll_sensor/100);
00257   Serial.print(", pitch: ");
00258   Serial.print(dcm.pitch_sensor/100);
00259   Serial.print(", yaw: ");
00260   Serial.println(dcm.yaw_sensor/100);
00261   
00262 }
00263