Thomas Giraud-Sauveur
/
Gimbal_ENSEA
pour simone
Diff: main_copy.cpp
- Revision:
- 0:63c6db89607f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main_copy.cpp Fri Jun 03 13:51:01 2016 +0000 @@ -0,0 +1,59 @@ +/* +#include "mbed.h" +#include "mycontroller.h" + +//42 steps permet de faire un tour avec 6 etats + +PwmOut pwmA(D5); +PwmOut pwmB(D6); +PwmOut pwmC(D7); + +DigitalOut myled(LED1); + +//const int motorPinState[]={1,1,1,0,0,0}; +//const int pwmSin[] = {127, 138, 149, 160, 170, 181, 191, 200, 209, 217, 224, 231, 237, 242, 246, 250, 252, 254, 254, 254, 252, 250, 246, 242, 237, 231, 224, 217, 209, 200, 191, 181, 170, 160, 149, 138, 127, 116, 105, 94, 84, 73, 64, 54, 45, 37, 30, 23, 17, 12, 8, 4, 2, 0, 0, 0, 2, 4, 8, 12, 17, 23, 30, 37, 45, 54, 64, 73, 84, 94, 105, 116 }; +const int pwmSin[] = {128, 132, 136, 140, 143, 147, 151, 155, 159, 162, 166, 170, 174, 178, 181, 185, 189, 192, 196, 200, 203, 207, 211, 214, 218, 221, 225, 228, 232, 235, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 249, 250, 250, 251, 252, 252, 253, 253, 253, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 254, 254, 253, 253, 253, 252, 252, 251, 250, 250, 249, 248, 248, 247, 246, 245, 244, 243, 242, 241, 240, 239, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 249, 250, 250, 251, 252, 252, 253, 253, 253, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 254, 254, 253, 253, 253, 252, 252, 251, 250, 250, 249, 248, 248, 247, 246, 245, 244, 243, 242, 241, 240, 239, 238, 235, 232, 228, 225, 221, 218, 214, 211, 207, 203, 200, 196, 192, 189, 185, 181, 178, 174, 170, 166, 162, 159, 155, 151, 147, 143, 140, 136, 132, 128, 124, 120, 116, 113, 109, 105, 101, 97, 94, 90, 86, 82, 78, 75, 71, 67, 64, 60, 56, 53, 49, 45, 42, 38, 35, 31, 28, 24, 21, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 8, 7, 6, 6, 5, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 8, 7, 6, 6, 5, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 21, 24, 28, 31, 35, 38, 42, 45, 49, 53, 56, 60, 64, 67, 71, 75, 78, 82, 86, 90, 94, 97, 101, 105, 109, 113, 116, 120, 124}; + +int sineArraySize = sizeof(pwmSin)/sizeof(int); +int phaseShift = sineArraySize / 3; + +int currentStepA=0; +int currentStepB=currentStepA+phaseShift; +int currentStepC=currentStepB+phaseShift; + +int main() +{ + + pwmA.period(1/20000.0); + pwmB.period(1/20000.0); + pwmC.period(1/20000.0); + //mypwm.pulsewidth_ms(1); + printf("sineArraySize : %d\n",sineArraySize); + //printf("pwm set to %.2f %%\n", mypwm.read() * 100); + for(int i=0; i<sineArraySize/2; i+=10) { + pwmA=pwmSin[currentStepA]/255.0; + pwmB=pwmSin[currentStepB]/255.0; + pwmC=pwmSin[currentStepC]/255.0; + + currentStepA+=10; + currentStepB+=10; + currentStepC+=10; + + currentStepA%=sineArraySize; + currentStepB%=sineArraySize; + currentStepC%=sineArraySize; + + wait_ms(10); + printf("pwm : %2f %2f %2f \n",pwmA.read(),pwmB.read(),pwmC.read()); + } + + pwmA=0; + pwmB=0; + pwmC=0; + + while(1) { + myled = !myled; + wait(1); + } +} +*/ \ No newline at end of file