sotsuron

Fork of linearMirrorMotion1017 by Hiromasa Oku

Revision:
20:8475768fc2f7
Parent:
19:8e9fe7d25b9c
Child:
21:4095a071724d
Child:
29:aa8fe9fccec8
--- a/main.cpp	Fri May 24 06:37:58 2013 +0000
+++ b/main.cpp	Fri May 31 06:32:07 2013 +0000
@@ -10,8 +10,7 @@
 DigitalIn directionPin(p15);    //green
 
 void processSerial();
-Timer timer_v;          // for shearing
-Timer timer;            //for send the speed on the serial port every 30 ms:
+Timer timer_v;          // for shearing        //for send the speed on the serial port every 30 ms:
 LocalFileSystem local("local");
 //Serial pc(USBTX, USBRX);
 
@@ -51,7 +50,7 @@
 
 ////for culculate rotary velocity --------------------------------------------------------
 
-volatile float angleIncrement = 2.0*PI / 360; // when in Sign/Magnitude mode
+volatile float angleIncrement = 2.0*PI / 1024; // when in Sign/Magnitude mode
 float radious = 700, attachSecond = 10000;
 
 // a ticker function to compute the speed periodically-------------------------------------------------------------
@@ -71,9 +70,11 @@
 void computeSpeed()
 {
     // We know exactly how much time passed since we last computed the speed, this is PERIODIC_COMPUTE in microseconds
-    angularSpeed =  1000000.0 * (float)(angle-oldAngle) / (float)(PERIODIC_COMPUTE); // in rad/sec
+    float oldspeed = angularSpeed;
+    angularSpeed = ( 1000000.0 * (float)(angle-oldAngle) / (float)(PERIODIC_COMPUTE) + oldspeed )/ 2.0; // in rad/sec
     oldAngle=angle;
     myRender.updateSpeed(angularSpeed,angle);
+    void processSerial();
 }
 
 
@@ -109,9 +110,9 @@
     oldAngle=angle=0;
 
     // Attach the external interrupt routine----------------------------------------------------------------------
-    superEncoder.attach_us(&encoderClock, attachSecond);
-    timer.reset();
-    timer.start();
+    superEncoder.attach_us(&encoderClock, 111);
+    //clockEncoderPin.rise(&encoderClock);
+    //clockEncoderPin.fall(&encoderClock);
 
     //using renderclass.cpp ----------------------------------------------------------
     //createTextPoints(textString);
@@ -131,16 +132,6 @@
     // MAIN LOOP: --------------------------------------------------------------------------------------------
     while(1) {
         if (pc.readable()>0) processSerial();
-
-        if(1/*start*/) {
-            timer_v.reset();
-            wait_us(5000);
-            /* send the speed on the serial port every 30 ms:
-            if (timer.read_ms()>300000) {
-                pc.printf("Angular Speed = %4.2f\t Cumulative Angle = %4.2f\n" , angularSpeed, angle);
-                timer.reset();
-            }*/
-        }
     }
 }
 
@@ -210,7 +201,8 @@
                 //makeBuffer();
             } else if (val == 'S') {
                 stringData[indexStringData] = 0;
-                st = atoi(stringData);
+                myRender.shearingSwitch = 1 - myRender.shearingSwitch;
+                pc.printf("shearingSwitch : %d \n" , myRender.shearingSwitch);
                 indexStringData=0;
                 //makeBuffer();
             } else if (val == 'R') {
@@ -221,6 +213,7 @@
             } else if (val == 'T') {
                 stringData[indexStringData] = 0;
                 attachSecond = atoi(stringData);
+                pc.printf("attachSecond : %d \n" , attachSecond);
                 indexStringData=0;
                 //makeBuffer();
             }