this version has all of Jim's fixes for reading the GPS and IMU data synchronously

Dependencies:   MODSERIAL SDFileSystem mbed SDShell CRC CommHandler FP LinkedList LogUtil

Revision:
1:8e24e633f8d8
Parent:
0:432b860b6ff7
Child:
2:7039be3daf6e
--- a/main.cpp	Mon Apr 22 21:26:04 2013 +0000
+++ b/main.cpp	Tue Apr 30 19:59:43 2013 +0000
@@ -13,9 +13,15 @@
 DigitalIn sd_detect(p27);
 DigitalOut ppsled(LED1);        //blink an LED at the 1PPS
 DigitalOut trig1led(LED2);      //blink an LED at the camera trigger detection
-DigitalOut recordDataled(LED4); //set the led when the record is on
-InterruptIn camera1Int(p30);    // camera interrupt in
-DigitalOut camera2Pin(p29);     // We dont use the second camera interrupt
+DigitalOut rxMsg(LED3);
+DigitalOut txMsg(LED4);
+//DigitalOut recordDataled(LED4); //set the led when the record is on
+
+//hardware trigger mechanization for bulb shutter commands
+DigitalInOut fire(p29);     //connected to the tip of 2.5mm connector (T2i)
+DigitalInOut pre_fire(p30); //connected to the mid-connection for 2.5mm connector (T2i)
+
+
 //USB serial data stream back to the PC
 Serial toPC(USBTX, USBRX);      //connect the GPS TX, RX to p9 and p10
 
@@ -66,16 +72,6 @@
     ppsled = !ppsled;               //blink an LED at the 1PPS
 };
 
-//ISR for detection of the hotshoe trigger 1
-void camera1ISR(void)
-{
-    //GPSTime is from POS message header
-    //PPSTimeOffset is an even sec to account for Time becoming known AFTER the 1PPS
-    //PPSTimeOffset + timeFromPPS.read() can be as large as 1.02 secs
-    camera1Time = GPSTime + PPSTimeOffset + timeFromPPS.read();    
-    camera1EventDetected = true;  //reset to false in main after processing the image detection
-    trig1led = !trig1led;  //blink an LEWD at the camera event detection
-};
 
 ///////////////////////////////////////////////////////
 //set up the USB port and the GPS COM port
@@ -171,14 +167,6 @@
     //GPS_COM1.baud(921600); wait_ms(500);  //without this wait -- the baud rate is not detected when using MODSERIAL     
 };
 
-void setupTriggers()
-{
-    camera1Int.mode(PullUp);
-    camera2Pin = 1;
-    //establish Trigger ISR 
-    camera1Int.rise(&camera1ISR);
-    
-};
 
 /////////////////////////////////////////////////////////////////////
 //  mbed main to support the Waldo_FCS
@@ -192,14 +180,19 @@
     OEM615BESTVEL velMsg;   //BESTVEL structure in OEMV615.h that has matching time to a BESTPOS message
     OEM615BESTVEL curVel;   //BESTVEL structure in OEMV615.h
 
+
+    fire.output();  //set the fire pin as outoput
+    pre_fire.output();  //set the pre-fire pin as output
+    //fire.mode(OpenDrain);
+    
+    //set up for the first trigger
+    fire = 1;
+    pre_fire = 1;
     //set up the GPS and mbed COM ports
     setupCOM(); 
     
     //set up the ADIS16488 
     setupADIS();
-    
-    //setup Hotshoe
-    setupTriggers();
 
     setUpMessages();  //set up the expected text message commands frm the PC 
     
@@ -223,22 +216,18 @@
     toPC.printf(" CRC after AA44121C header: %08x \n", CRC);
     wait(20);
     */
-    
-    int CRCerrors = 0;
-    
+        
     recordData = true;
     sendRecData = true;     
     
     unsigned long cyclesPerSec = 0;
-    unsigned long delTimeOfWrite = 0;
-    unsigned long maxWriteTime = 0;
     bool GPSdataWritten = false;
     
-    while(PPSCounter < 1000)
+    //while(PPSCounter < 300)
     ///////////////////////////////////////////////////////////////////////////
     // top of the while loop
     ///////////////////////////////////////////////////////////////////////////
-    //while(1)
+    while(1)
     {        
         //read the USB serial data from the PC to check for commands
         //in the primary real-time portion, there are no bytes from the PC so this has no impact
@@ -246,6 +235,20 @@
                 
         processPCmessages(fpNav, posMsg, velMsg);
         
+        if(fireTrigger)
+        {
+            //pre-fire the trigger using the mid-body 2.5mm connection (T2i)
+            pre_fire = 0;  //pin30 (midbody of connector) set to zero
+            wait(.01f);  //wait for 0.25 secs
+            fire = 0; //fire the trigger using the tip connection
+            wait(1.0);
+            fire = 1;
+            pre_fire = 1;
+            unsigned long triggerTime = GPSTimemsecs + PPSTimeOffset*1000 + timeFromPPS.read_us()/1000.0;
+            toPC.printf("WMsg TRIGGERTIME %10d \n", triggerTime);
+            fireTrigger = false;
+        }
+        
         cyclesPerSec++;
 
 //
@@ -286,20 +289,20 @@
                 curPos = *((OEM615BESTPOS*)&msgBuffer[messageLocation[savedMessageCounter-1]]);
                 posMsg = curPos;
                 
-                //if (streamPos)
+                if (streamPos)
                 {
-                        toPC.printf("BESTPOS %5d %1d %8.5lf %9.5lf %5.3lf %d %d %d\n",
+                        toPC.printf("BESTPOS %5d %1d %8.5lf %9.5lf %5.3lf %d %d\n",
                                           curPos.msgHeader.GPSTime_msecs,  curPos.solStatus,
                                           curPos.latitude, curPos.longitude, curPos.height,
-                                          curPos.numSV, curPos.numSolSV, curPos.numGGL1);
+                                          curPos.numSV, curPos.numSolSV);
                 }
                 
             } 
             else if (msgHdr.messageID == 99)  
             {
                 curVel = *((OEM615BESTVEL*)&msgBuffer[ messageLocation[savedMessageCounter-1] ]);
-                toPC.printf("BESTVEL  vel: horizontalSpeed= %5.3f heading=%5.1f verticalSpeed=%4.2f \n", 
-                    curVel.horizontalSpeed,  curVel.heading,  curVel.verticalSpeed );
+                //toPC.printf("BESTVEL  vel: horizontalSpeed= %5.3f heading=%5.1f verticalSpeed=%4.2f \n", 
+                //    curVel.horizontalSpeed,  curVel.heading,  curVel.verticalSpeed );
                 velMsg = curVel;
             }
             /*
@@ -316,6 +319,7 @@
             completeMessageAvailable = false;
         }
         
+        //write the GPS data to the SD card
         if (!IMUDataReady && !GPSdataWritten && timeFromPPS.read_us() > 500000 && recordData && (fpNav != NULL))
         {
                 totalBytesWritten += fwrite(&msgBuffer, 1, byteCounter, fpNav);
@@ -329,13 +333,13 @@
             //write the IMU data
             if ( recordData && (fpNav != NULL) )
             {   
-                delTimeOfWrite = timeFromStart.read_us();
+                //delTimeOfWrite = timeFromStart.read_us();
                 
                 if (fillingPingWritingPong) fwrite(&imuPong, 1, IMUrecArraySize*sizeof(IMUREC), fpNav);
                 else                        fwrite(&imuPing, 1, IMUrecArraySize*sizeof(IMUREC), fpNav);
                     
-                delTimeOfWrite = (unsigned long)((unsigned long)timeFromStart.read_us() - delTimeOfWrite);
-                if (delTimeOfWrite > maxWriteTime) maxWriteTime = delTimeOfWrite;                
+                //delTimeOfWrite = (unsigned long)((unsigned long)timeFromStart.read_us() - delTimeOfWrite);
+                //if (delTimeOfWrite > maxWriteTime) maxWriteTime = delTimeOfWrite;                
             }
             IMURecordCounter+=IMUrecArraySize;
             IMUDataReady = false;
@@ -349,15 +353,11 @@
         
         if (detectedGPS1PPS)  //true if we are exactly at a 1PPS event detection
         {   
-            toPC.printf("PPS=%4d stat=%1d bytes=%3d GPSMsgs=%2d  #write=%8d cycles=%6d  MR=%5u\n", 
-                            PPSCounter, posMsg.solStatus, savedByteCounter, savedPerSecMessageCounter, 
-                            totalBytesWritten, cyclesPerSec, maxWriteTime );
+            //toPC.printf("PPS=%4d stat=%1d bytes=%3d GPSMsgs=%2d  #write=%8d cycles=%6d\n", 
+            //                PPSCounter, posMsg.solStatus, savedByteCounter, savedPerSecMessageCounter, 
+            //                totalBytesWritten, cyclesPerSec );
                             
-            //if ( (savedIMUClockCounter - IMURecordCounter) > 2) toPC.printf(" IMU diffs = %2d \n", savedIMUClockCounter - IMURecordCounter);
-            //completeMessageAvailable = false;   
             cyclesPerSec = 0;
-            maxDelIMUmsecs = 0;
-            maxWriteTime = 0;
             totalBytesWritten = 0;
             GPSdataWritten = false;