just a test

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Revision:
47:2312a8dc9658
Parent:
46:90516893793a
--- a/main.cpp	Tue Apr 01 11:34:37 2014 +0000
+++ b/main.cpp	Tue Apr 01 14:57:37 2014 +0000
@@ -13,7 +13,7 @@
 DigitalOut myled(LED1);
 DigitalOut myled2(LED2);
 DigitalOut myled3(LED3);
-
+ DigitalOut ledSwitchOne(LED_SWITCH_ONE); 
 
 // To test the time it takes for executing one loop in the main program:
 //#define LOOPTIMECOMPUTE
@@ -21,6 +21,13 @@
 // To get serial commands (for debug, or other things using a Terminal - for instance, a laser scan)
 #define SERIAL_COMMANDS
 
+ int renderFraction=1;// when 1, the blob needs to be rendered completely before update; 2 means half of it, etc. 0 means render all the time. 
+
+// NEW (1.4.2014): change modes by switch for fast demos:
+int totalNumberDemos=13;
+int currentDemoMode=0;
+void changeMode(int mode);
+
 //----------  ETHERNET / OSC related (in the future, put somewhere else...): -------------------------------------------
 // mbed IP address (server):
 #ifdef DHCP
@@ -64,8 +71,6 @@
 Timer measureReadPeriod; // timer for reading hardare or communication data (I will read in ms)
 #define periodReadingData 30
 
- int renderFraction=1;// when 1, the blob needs to be rendered completely before update; 2 means half of it, etc. 0 means render all the time. 
-
 //Timer measureUpdatePeriod;
 
 
@@ -76,6 +81,7 @@
 
     // Initialize the hardware (laser powers, positions...):
     IO.init();
+    ledSwitchOne=0;
 
     // -------------------------------
     // Set the Ethernet port:
@@ -111,7 +117,7 @@
 
     // initialize with the desired blob configuration:
 
-    blobconf.initConfig(ONE_ELASTIC_FOLLOWING);
+  //  blobconf.initConfig(ONE_ELASTIC_FOLLOWING);
        
     // Tested modes:
    // blobconf.clearConfig();
@@ -127,7 +133,7 @@
  //blobconf.addOneRigidLoopTest();
 
 // START WITH TWO FOLLOWING SPOTS (exhibition Tokyo Design Week):
- // blobconf.initConfig(FOLLOWING_SPOTS, 2); // value is the nb of spots instantiated
+  blobconf.initConfig(FOLLOWING_SPOTS, 1); // value is the nb of spots instantiated
 // Make them of different color:
  //blobconf.blobArray[0]->setBlueColor(1);
  //blobconf.blobArray[1]->setGreenColor(1);
@@ -221,21 +227,31 @@
         //(1) Check for change of threshold mode button (switch one): 
         //!!! ATTENTION: this does not work very well to say the truth: bouncing+adc settings problems... better use a TWO STATE SWITCH:
        bool stateswitch;
-       // if (IO.switchOneCheck(stateswitch)) {
+       if (IO.switchOneCheck(stateswitch)) {
             //if (stateswitch) pc.printf("Setting AUTO threshold mode\n"); else pc.printf("Setting FIXED threshold mode\n"); 
        //     for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.setThresholdMode((stateswitch? 1 : 0));
-       // }
+            currentDemoMode=(currentDemoMode+1)%totalNumberDemos;
+           // ledSwitchOne=(stateswitch? 1 :0); // this switch has a built-in led
+           ledSwitchOne=1; wait_ms(500) ; ledSwitchOne=0; 
+            changeMode(currentDemoMode);
+             blobconf.allResume();
+       }
        if (IO.twoStateSwitchCheck(stateswitch)) { // if there is a change...
            for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.setThresholdMode((stateswitch? 1 : 0));
            }
        
         //(2) in case the the second switch was pressed, check the current pot value and update the fixed threshold (regardless of the threshold mode)
        // NOTE: using the potentiometer FAILS because I cannot properly switch back and forth between ADC modes (burst and normal)
-       //if (IO.switchTwoCheck(stateswitch)) { 
+       if (IO.switchTwoCheck(stateswitch)) { 
+        timerForRendering.detach();
+          IO.showLimitsMirrors(5); // in seconds
+          timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL); 
+          
        //    IO.updatePotValue(); 
        //    for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.setFixedThreshold(IO.potValue);
        //    pc.printf("Got :%d\n", IO.potValue);
-       // }
+        }
+        
         if (rotaryEncoder1.CheckNew()) {
             for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.setFixedThreshold(rotaryEncoder1.Get());
             //pc.printf("Fixed Threshold :%d\n", rotaryEncoder1.Get());
@@ -658,7 +674,7 @@
       }
     }
     
-     else if (!strcmp( address[0], "adjustRenderFraction" ) ) {
+     else if (!strcmp( address[0], "adjustRenderFraction" ) ) { // for all spots...
       int value=data[0]; // value 100 means no change of speed. 200 is twice as fast, 50 is half as fast. 
       if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data)     
          renderFraction=value;
@@ -746,8 +762,9 @@
       }
     } 
     
-    else if (!strcmp( address[0], "showParameters" ) ) {  
-        blobconf.showParameters();
+    else if (!strcmp( address[0], "printParameters" ) ) {  
+        pc.printf("Fraction display for the config: %d\n", renderFraction);
+        blobconf.printParameters();
     } 
     
  // ===================== SEND DATA MODES =======================
@@ -930,6 +947,105 @@
     }
 }
 
+void changeMode(int mode) {
+
+    strcpy(address[0],"");
+   strcpy(address[1],"");
+   data[0]=-1;
+   data[1]=-1;
+
+switch(mode) {
+  case 0: 
+   strcpy(address[0],"spot_following");
+   data[0]=1;
+   interpretCommand();
+ break;
+ case 1:
+    strcpy(address[0],"spot_following");
+   data[0]=2;
+   interpretCommand();
+ break;
+ case 2:
+  strcpy(address[0],"spot_bouncing");
+   data[0]=1;
+   interpretCommand();
+ break;
+ case 3:
+  strcpy(address[0],"spot_bouncing");
+   data[0]=4;
+   interpretCommand();
+ break;
+ case 4:
+ strcpy(address[0],"spot_lorentz");
+   data[0]=1;
+   interpretCommand();
+ break;
+ case 5:
+ strcpy(address[0],"spot_lorentz");
+   data[0]=2;
+   interpretCommand();
+ break;
+ case 6:
+  strcpy(address[0],"rain_mode");
+  data[0]=2;
+  interpretCommand();
+ break;
+ case 7:
+  strcpy(address[0],"rain_mode");
+  data[0]=5;
+  interpretCommand();
+ break;
+case 8:
+ strcpy(address[0],"air_hockey");
+   data[0]=1;
+   interpretCommand();
+ break;
+   case 9:
+  strcpy(address[0],"spot_tracking");
+  data[0]=1;
+  interpretCommand();
+   // here, let's make the min contrast smaller, for finger tracking:
+   strcpy(address[0],"adjustContrast");
+  data[0]=120;
+  interpretCommand();
+ break;
+ case 10:
+strcpy(address[0],"elastic_mouth");
+interpretCommand();
+ break;
+ case 11:
+ strcpy(address[0],"elastic_following");
+ interpretCommand();
+ break;
+ case 12:
+ strcpy(address[0],"elastic_mouth_small");
+ interpretCommand();
+ break;
+ //case 9:
+ //strcpy(address[0],"pac_man");
+ //interpretCommand();
+ //break;
+ //case 10:
+ //  strcpy(address[0],"circular_pong");
+ //  data[0]=3;
+ //  interpretCommand();
+ //break;
+ // case 10:
+ // strcpy(address[0],"vertical_pinball");
+ //  data[0]=2;
+ //  interpretCommand();
+ //pbreak;
+ //case 11:
+ //strcpy(address[0],"fish_net");
+  // data[0]=3;
+  // interpretCommand();
+ //break;
+ 
+ }
+ 
+ }
+ 
+
 
 // ================ MISCELANEA