wesh gros, ajout des ref dans brushlessservo

Dependencies:   MPU6050 mbed

Fork of Gimbal_ENSEA by Thomas Giraud-Sauveur

Committer:
sype
Date:
Fri Jun 03 14:17:35 2016 +0000
Revision:
2:d0606d66af96
Parent:
0:63c6db89607f
Ajout ref brushlessservo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ThomasGS 0:63c6db89607f 1 /*
ThomasGS 0:63c6db89607f 2 #include "mbed.h"
ThomasGS 0:63c6db89607f 3 #include "mycontroller.h"
ThomasGS 0:63c6db89607f 4
ThomasGS 0:63c6db89607f 5 //42 steps permet de faire un tour avec 6 etats
ThomasGS 0:63c6db89607f 6
ThomasGS 0:63c6db89607f 7 PwmOut pwmA(D5);
ThomasGS 0:63c6db89607f 8 PwmOut pwmB(D6);
ThomasGS 0:63c6db89607f 9 PwmOut pwmC(D7);
ThomasGS 0:63c6db89607f 10
ThomasGS 0:63c6db89607f 11 DigitalOut myled(LED1);
ThomasGS 0:63c6db89607f 12
ThomasGS 0:63c6db89607f 13 //const int motorPinState[]={1,1,1,0,0,0};
ThomasGS 0:63c6db89607f 14 //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 };
ThomasGS 0:63c6db89607f 15 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};
ThomasGS 0:63c6db89607f 16
ThomasGS 0:63c6db89607f 17 int sineArraySize = sizeof(pwmSin)/sizeof(int);
ThomasGS 0:63c6db89607f 18 int phaseShift = sineArraySize / 3;
ThomasGS 0:63c6db89607f 19
ThomasGS 0:63c6db89607f 20 int currentStepA=0;
ThomasGS 0:63c6db89607f 21 int currentStepB=currentStepA+phaseShift;
ThomasGS 0:63c6db89607f 22 int currentStepC=currentStepB+phaseShift;
ThomasGS 0:63c6db89607f 23
ThomasGS 0:63c6db89607f 24 int main()
ThomasGS 0:63c6db89607f 25 {
ThomasGS 0:63c6db89607f 26
ThomasGS 0:63c6db89607f 27 pwmA.period(1/20000.0);
ThomasGS 0:63c6db89607f 28 pwmB.period(1/20000.0);
ThomasGS 0:63c6db89607f 29 pwmC.period(1/20000.0);
ThomasGS 0:63c6db89607f 30 //mypwm.pulsewidth_ms(1);
ThomasGS 0:63c6db89607f 31 printf("sineArraySize : %d\n",sineArraySize);
ThomasGS 0:63c6db89607f 32 //printf("pwm set to %.2f %%\n", mypwm.read() * 100);
ThomasGS 0:63c6db89607f 33 for(int i=0; i<sineArraySize/2; i+=10) {
ThomasGS 0:63c6db89607f 34 pwmA=pwmSin[currentStepA]/255.0;
ThomasGS 0:63c6db89607f 35 pwmB=pwmSin[currentStepB]/255.0;
ThomasGS 0:63c6db89607f 36 pwmC=pwmSin[currentStepC]/255.0;
ThomasGS 0:63c6db89607f 37
ThomasGS 0:63c6db89607f 38 currentStepA+=10;
ThomasGS 0:63c6db89607f 39 currentStepB+=10;
ThomasGS 0:63c6db89607f 40 currentStepC+=10;
ThomasGS 0:63c6db89607f 41
ThomasGS 0:63c6db89607f 42 currentStepA%=sineArraySize;
ThomasGS 0:63c6db89607f 43 currentStepB%=sineArraySize;
ThomasGS 0:63c6db89607f 44 currentStepC%=sineArraySize;
ThomasGS 0:63c6db89607f 45
ThomasGS 0:63c6db89607f 46 wait_ms(10);
ThomasGS 0:63c6db89607f 47 printf("pwm : %2f %2f %2f \n",pwmA.read(),pwmB.read(),pwmC.read());
ThomasGS 0:63c6db89607f 48 }
ThomasGS 0:63c6db89607f 49
ThomasGS 0:63c6db89607f 50 pwmA=0;
ThomasGS 0:63c6db89607f 51 pwmB=0;
ThomasGS 0:63c6db89607f 52 pwmC=0;
ThomasGS 0:63c6db89607f 53
ThomasGS 0:63c6db89607f 54 while(1) {
ThomasGS 0:63c6db89607f 55 myled = !myled;
ThomasGS 0:63c6db89607f 56 wait(1);
ThomasGS 0:63c6db89607f 57 }
ThomasGS 0:63c6db89607f 58 }
ThomasGS 0:63c6db89607f 59 */