this version 10/17

Dependencies:   mbed

Fork of linearMirrorMotion by Alvaro Cassinelli

Files at this revision

API Documentation at this revision

Comitter:
hiromasaoku
Date:
Fri May 31 06:32:07 2013 +0000
Parent:
19:8e9fe7d25b9c
Commit message:
for sharing

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
renderclass.cpp Show annotated file Show diff for this revision Revisions of this file
renderclass.h Show annotated file Show diff for this revision Revisions of this file
diff -r 8e9fe7d25b9c -r 8475768fc2f7 main.cpp
--- 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();
             }
diff -r 8e9fe7d25b9c -r 8475768fc2f7 renderclass.cpp
--- a/renderclass.cpp	Fri May 24 06:37:58 2013 +0000
+++ b/renderclass.cpp	Fri May 31 06:32:07 2013 +0000
@@ -9,21 +9,21 @@
 
 inline void render::shearing(point2dl& dataBefore)
 {
-    dataBefore.x = dataBefore.x ;//+ speed * cos(angle) * timer_v.read_us()/st/1000;
-    dataBefore.y = dataBefore.y ;//+ speed * sin(angle) * timer_v.read_us()/st/1000;
-
+    dataBefore.x = dataBefore.x - speed * cos(angle+PI/2)*speedTimer.read_us()/400;
+    dataBefore.y = dataBefore.y - speed * sin(angle+PI/2)*speedTimer.read_us()/400;
 }
 
 inline void render::rotation(point2dl& dataBefore)
 {
     int x=dataBefore.x;
-    dataBefore.x = cos(angle)*x - sin(angle)*dataBefore.y;
-    dataBefore.y = sin(angle)*x + cos(angle)*dataBefore.y;
+    dataBefore.x = 1800 * cos(angle) + sin(angle)*x - cos(angle)*dataBefore.y;
+    dataBefore.y = 1800 * sin(angle) - cos(angle)*x - sin(angle)*dataBefore.y;
 }
 //----------------------------------------------------------------------------------
 
 void render::startRender()
 {
+    speedTimer.start();
     renderTimer.attach_us(this, &render::draw,RENDER_INTERVAL);
     pc.printf("render started!\n");
 }
@@ -43,12 +43,13 @@
     //for(int i=0; i!=(*ptext).size(); i++){
     for(std::vector<letter>::iterator itr = (*ptext).begin(); itr != (*ptext).end(); ++itr) {
         translated.push_back(*itr);
-         pc.printf("moving...." );
     }                                            //copy the liblary to the buffer.
     
     
     currentLetters=0;
     currentPoints=0;
+    shearingSwitch = 1;
+
 }
 
 
@@ -59,40 +60,53 @@
     //speed=sqrt(vx*vx+vy*vy);//*factorSpeed;
     //angle=atan2(vy,vx);
 }
-float t=0;
+
+int stopcounter=100;
+
 void render::draw()
 {
     if(translated.size()>0){
+    if(stopcounter == 99) speedTimer.reset();
+    if(stopcounter==100){
+    
     point2dl drawPoint=translated[currentLetters].letpoints[currentPoints];
     transform(drawPoint); // transform it with the current speed and angle
-    pc.printf("%d, %d, %d \n" , (int)drawPoint.x, (int)drawPoint.y, (int)drawPoint.laserSwitch);
     //IO.setRedPower(drawPoint.laserSwitch);
-    IO.writeOutXY(CENTER_AD_MIRROR_X+ 4*(int)drawPoint.x , CENTER_AD_MIRROR_Y - 4*(int)drawPoint.y);
+    IO.writeOutXY(CENTER_AD_MIRROR_X + (int)drawPoint.x , CENTER_AD_MIRROR_Y + (int)drawPoint.y);
     
     
     if(currentPoints>0) IO.setRedPower(translated[currentLetters].letpoints[currentPoints-1].laserSwitch);
-    else                IO.setRedPower(0);              ///laserswitch txt library needs to rewrite..........?\(>o<)/?
+    else                IO.setRedPower(0);             
 
     currentPoints++;
+    }
+    else stopcounter++;
     
     if(currentPoints >= translated[currentLetters].letpoints.size() ) {
+        if(stopcounter == 100) stopcounter = 0;
+        else if(stopcounter == 0){
+        renderTimer.detach();
+        }
+        //wait_us(RENDER_INTERVAL);
+        else if(stopcounter == 1){
+        IO.setRedPower(0);
+        //wait_us(RENDER_INTERVAL);
         currentLetters++;
         currentPoints = 0;
-        
-        renderTimer.detach();
-        wait_us(RENDER_INTERVAL);
-        IO.setRedPower(0);
-        wait_us(RENDER_INTERVAL*40);
         renderTimer.attach_us(this, &render::draw,RENDER_INTERVAL);
+        speedTimer.reset();
+        }
     }
     if(currentLetters >= translated.size()) {
         currentLetters = 0;
         currentPoints = 0;
         renderTimer.detach();
-        wait_us(RENDER_INTERVAL);
+        //wait_us(RENDER_INTERVAL);
         IO.setRedPower(0);
-        wait_us(RENDER_INTERVAL*20);
+        //wait_us(RENDER_INTERVAL*200);
         renderTimer.attach_us(this, &render::draw,RENDER_INTERVAL);
+        speedTimer.reset();
+        stopcounter = -200;
     }
     }
 }
@@ -100,26 +114,6 @@
 void render::transform(point2dl& mypoint)
 {
     rotation(mypoint);
-    shearing(mypoint);
+    if(shearingSwitch == 1) shearing(mypoint);
 }
 
-/*
-void render::translating(float speed, float angle)  //DO when get the speed and angle data.
-{
-    for (int i = 0; i > 10;  i++) {
-        int j=0;
-        if(currentPoints + j > (*ptext)[currentLetters].letpoints.size()) {
-            currentPoints = 0;
-            currentLetters++;
-            j=0;
-        }
-        if(currentLetters > (*ptext).size()) break;
-
-        point2dl bufferRotate = rotation((*ptext)[currentLetters].letpoints[currentPoints]);
-        point2dl bufferShear = shearing(bufferRotate);
-
-        translated[currentLetters].letpoints[currentPoints] = bufferShear;
-
-        j++;
-    }
-}*/
\ No newline at end of file
diff -r 8e9fe7d25b9c -r 8475768fc2f7 renderclass.h
--- a/renderclass.h	Fri May 24 06:37:58 2013 +0000
+++ b/renderclass.h	Fri May 31 06:32:07 2013 +0000
@@ -2,7 +2,7 @@
 #include <vector>
 #define PI 3.14159
 
-#define RENDER_INTERVAL 1000// in microseconds
+#define RENDER_INTERVAL 700// in microseconds
 
 struct point2dl {
     int x,y;
@@ -25,6 +25,8 @@
     void shearing(point2dl& dataBefore);
     void rotation(point2dl& dataBefore);
     void updateSpeed(float vx, float vy);
+
+    int shearingSwitch;
     
     private:
     vector<letter> *ptext;
@@ -34,7 +36,9 @@
     point2dl drawPoint;
     
     Ticker renderTimer;
+    Timer   speedTimer;
     
     float speed;
     float angle;
+    
 };
\ No newline at end of file