sotsuron

Fork of linearMirrorMotion1017 by Hiromasa Oku

Revision:
11:8a0fecc86705
Parent:
10:a3dd8ec4be60
Child:
12:d945fb6d4988
--- a/main.cpp	Mon Mar 25 15:54:31 2013 +0000
+++ b/main.cpp	Fri Mar 29 08:55:10 2013 +0000
@@ -3,8 +3,8 @@
 #include <vector>
 #define PI 3.141592
 
-InterruptIn clockEncoderPin(p5);
-DigitalIn directionPin(p6);
+InterruptIn clockEncoderPin(p14);
+DigitalIn directionPin(p15);
 
 void processSerial();
 Timer timer_v;
@@ -19,7 +19,7 @@
 float sint=0, cost=1;
           
 float vx = 0, vy=0;
-float theta=0, dt_betwords=200, st=400;
+float theta=0, dt_betwords=50000, st=400;
 unsigned int dt=500, ticktime=600;
 
 bool newPositionReady=false;
@@ -39,16 +39,17 @@
 
 vector<letter> libletter;   // letter library
 
-////for culculate rotary velocity --------------------------------------------------------
+////for culculate rotary velocit800000000y --------------------------------------------------------
 
 volatile float angleIncrement = 2.0*PI / 128; // when in Sign/Magnitude mode
-float radious = 100;
+float radious = 700, radious_circle = 500;
 
 // a ticker function to compute the speed periodically:
 #define PERIODIC_COMPUTE 10000 // in us
 volatile float angularSpeed = 0;
 volatile float angle=0, oldAngle=0;
 Ticker speedTimerCompute;
+Ticker superEncoder;
 
 // the external interrupt routine:
 void encoderClock() {
@@ -57,7 +58,7 @@
 
 void computeSpeed() {
     // We know exactly how much time passed since we last computed the speed, this is PERIODIC_COMPUTE in microseconds
-    angularSpeed = 1000000.0 * (angle-oldAngle) / (float)(PERIODIC_COMPUTE); // in rad/sec
+    angularSpeed = ( 1000000.0 * (float)(angle-oldAngle) / (float)(PERIODIC_COMPUTE) + angularSpeed)/2; // in rad/sec
     oldAngle=angle;
 }
    
@@ -94,7 +95,9 @@
     oldAngle=angle=0;
   
     // Attach the external interrupt routine:
-    clockEncoderPin.rise(&encoderClock);
+    //clockEncoderPin.rise(&encoderClock);
+    //clockEncoderPin.fall(&encoderClock);
+    superEncoder.attach_us(&encoderClock, radious_circle);
     timer.reset(); timer.start();
     
     // Attach the periodic computing function:
@@ -112,20 +115,15 @@
     while(1) {
     if (pc.readable()>0) processSerial();
     
-    if(start) {
+    if(1/*start*/) {
         
         timer_v.reset();
         wait_us(5000);
-        //culculating velocity -----------------------------------
-           //velocity valuable ::  sint, cost, theta, vx, vy
-        
         // send the speed on the serial port every 30 ms:
-        if (timer.read_ms()>1000) {
+        if (timer.read_ms()>30) {
             pc.printf("Angular Speed = %4.2f\t Cumulative Angle = %4.2f\n" , angularSpeed, angle);
-            sint = sin(angle);
-            cost = cos(angle);
             timer.reset();
-        }   
+        }
         
         
         // drawing ///-----------------------------------------------
@@ -134,10 +132,12 @@
             for(int j=0; j<libletter[inputletters[i]-'a'].letpoints.size(); j++) {
             
                 if (pc.readable()>0) processSerial();
+                sint = sin(angle);
+                cost = cos(angle);
                 
-                int x = -0.8*((libletter[inputletters[i]-'a'].letpoints[j].x ) - radious*angle*timer_v.read_us()/st*j/100); //this ZURE should be modifyed not by dt but Timer.
+                int x = -0.8*((libletter[inputletters[i]-'a'].letpoints[j].x ) - radious*angularSpeed*timer_v.read_us()/st*j/1000); //this ZURE should be modifyed not by dt but Timer.
                 int y = (libletter[inputletters[i]-'a'].letpoints[j].y);
-                IO.writeOutXY(X+cost*x - sint*y,Y + sint*x + cost*y);
+                IO.writeOutXY(X + radious*cost + sint*x + cost*y,Y + radious*sint - cost*x + sint*y);
                 timer_v.reset();
                 wait_us(dt);
                 IO.setRedPower(libletter[inputletters[i]-'a'].letpoints[j].laserSwitch);//on
@@ -150,7 +150,7 @@
         IO.setRGBPower(1); //off
         wait_us(10000);
         start=false;
-        
+        ////////////////////*/
         }
         
         
@@ -233,6 +233,11 @@
             radious = atoi(stringData);
             indexStringData=0;
             //makeBuffer();
+        }else if (val == 'T') {
+            stringData[indexStringData] = 0;
+            radious_circle = atoi(stringData);
+            indexStringData=0;
+            //makeBuffer();
         }
         // X value?
         /*else if (val=='x') {