sotsuron

Fork of linearMirrorMotion1017 by Hiromasa Oku

Revision:
6:a82917b3b1aa
Parent:
5:e02cd57242c7
Child:
7:64b313c58420
diff -r e02cd57242c7 -r a82917b3b1aa main.cpp
--- a/main.cpp	Thu Nov 29 08:05:10 2012 +0000
+++ b/main.cpp	Wed Dec 05 08:04:25 2012 +0000
@@ -21,14 +21,18 @@
 int startX = CENTER_AD_MIRROR_X;
 int startY = CENTER_AD_MIRROR_Y;
 
+float sint=0, cost=1;
+          
 float vx = 0, vy=0, omegaX=0, omegaY=0; 
-float theta=0,scale=700;
+float theta=0,scale=7000;
 unsigned int dt=500, timecounter = 0;
 
 bool newPositionReady=false;
 unsigned int counter=0;
 vector<char> inputletters;
 
+bool start=false;
+
 struct point2d {
     int x,y;
 };
@@ -110,26 +114,33 @@
     timer.start();
     // MAIN LOOP: --------------------------------------------------------------------------------------------
     while(1) {
-        if (pc.readable()>0) processSerial();
-        
-        
-        float sint = sin(theta);
-        float cost = cos(theta);
-
+    if (pc.readable()>0) processSerial();
+    
+    if(start) {
+        wait_us(5000);
         for(int i=0; i<inputletters.size(); i++) {
-            if (pc.readable()>0) processSerial();
-            wait(0.1);
+    
+            
             for(int j=0; j<libletter[inputletters[i]-'a'].letpoints.size(); j++) {
-                int x = 0.8*scale/1000*(libletter[inputletters[i]-'a'].letpoints[j].x - vx*dt/1000*j); //+500*(i-inputletters.size()/2.0));
-                int y = -scale/1000*(libletter[inputletters[i]-'a'].letpoints[j].y);
-                IO.writeOutXY(X+cost*x + sint*y,Y-sint*x + cost*y);
+                if (pc.readable()>0) processSerial();
+                
+                int x = 0.8*(libletter[inputletters[i]-'a'].letpoints[j].x );//- sqrtf(fabs(vx*vy))*dt/10000*j); //+500*(i-inputletters.size()/2.0));
+                int y = (libletter[inputletters[i]-'a'].letpoints[j].y);
+                IO.writeOutXY(X+cost*x - sint*y,Y + sint*x + cost*y);
                 wait_us(dt);
-                IO.setRGBPower(0);//on
+                IO.setRGBPower(3);//on
             }
-            IO.setRGBPower(1);
-            wait(0.01);
+            IO.setRGBPower(1); //off
+            wait_us(scale);//10*dt);
+
         }
-
+        
+        IO.setRGBPower(1); //off
+        wait_us(10000);
+        start=false;
+        
+        }
+        
         /*for(int j=0; j<buf.size()/2; j++) {
             if ( (buf[j*2] == 222) && (buf[j*2+1] == 222)){
                 IO.setRGBPower(1);
@@ -153,9 +164,8 @@
             timecounter += dt;
             if(timecounter >= T) timecounter = 0; 
         }*/
-        buf2.clear();
-        IO.setRGBPower(1); //off
-        wait(0.02);
+        //buf2.clear();
+        //wait(0.02);
 
     }
 }
@@ -169,6 +179,7 @@
 void processSerial()
 {
 
+    start=true;
     while(pc.readable()>0) {
 
         char val =pc.getc();
@@ -192,11 +203,12 @@
             stringData[indexStringData] = 0;
             X = atoi(stringData);
             indexStringData=0;
-            timer.stop();
-            vx = ((float)X-(float)beforeX) / timer.read();
+            //timer.stop();
+            vx = ((float)X-(float)beforeX) / (float)timer.read_ms();
             //newSpeedReady = true;
-            theta=atan2(vx,vy);
-            timer.start();
+            //theta=atan2(vy,vx);
+            //timer.reset();
+            //timer.start();
         }
 
         else if (val == 'Y') {
@@ -204,11 +216,20 @@
             stringData[indexStringData] = 0;
             Y = atoi(stringData);
             indexStringData=0;
-            timer.stop();
+            //timer.stop();
             //newSpeedReady = true;
-            vx = ((float)Y-(float)beforeY) / timer.read();
-            theta=atan2(vx,vy);
+            //if( (Y-beforeY) > 5){ 
+            vy = ((float)Y-(float)beforeY) / (float)timer.read_ms();
+            theta=atan2(vy,vx);
+            timer.reset();
             timer.start();
+            sint = -sin(theta);//cos(theta);
+            cost = -cos(theta);//-sin(theta);  
+            //}
+            //if (cost > 0){
+            //sint = -sint;//cos(thet      
+            //cost = -cost;//-sin(theta);  
+            //}
         }
 
         else if (val == 'T') {
@@ -256,5 +277,5 @@
         }
         */
 
-    }
+   }
 }
\ No newline at end of file