Takashi Asano / Mbed 2 deprecated linearMirrorMotion1017

Fork of linearMirrorMotion1017 by Hiromasa Oku

Files at this revision

API Documentation at this revision

Comitter:
takapiasano
Date:
Fri Jun 28 02:30:51 2013 +0000
Parent:
21:4095a071724d
Child:
23:ce375ac0ddfe
Child:
24:ab74d2018e6c
Commit message:
horizontal demo

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
--- a/main.cpp	Fri Jun 07 05:01:40 2013 +0000
+++ b/main.cpp	Fri Jun 28 02:30:51 2013 +0000
@@ -50,10 +50,10 @@
 
 ////for culculate rotary velocity --------------------------------------------------------
 int radious = 700, attachSecond = 500;
-/*volatile float*/int  angleIncrement = 1 ;//2.0*PI / 2500; // when in Sign/Magnitude mode
+/*volatile float*/ int  angleIncrement = 1;//2.0*PI / 2500;// when in Sign/Magnitude mode
 
 // a ticker function to compute the speed periodically-------------------------------------------------------------
-#define PERIODIC_COMPUTE 10000 // in us
+#define PERIODIC_COMPUTE 5000 // in us
 volatile float angularSpeed = 0;
 /*volatile float*/ int angle=0, oldAngle=0;
 Ticker speedTimerCompute;
@@ -72,9 +72,8 @@
     float oldspeed = angularSpeed;
     angularSpeed = ( 1000000.0 * (float)(angle-oldAngle) / (float)(PERIODIC_COMPUTE) + oldspeed )/ 2.0; // in rad/sec
     oldAngle=angle;
-    myRender.updateSpeed(angularSpeed,angle);
+    myRender.updateSpeed(angularSpeed,angle, ((directionPin)-0.5)*2*angleIncrement*100.0/attachSecond, 0);
     void processSerial();
-    
 }
 
 
@@ -184,7 +183,7 @@
                 //if( (Y-beforeY) > 5){
                 //vy = ((float)Y-(float)beforeY) / (float)timer_v.read_us() *1000;
                 
-                myRender.updateSpeed(vx, vy);
+                //myRender.updateSpeed(vx, vy);
                 
                
             }
--- a/renderclass.cpp	Fri Jun 07 05:01:40 2013 +0000
+++ b/renderclass.cpp	Fri Jun 28 02:30:51 2013 +0000
@@ -9,15 +9,15 @@
 
 inline void render::shearing(point2dl& dataBefore)
 {
-    dataBefore.x = dataBefore.x - speed *speedTimer.read_us()/1000000 ;//- speed * cos(angle+PI/2)*speedTimer.read_us()/800;
-    dataBefore.y = dataBefore.y ;//- speed * sin(angle+PI/2)*speedTimer.read_us()/800;
+    dataBefore.x = dataBefore.x - vx * speedTimer.read_us()/100; //2000000;//dataBefore.x - speed *speedTimer.read_us()/1000000 ;//- speed * cos(angle+PI/2)*speedTimer.read_us()/800;
+    dataBefore.y = dataBefore.y - vy * speedTimer.read_us()/2000000;//dataBefore.y ;//- speed * sin(angle+PI/2)*speedTimer.read_us()/800;
 }
 
 inline void render::rotation(point2dl& dataBefore)
 {
     int x=dataBefore.x;
-    dataBefore.x = x + (int)angle % (2 * CENTER_AD_MIRROR_X) + CENTER_AD_MIRROR_X;//1800 * cos(angle) + sin(angle)*x - cos(angle)*dataBefore.y;
-    dataBefore.y = -dataBefore.y;//1800 * sin(angle) - cos(angle)*x - sin(angle)*dataBefore.y;
+    dataBefore.x = x + abs((int)angle) % (2 * (CENTER_AD_MIRROR_X-200)) -  CENTER_AD_MIRROR_X+200;//x + (CENTER_AD_MIRROR_X-200) * cos(angle);//radious * cos(angle) + sin(angle)*x - cos(angle)*dataBefore.y;//
+    dataBefore.y = -dataBefore.y;//radious * sin(angle) - cos(angle)*x - sin(angle)*dataBefore.y;//
     
 }
 //----------------------------------------------------------------------------------
@@ -50,15 +50,19 @@
     currentLetters=0;
     currentPoints=0;
     shearingSwitch = 1;
-
+    radious = 1800;
 }
 
 
-void render::updateSpeed(float gspeed, float gangle)
+void render::updateSpeed(float gspeed, float gangle, float vvx, float vvy)
 {
     speed = gspeed;
     angle = gangle;
 
+    vx = vvx;//gspeed * radious * cos(angle+PI/2);
+    vy = vvy;//gspeed * radious * sin(angle+PI/2);
+
+
     //speed=sqrt(vx*vx+vy*vy);//*factorSpeed;
     //angle=atan2(vy,vx);
 }
@@ -70,6 +74,8 @@
         transform(drawPoint);               // transform it with the current speed and angle
         IO.writeOutXY(CENTER_AD_MIRROR_X + (int)drawPoint.x , CENTER_AD_MIRROR_Y + (int)drawPoint.y);
         
+        
+        
         ////laser switch
         if(currentPoints>0) IO.setRedPower(translated[currentLetters].letpoints[currentPoints-1].laserSwitch);
         else                IO.setRedPower(0);
@@ -92,14 +98,12 @@
         if(currentLetters >= translated.size()) {
             currentLetters = 0;
             currentPoints = 0;
-            renderTimer.detach();
+            //renderTimer.detach();
             //wait_us(RENDER_INTERVAL);
             IO.setRedPower(0);
             //wait_us(RENDER_INTERVAL*20);
-            renderTimer.attach_us(this, &render::draw,RENDER_INTERVAL);
+            //renderTimer.attach_us(this, &render::draw,RENDER_INTERVAL);
             speedTimer.reset();
-            
-            //stopcounter = -200;
         }
     }
 }
--- a/renderclass.h	Fri Jun 07 05:01:40 2013 +0000
+++ b/renderclass.h	Fri Jun 28 02:30:51 2013 +0000
@@ -24,7 +24,7 @@
     void transform(point2dl& mypoint);
     void shearing(point2dl& dataBefore);
     void rotation(point2dl& dataBefore);
-    void updateSpeed(float vx, float vy);
+    void updateSpeed(float gspeed, float gangle, float vvx, float vvy);
 
     int shearingSwitch;
     
@@ -40,5 +40,8 @@
     
     float speed;
     float angle;
+    float vx;
+    float vy;
+    int radious;
     
 };
\ No newline at end of file