synch the camera trigger with the signal in phase and quadrature (every frame or every N frames). We can also simulate the product by the in-phase signal (with a small arbitrary phase difference)

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
mbedalvaro
Date:
Mon Dec 08 07:03:38 2014 +0000
Parent:
0:4b5874bff9bb
Commit message:
this is the latest code for the active markers project

Changed in this revision

Flipper.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Flipper.h	Mon Jul 14 09:35:12 2014 +0000
+++ b/Flipper.h	Mon Dec 08 07:03:38 2014 +0000
@@ -3,9 +3,9 @@
 
 #include "mbed.h"
 
-#define shutterPin p21 // for tests
-#define  ledPin p22 // the actual modulation of the LED source (equal to PHASE or QUAD signal every N frames)
-#define  cameraTriggerPin p23
+#define  ledPin p23 // the actual modulation of the LED source (equal to PHASE or QUAD signal every N frames)
+#define shutterPin p22 // for tests
+#define  cameraTriggerPin p21
 
 // A class for flip()-ing a DigitalOut using a timer
 
@@ -28,7 +28,7 @@
     }
     
     void start() {
-        myTicker.attach_us(this, &Flipper::flip, us_interval); // the address of the object, member function, and interval
+        myTicker.attach_us(this, &Flipper::flip, (unsigned int)(0.5*us_interval)); // the address of the object, member function, and interval
     }
     
    void stop() {
@@ -58,10 +58,18 @@
         NUM_STATES
         };
   
-    Trigger(PinName pin, float fps, unsigned int exposure) : _pin(pin) {
+    //Trigger(PinName pin, float fps, unsigned int exposure) : _pin(pin) {
+//    _pin=1;
+//    us_exposureTime=exposure;
+//    us_waitingTime=(unsigned int)(1000000.0/fps-us_exposureTime);
+//    framesQPToggle=2; // default number of frames before toggling between Q and P signals (delaying the Flipper signal by 90 deg). 
+//    QP_Mode=true;
+//    }
+
+Trigger(PinName pin, unsigned int waitingtime, unsigned int exposure) : _pin(pin) {
     _pin=1;
     us_exposureTime=exposure;
-    us_waitingTime=(unsigned int)(1000000.0/fps-us_exposureTime);
+    us_waitingTime=waitingtime;
     framesQPToggle=2; // default number of frames before toggling between Q and P signals (delaying the Flipper signal by 90 deg). 
     QP_Mode=true;
     }
@@ -70,8 +78,12 @@
         framesQPToggle=numToggleQPFrames;
     }
     
-    void setFrameRate(float fps) {
-        us_waitingTime=(unsigned int)(1000000.0/fps-us_exposureTime);
+   // void setFrameRate(float fps) {
+//        us_waitingTime=(unsigned int)(1000000.0/fps-us_exposureTime);
+//    }
+    
+     void setFrameRate(unsigned int waitingtime) {
+        us_waitingTime=waitingtime;
     }
     
      void setExposure(unsigned int exposure) {
@@ -143,7 +155,7 @@
     }
     
     void start() {
-        myTicker.attach_us(this, &Shutter::flip, us_interval); // the address of the object, member function, and interval
+        myTicker.attach_us(this, &Shutter::flip, (unsigned int)(0.5*us_interval)); // the address of the object, member function, and interval
     }
     
    void mixSignal(bool mode) {
--- a/main.cpp	Mon Jul 14 09:35:12 2014 +0000
+++ b/main.cpp	Mon Dec 08 07:03:38 2014 +0000
@@ -4,22 +4,27 @@
 // The following parameters can be changed by serial commands:
 // NOTE: program 9 on the LCC-230 gives a freq of 150Hz. If frame rate for the camera is 30fps, then the nb of cycles per frame is 150/30=5
 // for 28.09, then the of cycles per frame is 150/28.09=5.339
-float CAMERA_FPS=15;//28.0915;//28.09;
-unsigned long CAMERA_TRIGGER_PERIOD=1000000.0/CAMERA_FPS;
-float EXPOSURE_TIME_FACTOR=1.0/4;
+float CAMERA_FPS=58.75;//28.0915;//28.09;
+unsigned long CAMERA_TRIGGER_PERIOD=1000000.0/CAMERA_FPS; // it is recommendable that this division gives an integer!
+float EXPOSURE_TIME_FACTOR=1.0/3;
 unsigned long EXPOSURE_TIME=EXPOSURE_TIME_FACTOR*CAMERA_TRIGGER_PERIOD;
+unsigned long WAITING_TIME=CAMERA_TRIGGER_PERIOD-EXPOSURE_TIME;
 
-float NB_CYCLES_PER_EXPOSURE_TIME=4;//5.339;//1;//1.0*150/28; // this is the nb of cycles of the led during one camera frame
-float NB_CYCLES_PER_CAMERA_FRAME=1.0/EXPOSURE_TIME_FACTOR*NB_CYCLES_PER_EXPOSURE_TIME;
+// NOTE: since the delays (waiting time and exposure time) are in microseconds, we NEED to have an integer number of cycles per CAMERA frame...
+// (no pb if there is not an integer INSIDE the exposure time, but better to have it). Hence the "approximate" value:
+float approximate_NbCylclesExposureTime=6;
+unsigned long NB_CYCLES_PER_CAMERA_FRAME=1.0*approximate_NbCylclesExposureTime/EXPOSURE_TIME_FACTOR;
 
 unsigned long LED_PERIOD=1000000.0/(NB_CYCLES_PER_CAMERA_FRAME*CAMERA_FPS); //in us
+// NOTE: there is no warangy this division will be integer! PLUS it must be a multiple of 2!! mmm...
 
 unsigned int NB_FRAMES_TOGGLE_QP=1; // this is the nb of camera frames before toggling the modulation (note: there is no synchronization!)
 
 enum SignalMode {PHASE=0, QUADRATURE, TOGGLE_PHASE_QUADRATURE};
 SignalMode currentSignalMode=TOGGLE_PHASE_QUADRATURE; //NOTE: all the leds mode affected by this at the same time
 
-Trigger cameraTrigger(cameraTriggerPin,1.0*CAMERA_FPS,(unsigned int)EXPOSURE_TIME);
+//Trigger cameraTrigger(cameraTriggerPin,1.0*CAMERA_FPS,(unsigned int)EXPOSURE_TIME);
+Trigger cameraTrigger(cameraTriggerPin,(unsigned int)WAITING_TIME-27,(unsigned int)EXPOSURE_TIME);
 Flipper ledSource(ledPin, LED_PERIOD);
 Shutter lcdShutter(shutterPin, LED_PERIOD);
 
@@ -36,9 +41,9 @@
     
     ledSource.start();
     
-    // add some delay:
-    wait_us(5000);
-    lcdShutter.mixSignal(false);
+    // add some delay?
+   // wait_us(100);
+    lcdShutter.mixSignal(true);
     lcdShutter.start();
 
     // spin in a main loop. flipper will interrupt it to call flip
@@ -87,6 +92,15 @@
                 incomingValue[indexString]=0; // termination for the string
                 indexString=0;
                 cameraTrigger.setExposure(atoi(incomingValue));
+            } else if (incomingByte == 'L') { // get the LED PERIOD (to adjust the real LCD shutter)
+               // incomingValue[indexString]=0; // termination for the string
+               // indexString=0;
+                pc.printf("\n\nCAMERA FPS: %f fps\n", CAMERA_FPS);
+                pc.printf("CAMERA TRIGGER PERIOD: %i us\n", CAMERA_TRIGGER_PERIOD);
+                pc.printf("EXPOSURE TIME: %i us\n", EXPOSURE_TIME);
+                pc.printf("\nLED PERIOD: %i us\n", LED_PERIOD);
+                pc.printf("LED FREQ: %f Hz\n", 1.0/LED_PERIOD*1000000);
+                pc.printf("TOGGLE QP every: %i frames\n", NB_FRAMES_TOGGLE_QP);
             }
             
         }