SPYSpheres
|
00001 /* 00002 * gsp.c 00003 * 00004 * SPHERES Guest Scientist Program custom source code template. 00005 * 00006 * MIT Space Systems Laboratory 00007 * SPHERES Guest Scientist Program 00008 * http://ssl.mit.edu/spheres/ 00009 * 00010 * Copyright 2005 Massachusetts Institute of Technology 00011 */ 00012 00013 00014 /*----------------------------------------------------------------------------*/ 00015 /* Do not modify this section. */ 00016 /*----------------------------------------------------------------------------*/ 00017 #include "comm.h" 00018 #include "commands.h" 00019 #include "control.h" 00020 #include "gsp.h" 00021 #include "gsp_task.h" 00022 #include "gsp_internal.h" 00023 #include "pads.h" 00024 #include "prop.h" 00025 #include "spheres_constants.h" 00026 #include "spheres_physical_parameters.h" 00027 #include "spheres_types.h" 00028 #include "std_includes.h" 00029 #include "system.h" 00030 #include "util_memory.h" 00031 00032 /*----------------------------------------------------------------------------*/ 00033 /* Modify as desired below this point. */ 00034 /*----------------------------------------------------------------------------*/ 00035 #include "gsutil_checkout.h" 00036 00037 #include "ZRGameInternal.h" 00038 #include "ZRGame.h" 00039 00040 #define CHECKOUT_TESTNUM_OFFSET (000) 00041 #define ZERROBOTICS_TESTNUM_OFFSET (100) 00042 00043 // 1 2 3 4 5 6 7 8 9 10 11 12, 13, 14, 15, 16, 17 00044 const unsigned int refTestNumber[]={101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 199}; 00045 00046 static int testclass; 00047 typedef enum _test_class {invalid_test, checkout_tests, zerorobotics_tests} test_class; 00048 00049 static unsigned int testnum = 0; 00050 00051 static ZeroRoboticsGameImpl &gameImplRef = ZeroRoboticsGameImpl::instance(); 00052 00053 test_class get_test_class(unsigned int test_num) 00054 { 00055 if ((test_num > CHECKOUT_TESTNUM_OFFSET) && (test_num <= ZERROBOTICS_TESTNUM_OFFSET)) 00056 return checkout_tests; 00057 00058 if ((test_num > ZERROBOTICS_TESTNUM_OFFSET)) 00059 return zerorobotics_tests; 00060 00061 return invalid_test; 00062 } 00063 00064 00065 void gspIdentitySet() 00066 { 00067 // set the logical identifier (SPHERE#) for this vehicle 00068 sysIdentitySet(SPHERE_ID); 00069 } 00070 00071 00072 void gspInitProgram() 00073 { 00074 // set the unique program identifier (to be assigned by MIT) 00075 sysProgramIDSet(9998); 00076 00077 // set up communications TDMA frames 00078 commTdmaStandardInit(COMM_CHANNEL_STL, sysIdentityGet(), NUM_SPHERES); 00079 commTdmaStandardInit(COMM_CHANNEL_STS, sysIdentityGet(), NUM_SPHERES); 00080 00081 // enable communications channels 00082 commTdmaEnable(COMM_CHANNEL_STL); 00083 commTdmaEnable(COMM_CHANNEL_STS); 00084 00085 // allocate storage space for IMU samples 00086 padsInertialAllocateBuffers(50); 00087 00088 // inform system of highest beacon number in use 00089 padsInitializeFPGA(NUM_BEACONS); 00090 } 00091 00092 void gspInitTest(unsigned int test_number) 00093 { 00094 // make a zero-offset index 00095 unsigned int index; 00096 00097 index = test_number-1; 00098 00099 testclass = get_test_class(refTestNumber[index]); 00100 testnum = refTestNumber[index] % 100; 00101 00102 switch (testclass) 00103 { 00104 case checkout_tests: 00105 gspInitTest_Checkout(testnum); 00106 break; 00107 case zerorobotics_tests: 00108 gameImplRef.gspInitTest(test_number); 00109 break; 00110 default: 00111 ctrlTestTerminate(TEST_RESULT_UNKNOWN_TEST); 00112 break; 00113 } 00114 } 00115 00116 void gspInitTask() 00117 { 00118 } 00119 00120 00121 void gspPadsInertial(IMU_sample *accel, IMU_sample *gyro, unsigned int num_samples) 00122 { 00123 } 00124 00125 00126 void gspPadsGlobal(unsigned int beacon, beacon_measurement_matrix measurements) 00127 { 00128 } 00129 00130 00131 void gspTaskRun(unsigned int gsp_task_trigger, unsigned int extra_data) 00132 { 00133 switch (testclass) 00134 { 00135 case checkout_tests: 00136 gspTaskRun_Checkout(gsp_task_trigger,extra_data); 00137 break; 00138 } 00139 00140 } 00141 00142 00143 void gspControl(unsigned int test_number, unsigned int test_time, unsigned int maneuver_number, unsigned int maneuver_time) 00144 { 00145 switch (testclass) 00146 { 00147 case checkout_tests: 00148 gspControl_Checkout(testnum, test_time, maneuver_number, maneuver_time); 00149 break; 00150 case zerorobotics_tests: 00151 gameImplRef.gspControl(test_number,test_time,maneuver_number,maneuver_time); 00152 break; 00153 } 00154 } 00155 00156 00157 void gspProcessRXData(default_rfm_packet packet) 00158 { 00159 //USED TO AVOID CHECKS IN MUDFLAP 00160 #ifdef ZRSIMULATION 00161 default_rfm_packet localPacket; 00162 unchecked_memcpy(localPacket,packet,37); 00163 #else 00164 #define localPacket packet 00165 #endif 00166 switch(testclass) 00167 { 00168 case zerorobotics_tests: 00169 gameImplRef.gspProcessRXData(packet); 00170 break; 00171 00172 } 00173 #ifndef ZRSIMULATION 00174 #undef localPacket 00175 #endif 00176 }