just a test

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Revision:
30:d8af03f01cd4
Parent:
29:2fc8c12822eb
Child:
31:5f039cbddee8
--- a/rigidLoop.cpp	Wed Jun 20 03:25:49 2012 +0000
+++ b/rigidLoop.cpp	Fri Sep 21 10:02:35 2012 +0000
@@ -51,7 +51,6 @@
             // NOTE: number of points in the case of need to compute recentering vector needs to be EVEN
             bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), 16); //(float _radius, vector2D _pos,vector2D _vel, int _numScafoldPoints);
 
-            // Note: We may assume NO MASS for the center of the contour following loop. Adding mass may be interesting though (smooth motion).
             massCenter=0.01;
             dampMotionCenterMass=0.001;
             
@@ -65,6 +64,34 @@
             angleCorrectionForceLoop=0;//360.0/bluePrint.scafold.size()/2; // in DEGREES
 
             break;
+            
+        case SPOT_TRACK:
+            // Name of this kind of spot:
+            sprintf(spotName,"spot_track");
+
+            //setColor(0x07);//0x04+0x02>>i);
+            setColor(0x04);
+
+            gravity.set(0,0);
+
+            saccadeRadius=50;//+rand()%20;
+            // default (initial) shape (the scafold belongs to the base class):
+            bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), 24); //(float _radius, vector2D _pos,vector2D _vel, int _numScafoldPoints);
+
+            // Numeric parameters for the simulated mechanical system:
+            massCenter=0.001;//+0.000005*(rand()%100);
+            dampMotionCenterMass=0.001;//0.00015;//00003;
+
+            // Finally, we can create the loop (not much to do in this case, only set the central position, and some other things):
+            createLoopFromScafold();
+
+            // per-blob mirror delay (if things were well adjusted - in particular mirror waiting times, then this could be 0.
+            // But in case of unique blobs, it may be interesting to accelerate display AND correct the delay by software).
+            // Even more interesting: in case of rigid circular blob, this can be coorected using angleCorrectionForceLoop:
+            displaySensingBuffer.setDelayMirrors(3);
+            angleCorrectionForceLoop=-5;// in degrees
+
+            break;
 
         case SPOT_FOLLOWING:
 
@@ -75,7 +102,7 @@
             setColor(0x04);
 
             // default (initial) shape (the scafold belongs to the base class):
-            saccadeRadius=15;
+            saccadeRadius=23;
             bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), 18); //(float _radius, vector2D _pos,vector2D _vel, int _numScafoldPoints);
 
             // Note: We may assume NO MASS for the center of the contour following loop. Adding mass may be interesting though (smooth motion).
@@ -120,6 +147,87 @@
 
             // Finally, we can create the loop (not much to do in this case, only set the central position, and some other things):
             createLoopFromScafold();
+            
+
+            // per-blob mirror delay (if things were well adjusted - in particular mirror waiting times, then this could be 0.
+            // But in case of unique blobs, it may be interesting to accelerate display AND correct the delay by software).
+            // Even more interesting: in case of rigid circular blob, this can be coorected using angleCorrectionForceLoop:
+            displaySensingBuffer.setDelayMirrors(3);
+            angleCorrectionForceLoop=-5;// in degrees
+
+            break;
+            
+            case SPOT_PACMAN:
+            // this will define the behaviour of the "ghosts" in pacman. The spot just moves at a constant speed when there is no object. 
+            // When it collides, we use the position of the pacman (another spot) and the tangent vector to the blocking line to define the new direction of the 
+            // speed vector. 
+            
+            sprintf(spotName,"bounce_slide");
+
+            //setColor(0x07);//0x04+0x02>>i);
+            setColor(0x06); // make it green
+            
+            gravity.set(0,0);
+
+             // make it bounce slowly: 
+            dampMotionCenterMass=0.006;;
+
+            saccadeRadius=35;//+rand()%20;
+            // default (initial) shape (the scafold belongs to the base class):
+            bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), 18); //(float _radius, vector2D _pos,vector2D _vel, int _numScafoldPoints);
+
+            // Numeric parameters for the simulated mechanical system (probably not used in this kind of spot)
+            massCenter=0.0008;//+0.000005*(rand()%100);
+            dampMotionCenterMass=0.0006;//0.00015;//00003;
+            factorBouncingForce=0.0018; // this is because we will use a force on the central mass
+
+            // Finally, we can create the loop (not much to do in this case, only set the central position, and some other things):
+            createLoopFromScafold();
+
+            slidingDirection=true; //  For contour following (will change direction when touching wall)
+            speedContourFollowing=1.1*saccadeRadius;
+            justSearched=false;
+
+
+            // per-blob mirror delay (if things were well adjusted - in particular mirror waiting times, then this could be 0.
+            // But in case of unique blobs, it may be interesting to accelerate display AND correct the delay by software).
+            // Even more interesting: in case of rigid circular blob, this can be coorected using angleCorrectionForceLoop:
+            displaySensingBuffer.setDelayMirrors(3);
+            angleCorrectionForceLoop=-5;// in degrees
+
+            break;
+            
+            case SPOT_GHOST:
+            // this will define the behaviour of the "ghosts" in pacman. The spot just moves at a constant speed when there is no object. 
+            // When it collides, we use the position of the pacman (another spot) and the tangent vector to the blocking line to define the new direction of the 
+            // speed vector. 
+            
+            sprintf(spotName,"bounce_slide");
+
+            //setColor(0x07);//0x04+0x02>>i);
+            setColor(0x05); // make it BLUE
+            
+            gravity.set(0,0);
+
+             // make it bounce slowly: 
+            dampMotionCenterMass=0.006;;
+
+            saccadeRadius=35;//+rand()%20;
+            // default (initial) shape (the scafold belongs to the base class):
+            bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), 18); //(float _radius, vector2D _pos,vector2D _vel, int _numScafoldPoints);
+
+            // Numeric parameters for the simulated mechanical system (probably not used in this kind of spot)
+            massCenter=0.0008;//+0.000005*(rand()%100);
+            dampMotionCenterMass=0.0006;//0.00015;//00003;
+            factorBouncingForce=0.0018; // this is because we will use a force on the central mass
+
+            // Finally, we can create the loop (not much to do in this case, only set the central position, and some other things):
+            createLoopFromScafold();
+
+            slidingDirection=true; //  For contour following (will change direction when touching wall)
+            speedContourFollowing=1.1*saccadeRadius;
+            justSearched=false;
+
 
             // per-blob mirror delay (if things were well adjusted - in particular mirror waiting times, then this could be 0.
             // But in case of unique blobs, it may be interesting to accelerate display AND correct the delay by software).
@@ -161,7 +269,7 @@
 
             break;
             
-             case  SPOT_FOUNTAIN:
+             case  SPOT_LORENTZ_FORCE:
             // Name of this kind of spot:
             sprintf(spotName,"rigid_fountain");
 
@@ -224,7 +332,7 @@
 void rigidLoop::setRegionMotion(float mmix, float mmiy, float mmax, float mmay) { // wrapper for setWallLimits, because there is no more things to do than set this for a unique mass
    // centerMass.setWallLimits(mmix+10, mmiy+10, mmax-10, mmay-10);
    // Use the static method of the pointMass class: 
-   pointMass::setWallLimits(mmix+10, mmiy+10, mmax-10, mmay-10);
+  pointMass::setWallLimits(mmix+10, mmiy+10, mmax-10, mmay-10);
 }
 
 void rigidLoop::speedFactor(float speedfactor) {
@@ -279,7 +387,7 @@
          // Apply correction angle (delay mirrors):
         unitTowardsLight.rotateDeg(angleCorrectionForceLoop);
          
-         // Compute "recenteringVectorLoop" (in fact, the vector making the spot goes completely away form the dark zone):
+         // Compute "recenteringVectorLoop": the vector making the spot goes completely AWAY form the dark zone
          float aux=0.5*momentNorm/saccadeRadius; // note: in principle, we ALWAYS have momentNorm < 2.R, so aux < 1
          if (aux>1) aux=1.0; // can happen because of the discrete integration!
          if (counterDarkZone<=numPoints/2) { // note: numPoints HAS to be EVEN
@@ -294,10 +402,11 @@
         angleRecenteringVector=recenteringVectorLoop.angleDegHoriz();
     }
 
-    // Now, depending on the mode of operation, we have two types of behaviour:
+    // ========================  Now, depending on the mode of operation, we have different types of behaviour ========================================
+    
     vector2Df slidingVector; //( need to declare it here because a switch "jump" cannot bypass an initialization)
     switch (updateMode) {
-        
+        // ================================================================
         case SPOT_TEST: // this is just for adjusting mirror delays, checking recentering vector, etc: 
         // do nothing for the time being 
         // NOTE: it is not so easy to show the recentering vector without affecting the mirror delay BECAUSE I AM USING THE INTERRUPT METHOD for display.
@@ -307,7 +416,20 @@
         transientBlobColor=blobColor; // just the original blob color
         
         break;
-
+        // ================================================================
+        case  SPOT_TRACK:
+         centerMass.pos +=recenteringVectorLoop;
+         centerMass.posOld=centerMass.pos; // this is necessary to compute bouceOffWalls using Verlet method... (MAKE A new variable INTEGRATION METHOD?)
+         centerMass.bounceOffWalls(); // constrain position (and compute wall "hit")
+             
+            // Change color with touch? YES
+            if (displaySensingBuffer.lightTouched)  
+                 transientBlobColor=blobColor|0x02; // set green ON on the trajectory, regardless of the initial color
+            else 
+                 transientBlobColor=blobColor; // just the original blob color
+             
+            break;
+        // ================================================================
         case SPOT_FOLLOWING:
             // we need to compute the tangencial "speed":
             // vector2D slidingVector;
@@ -318,7 +440,6 @@
                 
                 // Then the final correcting vector is the sum of sliding plus a recentering vector (with a factor if one want some smothing)
                 // This is used to update the position of the central mass - WITHOUT INTEGRATION (or with it, but for the time being, we don't do that):
-      
                 centerMass.pos +=slidingVector+ ( unitTowardsLight*(-1.0*saccadeRadius) + recenteringVectorLoop )* 0.6;
                // ATTENTION!!! the REAL radius may be smaller if the mirrors are running fast!!! (hence the last factor, that is not only for "smoothing" the 
                // re-entry and avoid oscillations). 
@@ -333,8 +454,7 @@
                     bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), numPoints);
                     justSearched=false;
                     }
-                   
-
+                    
             } else {
                 // not on something. SEARCH MODE (or go to spot_bouncing mode?)
                 saccadeRadius+=30; if (saccadeRadius>800) saccadeRadius=saccadeRadius_initial;
@@ -358,7 +478,8 @@
         wallCounter++;
 
             break;
-
+            
+        // ================================================================
         case  SPOT_BOUNCING:
             // this is very simple: we need to give a force to the centralMass that is OPPOSITE to the recenteringVectorLoop vector
             centerMass.resetForce();
@@ -408,9 +529,9 @@
                  transientBlobColor=blobColor|0x02; // set green ON on the trajectory, regardless of the initial color
             else 
                  transientBlobColor=blobColor; // just the original blob color
-             
             break;
             
+            // ================================================================
             case  SPOT_AIR_HOCKEY:
             // this is very simple: we need to give a force to the centralMass that is OPPOSITE to the recenteringVectorLoop vector
             centerMass.resetForce();
@@ -461,14 +582,24 @@
             else 
                  transientBlobColor=blobColor; // just the original blob color
              
-             // In case of "air hockey mode", reset position to initial positions and speeds when the spot touches two opposites sides:
-             if ((centerMass.innerCollitionDirection.y==1)||( centerMass.innerCollitionDirection.y==-1)) 
+             // In case of "air hockey mode", reset position to initial positions and speeds when the spot touches any two opposites sides:
+             if ((centerMass.innerCollitionDirection.x==1)||( centerMass.innerCollitionDirection.x==-1)) {
+                transientBlobColor=blobColor|0x02; 
+                for (saccadeRadius=30; saccadeRadius<900 ; saccadeRadius+=10) {
+                    bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), numPoints);
+                    draw(); 
+                }
+                saccadeRadius=saccadeRadius_initial;
+                bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), numPoints);
+                // reset to central position:
                 centerMass.setInitialCondition(startCenter, startSpeed);  
-        
-             
+                transientBlobColor=blobColor;
+                }
             break;
             
-            case  SPOT_FOUNTAIN:
+           
+           // ================================================================ 
+            case  SPOT_LORENTZ_FORCE:
             // this is very simple: we need to give a force to the centralMass that is OPPOSITE to the recenteringVectorLoop vector
             centerMass.resetForce();
 
@@ -517,9 +648,8 @@
             // In case of "fountain mode", reset position to initial positions and speeds, or change gravity sign:
            //  if (blobWallCollision) centerMass.setInitialCondition(startCenter, startSpeed);  
              if (blobWallCollision) slidingDirection=!slidingDirection;
-            
-            
             break;
+            // ================================================================
     }
     
 }