Takashi Asano
/
linearMirrorMotion1017
sotsuron
Fork of linearMirrorMotion1017 by
Diff: main.cpp
- Revision:
- 16:6dd2e60bc5bc
- Parent:
- 15:1d931a305464
- Child:
- 17:dce982e0a383
diff -r 1d931a305464 -r 6dd2e60bc5bc main.cpp --- a/main.cpp Mon Apr 08 03:13:15 2013 +0000 +++ b/main.cpp Mon May 20 08:25:22 2013 +0000 @@ -1,13 +1,15 @@ #include "mbed.h" +#include <vector> +#include "renderclass.h" #include "laserProjectorHardware.h" -#include <vector> #define PI 3.141592 InterruptIn clockEncoderPin(p14); DigitalIn directionPin(p15); void processSerial(); -Timer timer_v; +Timer timer_v; // for shearing +Timer timer; //for send the speed on the serial port every 30 ms: LocalFileSystem local("local"); //Serial pc(USBTX, USBRX); @@ -28,44 +30,20 @@ bool start=false; -struct point2dl { - int x,y; - int laserSwitch; // laser {1: on 0:off} until next step -}; -point2dl shearing(point2dl dataBefore, float velocity, float theta){ - point2dl dataAfter; - dataAfter.x = dataBefore.x + velocity * cos(theta) * timer_v.read_us()/st/1000; //st is a parameter for ajustment - dataAfter.y = dataBefore.y + velocity * sin(theta) * timer_v.read_us()/st/1000; - dataAfter.laserSwitch = dataBefore.laserSwitch; - - return dataAfter; -} +//renderclass---------------------------------------------------------- -point2dl rotation(point2dl dataBefore, float theta){ - sint = sin(theta); - cost = cos(theta); - point2dl dataAfter; - dataAfter.x = sint*dataBefore.x + cost*dataBefore.y; - dataAfter.y = -cost*dataBefore.x + sint*dataBefore.y; - dataAfter.laserSwitch = dataBefore.laserSwitch; +vector<letter> alphabet; // letter library +vector<letter> myText; - return dataAfter; -} + -struct letter { - int pointnum; - vector<point2dl> letpoints; -}; - -vector<letter> libletter; // letter library - -////for culculate rotary velocit800000000y -------------------------------------------------------- +////for culculate rotary velocity -------------------------------------------------------- volatile float angleIncrement = 2.0*PI / 128; // when in Sign/Magnitude mode float radious = 700, attachSecond = 500; -// a ticker function to compute the speed periodically: +// a ticker function to compute the speed periodically------------------------------------------------------------- #define PERIODIC_COMPUTE 10000 // in us volatile float angularSpeed = 0; volatile float angle=0, oldAngle=0; @@ -83,7 +61,6 @@ oldAngle=angle; } -Timer timer; int main(){ //read from TextFileLibrary ------------------------------------------------------ @@ -105,7 +82,7 @@ fscanf(fp, "%d", &bufp.laserSwitch); bufl.letpoints.push_back(bufp); } - libletter.push_back(bufl); + alphabet.push_back(bufl); } @@ -115,29 +92,30 @@ // initialize the angle (arbitrary origin): oldAngle=angle=0; - // Attach the external interrupt routine: - //clockEncoderPin.rise(&encoderClock); - //clockEncoderPin.fall(&encoderClock); + // Attach the external interrupt routine---------------------------------------------------------------------- superEncoder.attach_us(&encoderClock, attachSecond); timer.reset(); timer.start(); + //using renderclass.cpp ---------------------------------------------------------- + render myRender; + myRender.setRender(&myText); + myRender.startRender(); + // Attach the periodic computing function: speedTimerCompute.attach_us(&computeSpeed, PERIODIC_COMPUTE); - // Set displaying laser powers: + // Set displaying laser powers-------------------------------------------------------------------------- IO.setRedPower(0); IO.setGreenPower(0); wait_ms(100); - - X = beforeX = CENTER_AD_MIRROR_X; - Y = beforeY = CENTER_AD_MIRROR_Y; + + timer_v.start(); // 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: @@ -145,44 +123,6 @@ pc.printf("Angular Speed = %4.2f\t Cumulative Angle = %4.2f\n" , angularSpeed, angle); timer.reset(); } - - - // drawing ///----------------------------------------------- - for(int i=0; i<inputletters.size(); i++) { - - for(int j=0; j<libletter[inputletters[i]-'a'].letpoints.size(); j++) { - - if (pc.readable()>0) processSerial(); - - point2dl rotated = rotation(libletter[inputletters[i]-'a'].letpoints[j] ,angle); - point2dl sheared = shearing(rotated ,radious*angularSpeed, angle); - X = CENTER_AD_MIRROR_X + radious * cost; - Y = CENTER_AD_MIRROR_Y + radious * sint; - IO.writeOutXY(X + rotated.x,Y + rotated.y ); - - /* - int x = -0.8*((libletter[inputletters[i]-'a'].letpoints[j].x ) - radious*angularSpeed*timer_v.read_us()/st/1000); //this ZURE should be modifyed not by dt but Timer. - int y = (libletter[inputletters[i]-'a'].letpoints[j].y); - IO.writeOutXY(X + radious*cost + sint*x + cost*y,Y + radious*sint - cost*x + sint*y); - */ - - wait_us(dt); - IO.setRedPower(libletter[inputletters[i]-'a'].letpoints[j].laserSwitch);//on - } - timer_v.reset(); - IO.setRedPower(0); //off - wait_us(dt_betWords);//sqrtf(vx*vx+vy*vy)*100000); - - } - //////////////// - IO.setRGBPower(1); //off - wait_us(10000); - start=false; - ////////////////////*/ - } - - - } } @@ -192,9 +132,7 @@ char stringData[24]; // note: an integer is two bytes long, represented with a maximum of 5 digits, but we may send floats or unsigned int... int indexStringData=0;//position of the byte in the string -void processSerial() -{ - +void processSerial(){ start=true; while(pc.readable()>0) { @@ -205,13 +143,15 @@ stringData[indexStringData] = val; indexStringData++; } else if ((val >= 'a') && (val <= 'z')) { // this is 45 to 57 (included) - inputletters.push_back(val); + myText.push_back(alphabet['a'-1]); + //inputletters.push_back(val); } /*else if (val == '/') { makeBuffer(); }*/ else if (val == '.') { - inputletters.clear(); + myText.clear(); + //inputletters.clear(); } else if (val == 'X') {