just a test

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Revision:
12:0de9cd2bced5
Parent:
7:0df17f3078bc
Child:
14:0fc33a3a7b4b
--- a/rigidLoop.cpp	Thu Apr 12 05:16:48 2012 +0000
+++ b/rigidLoop.cpp	Thu Apr 12 08:38:44 2012 +0000
@@ -12,7 +12,7 @@
 
 
 // Note: this method is hidding the abstract method in the base class... and has DIFFERENT parameters than another child would have (enum type).
-void rigidLoop::createBlob(int _id, RigidLoopMode _elasticBlobMode, vector2D _initPos, vector2D _initSpeed) {
+void rigidLoop::createBlob(int _id, RigidLoopMode _elasticBlobMode, vector2Df _initPos, vector2Df _initSpeed) {
     // (1) set ID:
     identifier=_id;
 
@@ -43,7 +43,7 @@
             saccadeRadius=150;
 
             // default (initial) shape (the scafold belongs to the base class):
-            bluePrint.buildCircularScafold(saccadeRadius, vector2D(0,0), 14); //(float _radius, vector2D _pos,vector2D _vel, int _numScafoldPoints);
+            bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), 14); //(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;
@@ -52,9 +52,6 @@
             // Finally, we can create the loop (not much to do in this case, only set the central position, and some other things):
             createLoopFromScafold();
 
-            // Excursion limits (this will set the limits of motion for the rigid loop, which is given by it's central position, so we have to correct by the radius).
-            setRegionMotion(MIN_AD_MIRRORS+saccadeRadius, MIN_AD_MIRRORS+saccadeRadius, MAX_AD_MIRRORS-saccadeRadius, MAX_AD_MIRRORS-saccadeRadius);
-
             // 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:
@@ -73,7 +70,7 @@
 
             // default (initial) shape (the scafold belongs to the base class):
             saccadeRadius=35;
-            bluePrint.buildCircularScafold(saccadeRadius, vector2D(0,0), 18); //(float _radius, vector2D _pos,vector2D _vel, int _numScafoldPoints);
+            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).
             massCenter=0.01;
@@ -82,9 +79,6 @@
             // Finally, we can create the loop (not much to do in this case, only set the central position, and some other things):
             createLoopFromScafold();
 
-            // Excursion limits (this will set the limits of motion for the rigid loop, which is given by it's central position, so we have to correct by the radius).
-            setRegionMotion(MIN_AD_MIRRORS+saccadeRadius, MIN_AD_MIRRORS+saccadeRadius, MAX_AD_MIRRORS-saccadeRadius, MAX_AD_MIRRORS-saccadeRadius);
-
             slidingDirection=true; //  For contour following (will change direction when touching wall)
             speedContourFollowing=1.3*saccadeRadius;
             justSearched=false;
@@ -109,7 +103,7 @@
 
             saccadeRadius=85;
             // default (initial) shape (the scafold belongs to the base class):
-            bluePrint.buildCircularScafold(saccadeRadius, vector2D(0,0), 18); //(float _radius, vector2D _pos,vector2D _vel, int _numScafoldPoints);
+            bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), 18); //(float _radius, vector2D _pos,vector2D _vel, int _numScafoldPoints);
 
             // Numeric parameters for the simulated mechanical system:
             massCenter=0.0012;
@@ -119,9 +113,6 @@
             // Finally, we can create the loop (not much to do in this case, only set the central position, and some other things):
             createLoopFromScafold();
 
-            // Excursion limits (this will set the limits of motion for the rigid loop, which is given by it's central position, so we have to correct by the radius).
-            setRegionMotion(MIN_AD_MIRRORS+saccadeRadius, MIN_AD_MIRRORS+saccadeRadius, MAX_AD_MIRRORS-saccadeRadius, MAX_AD_MIRRORS-saccadeRadius);
-
             // 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:
@@ -132,6 +123,10 @@
     }
     
     saccadeRadius_initial=saccadeRadius; // this is for search mode for instance. 
+    
+    // Excursion limits (for all points). Tthis will set the limits of motion for the rigid loop, which is given by it's central position, so we have to correct by the radius:
+    setRegionMotion(MIN_AD_MIRRORS+saccadeRadius, MIN_AD_MIRRORS+saccadeRadius, MAX_AD_MIRRORS-saccadeRadius, MAX_AD_MIRRORS-saccadeRadius);
+
 
 }
 
@@ -157,8 +152,10 @@
     // centerMass.setInitialCondition(2047.0, 2047.0,0.0,0.0);
 }
 
-void rigidLoop::setRegionMotion(int mmix, int mmiy, int mmax, int 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);
+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);
 }
 
 
@@ -174,18 +171,24 @@
     // (III) Compute recentering vector (the "penetration vector in fact"), using "first order moment":
     // ATTENTION!! for this simple method (of "first order moment") to work, we have either to have numPoints very large, OR an EVEN quantity - so the
     // sum in the circle is 0).
-    vector2D momentVector(0,0);
+    vector2Df momentVector(0,0);
     int counterDarkZone=0; // note: for a VERY strange reason, if I put this on the laserSensingtrajectory class, the program does not work anymore!!
     for (int i = 0; i < numPoints; i++) { // note: numPoints should be EVEN
         if (displaySensingBuffer.lsdTrajectory[i].lightZone>0) { // this is, we are in a dark zone (better to integrate there, because it is normally smaller)
-            momentVector+=bluePrint.scafold[i];// note: no need to do -centerMass.pos, because the scafold is "centered" around 0
+            
+             momentVector.x+=(float)bluePrint.scafold[i].x; // note: casting is happening here automatically (unsigned short to float), but I put (float) to remember that types are different
+             momentVector.y+=(float)bluePrint.scafold[i].y;
+            
+            // We can also do the following, but ATTENTION: momentVector is of type vector2Df, and scafold[i] of type vector2Dd... 
+            // momentVector+=bluePrint.scafold[i];// note: no need to do -centerMass.pos, because the scafold is "centered" around 0
+            
             counterDarkZone++;
         }
     }
     momentVector=momentVector*(2*PI/numPoints);
     float momentNorm=momentVector.length(); // = 2.R.sin(half_angle) in the direction of the dark zone
     
-    vector2D unitTowardsLight; // this is the normed vector, pointing towards the light zone
+    vector2Df unitTowardsLight; // this is the normed vector, pointing towards the light zone
     if (momentNorm==0) {
         unitTowardsLight.set(0,0);
         recenteringVectorLoop.set(0,0);
@@ -211,9 +214,8 @@
         angleRecenteringVector=recenteringVectorLoop.angleDegHoriz();
     }
 
-
     // Now, depending on the mode of operation, we have two types of behaviour:
-    vector2D slidingVector; //( need to declare it here because a switch "jump" cannot bypass an initialization)
+    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: 
@@ -245,7 +247,7 @@
                 
                 if (justSearched) {
                     saccadeRadius=saccadeRadius_initial;
-                    bluePrint.buildCircularScafold(saccadeRadius, vector2D(0,0), numPoints);
+                    bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), numPoints);
                     justSearched=false;
                     }
                    
@@ -253,7 +255,7 @@
             } else {
                 // not on something. SEARCH MODE (or go to spot_bouncing mode?)
                 saccadeRadius+=10; if (saccadeRadius>800) saccadeRadius=saccadeRadius_initial;
-                bluePrint.buildCircularScafold(saccadeRadius, vector2D(0,0), numPoints);
+                bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), numPoints);
                 justSearched=true;
             }
 
@@ -313,8 +315,12 @@
     float cy= centerMass.pos.y;
     for (int i = 0; i < numPoints; i++) {
         // The shape is drawn by translating the scafold shape (centered on centerMass):
-        displaySensingBuffer.lsdTrajectory[i].x= int(bluePrint.scafold[i].x + cx ); // note: it should be an unsigned short!!
-        displaySensingBuffer.lsdTrajectory[i].y= int(bluePrint.scafold[i].y + cy );
+        displaySensingBuffer.lsdTrajectory[i].x= (unsigned short)(bluePrint.scafold[i].x + cx ); // note: it should be an unsigned short!!
+        displaySensingBuffer.lsdTrajectory[i].y= (unsigned short)(bluePrint.scafold[i].y + cy );
+        
+        // We can also do this, but ATTENTION: centerMass.pos is a vector2Df, and scafold[i] is a vector2Dd (typecasting?)
+        // displaySensingBuffer.lsdTrajectory[i]= bluePrint.scafold[i] + centerMass.pos;
+        
         //displaySensingBuffer.lsdTrajectory[i].color=blobColor; // perhaps per point color is not a good idea for the time being...
     }
     // global color for the whole loop: