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

Committer:
mbedalvaro
Date:
Mon Jul 14 09:35:12 2014 +0000
Revision:
0:4b5874bff9bb
Child:
1:4284f27d638d
this works very well. A VERY small jitter remains... no idea why. Also, not very happy with all the static member variables... looks like they just needed to be globals...

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedalvaro 0:4b5874bff9bb 1 #include "mbed.h"
mbedalvaro 0:4b5874bff9bb 2 #include "Flipper.h"
mbedalvaro 0:4b5874bff9bb 3
mbedalvaro 0:4b5874bff9bb 4 // The following parameters can be changed by serial commands:
mbedalvaro 0:4b5874bff9bb 5 // 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
mbedalvaro 0:4b5874bff9bb 6 // for 28.09, then the of cycles per frame is 150/28.09=5.339
mbedalvaro 0:4b5874bff9bb 7 float CAMERA_FPS=15;//28.0915;//28.09;
mbedalvaro 0:4b5874bff9bb 8 unsigned long CAMERA_TRIGGER_PERIOD=1000000.0/CAMERA_FPS;
mbedalvaro 0:4b5874bff9bb 9 float EXPOSURE_TIME_FACTOR=1.0/4;
mbedalvaro 0:4b5874bff9bb 10 unsigned long EXPOSURE_TIME=EXPOSURE_TIME_FACTOR*CAMERA_TRIGGER_PERIOD;
mbedalvaro 0:4b5874bff9bb 11
mbedalvaro 0:4b5874bff9bb 12 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
mbedalvaro 0:4b5874bff9bb 13 float NB_CYCLES_PER_CAMERA_FRAME=1.0/EXPOSURE_TIME_FACTOR*NB_CYCLES_PER_EXPOSURE_TIME;
mbedalvaro 0:4b5874bff9bb 14
mbedalvaro 0:4b5874bff9bb 15 unsigned long LED_PERIOD=1000000.0/(NB_CYCLES_PER_CAMERA_FRAME*CAMERA_FPS); //in us
mbedalvaro 0:4b5874bff9bb 16
mbedalvaro 0:4b5874bff9bb 17 unsigned int NB_FRAMES_TOGGLE_QP=1; // this is the nb of camera frames before toggling the modulation (note: there is no synchronization!)
mbedalvaro 0:4b5874bff9bb 18
mbedalvaro 0:4b5874bff9bb 19 enum SignalMode {PHASE=0, QUADRATURE, TOGGLE_PHASE_QUADRATURE};
mbedalvaro 0:4b5874bff9bb 20 SignalMode currentSignalMode=TOGGLE_PHASE_QUADRATURE; //NOTE: all the leds mode affected by this at the same time
mbedalvaro 0:4b5874bff9bb 21
mbedalvaro 0:4b5874bff9bb 22 Trigger cameraTrigger(cameraTriggerPin,1.0*CAMERA_FPS,(unsigned int)EXPOSURE_TIME);
mbedalvaro 0:4b5874bff9bb 23 Flipper ledSource(ledPin, LED_PERIOD);
mbedalvaro 0:4b5874bff9bb 24 Shutter lcdShutter(shutterPin, LED_PERIOD);
mbedalvaro 0:4b5874bff9bb 25
mbedalvaro 0:4b5874bff9bb 26 Serial pc(USBTX, USBRX); // tx, rx
mbedalvaro 0:4b5874bff9bb 27 void processSerial();
mbedalvaro 0:4b5874bff9bb 28
mbedalvaro 0:4b5874bff9bb 29 int main()
mbedalvaro 0:4b5874bff9bb 30 {
mbedalvaro 0:4b5874bff9bb 31 pc.baud(9600);
mbedalvaro 0:4b5874bff9bb 32
mbedalvaro 0:4b5874bff9bb 33
mbedalvaro 0:4b5874bff9bb 34 cameraTrigger.setQPToggleFrames(NB_FRAMES_TOGGLE_QP);
mbedalvaro 0:4b5874bff9bb 35 cameraTrigger.start();
mbedalvaro 0:4b5874bff9bb 36
mbedalvaro 0:4b5874bff9bb 37 ledSource.start();
mbedalvaro 0:4b5874bff9bb 38
mbedalvaro 0:4b5874bff9bb 39 // add some delay:
mbedalvaro 0:4b5874bff9bb 40 wait_us(5000);
mbedalvaro 0:4b5874bff9bb 41 lcdShutter.mixSignal(false);
mbedalvaro 0:4b5874bff9bb 42 lcdShutter.start();
mbedalvaro 0:4b5874bff9bb 43
mbedalvaro 0:4b5874bff9bb 44 // spin in a main loop. flipper will interrupt it to call flip
mbedalvaro 0:4b5874bff9bb 45 while(1) {
mbedalvaro 0:4b5874bff9bb 46 processSerial();
mbedalvaro 0:4b5874bff9bb 47 }
mbedalvaro 0:4b5874bff9bb 48 }
mbedalvaro 0:4b5874bff9bb 49
mbedalvaro 0:4b5874bff9bb 50 // String to store ALPHANUMERIC DATA (i.e., integers, floating point numbers, unsigned ints, etc represented as DEC) sent wirelessly:
mbedalvaro 0:4b5874bff9bb 51 char incomingValue[5];
mbedalvaro 0:4b5874bff9bb 52 char incomingByte;
mbedalvaro 0:4b5874bff9bb 53 char indexString=0;
mbedalvaro 0:4b5874bff9bb 54
mbedalvaro 0:4b5874bff9bb 55 void processSerial()
mbedalvaro 0:4b5874bff9bb 56 {
mbedalvaro 0:4b5874bff9bb 57
mbedalvaro 0:4b5874bff9bb 58 while(pc.readable()>0) {
mbedalvaro 0:4b5874bff9bb 59 char incomingByte =pc.getc();
mbedalvaro 0:4b5874bff9bb 60
mbedalvaro 0:4b5874bff9bb 61 if (incomingByte >='0' && incomingByte <='9') {
mbedalvaro 0:4b5874bff9bb 62 incomingValue[indexString]=incomingByte;
mbedalvaro 0:4b5874bff9bb 63 indexString++;
mbedalvaro 0:4b5874bff9bb 64 } else { // check for terminator (i.e. "CONTROL CODES"):
mbedalvaro 0:4b5874bff9bb 65 if (incomingByte=='P') {
mbedalvaro 0:4b5874bff9bb 66 currentSignalMode=PHASE;
mbedalvaro 0:4b5874bff9bb 67 cameraTrigger.toggleQP(false);
mbedalvaro 0:4b5874bff9bb 68 ledSource.flip();
mbedalvaro 0:4b5874bff9bb 69 } else if (incomingByte=='Q') {
mbedalvaro 0:4b5874bff9bb 70 currentSignalMode=QUADRATURE;
mbedalvaro 0:4b5874bff9bb 71 cameraTrigger.toggleQP(false);
mbedalvaro 0:4b5874bff9bb 72 ledSource.flip();
mbedalvaro 0:4b5874bff9bb 73 } else if (incomingByte=='T') {
mbedalvaro 0:4b5874bff9bb 74 currentSignalMode=TOGGLE_PHASE_QUADRATURE; // periodic toogling (every a TOGGLE_QP_PERIOD)
mbedalvaro 0:4b5874bff9bb 75 cameraTrigger.toggleQP(true);
mbedalvaro 0:4b5874bff9bb 76 } else if (incomingByte=='s') { // simulated shutter OFF
mbedalvaro 0:4b5874bff9bb 77 lcdShutter.mixSignal(false);
mbedalvaro 0:4b5874bff9bb 78 } else if (incomingByte=='S') { // simulated shutter ON
mbedalvaro 0:4b5874bff9bb 79 lcdShutter.mixSignal(true);
mbedalvaro 0:4b5874bff9bb 80
mbedalvaro 0:4b5874bff9bb 81 // CAMERA PARAMETERS:
mbedalvaro 0:4b5874bff9bb 82 } else if (incomingByte == 'F') { // camera frame rate
mbedalvaro 0:4b5874bff9bb 83 incomingValue[indexString]=0; // termination for the string
mbedalvaro 0:4b5874bff9bb 84 indexString=0;
mbedalvaro 0:4b5874bff9bb 85 cameraTrigger.setFrameRate(atoi(incomingValue));
mbedalvaro 0:4b5874bff9bb 86 } else if (incomingByte == 'E') { // control Exposure time:
mbedalvaro 0:4b5874bff9bb 87 incomingValue[indexString]=0; // termination for the string
mbedalvaro 0:4b5874bff9bb 88 indexString=0;
mbedalvaro 0:4b5874bff9bb 89 cameraTrigger.setExposure(atoi(incomingValue));
mbedalvaro 0:4b5874bff9bb 90 }
mbedalvaro 0:4b5874bff9bb 91
mbedalvaro 0:4b5874bff9bb 92 }
mbedalvaro 0:4b5874bff9bb 93 }
mbedalvaro 0:4b5874bff9bb 94 }