Takashi Asano
/
linearMirrorMotion1017
sotsuron
Fork of linearMirrorMotion1017 by
Diff: main.cpp
- Revision:
- 21:4095a071724d
- Parent:
- 20:8475768fc2f7
- Child:
- 22:e86d63dfbbe1
--- a/main.cpp Fri May 31 06:32:07 2013 +0000 +++ b/main.cpp Fri Jun 07 05:01:40 2013 +0000 @@ -10,7 +10,7 @@ DigitalIn directionPin(p15); //green void processSerial(); -Timer timer_v; // for shearing //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); @@ -49,14 +49,13 @@ */ ////for culculate rotary velocity -------------------------------------------------------- - -volatile float angleIncrement = 2.0*PI / 1024; // when in Sign/Magnitude mode -float radious = 700, attachSecond = 10000; +int radious = 700, attachSecond = 500; +/*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 volatile float angularSpeed = 0; -volatile float angle=0, oldAngle=0; +/*volatile float*/ int angle=0, oldAngle=0; Ticker speedTimerCompute; Ticker superEncoder; @@ -75,6 +74,7 @@ oldAngle=angle; myRender.updateSpeed(angularSpeed,angle); void processSerial(); + } @@ -110,7 +110,7 @@ oldAngle=angle=0; // Attach the external interrupt routine---------------------------------------------------------------------- - superEncoder.attach_us(&encoderClock, 111); + superEncoder.attach_us(&encoderClock, 500); //clockEncoderPin.rise(&encoderClock); //clockEncoderPin.fall(&encoderClock); @@ -128,7 +128,7 @@ wait_ms(100); - timer_v.start(); + //timer_v.start(); // MAIN LOOP: -------------------------------------------------------------------------------------------- while(1) { if (pc.readable()>0) processSerial(); @@ -171,7 +171,7 @@ stringData[indexStringData] = 0; X = atoi(stringData); indexStringData=0; - vx = ((float)X-(float)beforeX) / (float)timer_v.read_us() *1000; + //vx = ((float)X-(float)beforeX) / (float)timer_v.read_us() *1000; } else if (val == 'Y') { @@ -182,7 +182,7 @@ //timer_v.stop(); //newSpeedReady = true; //if( (Y-beforeY) > 5){ - vy = ((float)Y-(float)beforeY) / (float)timer_v.read_us() *1000; + //vy = ((float)Y-(float)beforeY) / (float)timer_v.read_us() *1000; myRender.updateSpeed(vx, vy); @@ -205,15 +205,21 @@ pc.printf("shearingSwitch : %d \n" , myRender.shearingSwitch); indexStringData=0; //makeBuffer(); - } else if (val == 'R') { + } else if (val == 'A') { stringData[indexStringData] = 0; - radious = atoi(stringData); + angleIncrement = atoi(stringData); + pc.printf("angleIncrement : %d \n" , angleIncrement); + superEncoder.detach(); + superEncoder.attach_us(&encoderClock, attachSecond); indexStringData=0; //makeBuffer(); } else if (val == 'T') { stringData[indexStringData] = 0; attachSecond = atoi(stringData); pc.printf("attachSecond : %d \n" , attachSecond); + + superEncoder.detach(); + superEncoder.attach_us(&encoderClock, attachSecond); indexStringData=0; //makeBuffer(); }