StoRC
Autonomous Payload Delivery System
|
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 telemetry.pde 00031 * @brief Functions for sending telemetry data over Serial3 to the Xbee 00032 * @author Michael Posner (CIS, MEAM '12) 00033 * @author Timothy Hennelly (ESE '12) 00034 * @author Jacob Orloff (MEAM '12) 00035 * 00036 */ 00037 00038 00039 void transmit_imu(void) { 00040 00041 Serial3.println("IM"); 00042 Serial3.println(millis()); 00043 Serial3.println(accel.x); 00044 Serial3.println(accel.y); 00045 Serial3.println(accel.z); 00046 Serial3.println(gyro.x); 00047 Serial3.println(gyro.y); 00048 Serial3.println(gyro.z); 00049 00050 } 00051 00052 void transmit_gps(void) { 00053 00054 //GPS Millisecond time of week -> HH:MM:SS 00055 long day = floor((gps->time/1000)/SEC_PER_DAY); 00056 long hour = floor(((gps->time/1000) - day*SEC_PER_DAY)/SEC_PER_HOUR); 00057 long minute = floor(((gps->time/1000) - day*SEC_PER_DAY - hour*SEC_PER_HOUR)/SEC_PER_MIN); 00058 long second = floor((gps->time/1000) - day*SEC_PER_DAY - hour*SEC_PER_HOUR - minute*SEC_PER_MIN); 00059 00060 //convert to EST 00061 hour -= 5; 00062 if(hour < 0) { 00063 hour += 24; 00064 } 00065 00066 Serial3.println("GP"); 00067 Serial3.println(millis()); 00068 Serial3.println(day); 00069 Serial3.println(hour); 00070 Serial3.println(minute); 00071 Serial3.println(second); 00072 00073 Serial3.println(gps->latitude); //these are *10^7, will correct in MATLAB 00074 Serial3.println(gps->longitude); //these are *10^7, will correct in MATLAB 00075 Serial3.println(gps->altitude/100.0); 00076 Serial3.println(gps->ground_speed/100.0); 00077 Serial3.println(gps->ground_course/100.0); 00078 00079 00080 } 00081 00082 void transmit_barometer(void) { 00083 00084 Serial3.println("BA"); 00085 Serial3.println(millis()); 00086 Serial3.println(barometer.Temp*0.1 + 273.15); //barometer returns in 0.1 deg C, print K 00087 Serial3.println(barometer.Press/1000.0); //barometer returns in Pa, print kPa 00088 00089 } 00090 00091 void transmit_rc(void) { 00092 00093 Serial3.println("RC"); 00094 Serial3.println(millis()); 00095 Serial3.println(rc_elevator); 00096 Serial3.println(rc_rudder); 00097 Serial3.println(rc_throttle); 00098 Serial3.println(rc_4); 00099 Serial3.println(rc_5); 00100 Serial3.println(rc_6); 00101 Serial3.println(rc_7); 00102 Serial3.println(rc_8); 00103 00104 } 00105 00106 void transmit_airspeed(void) { 00107 00108 Serial3.println("AR"); 00109 Serial3.println(millis()); 00110 Serial3.println(pitot_pressure_offset); 00111 Serial3.println(airspeed); 00112 00113 } 00114 00115 void transmit_magnetometer(void) { 00116 00117 Serial3.println("MG"); 00118 Serial3.println(millis()); 00119 Serial3.println(RAD2DEG(compass.heading)); 00120 Serial3.println(dcm.roll_sensor/100.0); 00121 Serial3.println(dcm.pitch_sensor/100.0); 00122 Serial3.println(dcm.yaw_sensor/100.0); 00123 00124 } 00125 00126 void transmit_controls_rudder(void) { 00127 00128 Serial3.println("CR"); 00129 Serial3.println(millis()); 00130 00131 Serial3.println(KP_RUD); 00132 Serial3.println(kp_rud_gm); 00133 Serial3.println(KD_RUD); 00134 Serial3.println(kd_rud_gm); 00135 Serial3.println(KI_RUD); 00136 Serial3.println(ki_rud_gm); 00137 Serial3.println(I_RUD); 00138 Serial3.println(del_RUD); 00139 00140 } 00141 00142 void transmit_controls_elevator(void) { 00143 00144 Serial3.println("CE"); 00145 Serial3.println(millis()); 00146 00147 Serial3.println(KP_ELE); 00148 Serial3.println(kp_ele_gm); 00149 Serial3.println(KP_RP); 00150 Serial3.println(KI_ELE); 00151 Serial3.println(ki_ele_gm); 00152 Serial3.println(I_ELE); 00153 Serial3.println(del_ELE); 00154 00155 } 00156 00157 void transmit_controls_throttle(void) { 00158 00159 Serial3.println("CT"); 00160 Serial3.println(millis()); 00161 00162 Serial3.println(KP_THR); 00163 Serial3.println(kp_thr_gm); 00164 Serial3.println(KI_THR); 00165 Serial3.println(ki_thr_gm); 00166 Serial3.println(I_THR); 00167 Serial3.println(del_ALT); 00168 Serial3.println(del_THR); 00169 00170 } 00171 00172 void transmit_state(void) { 00173 00174 Serial3.println("ST"); 00175 Serial3.println(millis()); 00176 00177 if(drop_state) { 00178 Serial3.println(1); 00179 } 00180 else { 00181 Serial3.println(0); 00182 } 00183 00184 Serial3.println(logging_sw); 00185 00186 if(get_wind_profile) { 00187 Serial3.println(1); 00188 } 00189 else { 00190 Serial3.println(0); 00191 } 00192 Serial3.println(avg_wind_ns); 00193 Serial3.println(avg_wind_ew); 00194 Serial3.println(drift_ns); 00195 Serial3.println(drift_ew); 00196 00197 } 00198 00199 void transmit_navigation(void) { 00200 00201 Serial3.println("NA"); 00202 Serial3.println(millis()); 00203 00204 Serial3.println(LAT_C); 00205 Serial3.println(LON_C); 00206 Serial3.println(del_LAT); 00207 Serial3.println(del_LON); 00208 Serial3.println(psi_c); 00209 Serial3.println(psi_error); 00210 Serial3.println(phi_c); 00211 Serial3.println(DROP_THRESH); 00212 00213 } 00214 00215 00216 void transmit_data(void) { 00217 00218 transmit_imu(); 00219 00220 if(use_gps == true) { 00221 transmit_gps(); 00222 } 00223 00224 transmit_barometer(); 00225 transmit_rc(); 00226 transmit_airspeed(); 00227 transmit_magnetometer(); 00228 transmit_controls_rudder(); 00229 transmit_controls_elevator(); 00230 transmit_controls_throttle(); 00231 transmit_state(); 00232 transmit_navigation(); 00233 00234 } 00235 00236 00237 00238 00239 00240