![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
quad test
Fork of Quad Rotor Control by
main.cpp@1:2143bcfd2ff1, 2015-02-02 (annotated)
- Committer:
- khaledelmadawi
- Date:
- Mon Feb 02 15:47:52 2015 +0000
- Revision:
- 1:2143bcfd2ff1
- Parent:
- 0:fe6280c7a52f
test;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Ryan | 0:fe6280c7a52f | 1 | #include "mbed.h" |
Ryan | 0:fe6280c7a52f | 2 | #include "stdio.h" |
Ryan | 0:fe6280c7a52f | 3 | #include "stdlib.h" |
Ryan | 0:fe6280c7a52f | 4 | #include "string" |
Ryan | 0:fe6280c7a52f | 5 | AnalogIn Volts(p20); |
Ryan | 0:fe6280c7a52f | 6 | PwmOut BLDCM1(p21); |
Ryan | 0:fe6280c7a52f | 7 | PwmOut BLDCM2(p22); |
Ryan | 0:fe6280c7a52f | 8 | PwmOut BLDCM3(p23); |
Ryan | 0:fe6280c7a52f | 9 | PwmOut BLDCM4(p24); |
Ryan | 0:fe6280c7a52f | 10 | Serial pc(USBTX, USBRX); |
Ryan | 0:fe6280c7a52f | 11 | |
Ryan | 0:fe6280c7a52f | 12 | //red right p21 |
Ryan | 0:fe6280c7a52f | 13 | //blue right p22 |
Ryan | 0:fe6280c7a52f | 14 | //white left p23 |
Ryan | 0:fe6280c7a52f | 15 | //red left p24 |
Ryan | 0:fe6280c7a52f | 16 | |
Ryan | 0:fe6280c7a52f | 17 | // -----------> Make SURE!! each ESC is grounded on mbeds ground!!!!!!!!!! <------------ |
Ryan | 0:fe6280c7a52f | 18 | |
Ryan | 0:fe6280c7a52f | 19 | |
Ryan | 0:fe6280c7a52f | 20 | float val; |
Ryan | 0:fe6280c7a52f | 21 | |
Ryan | 0:fe6280c7a52f | 22 | int main() { |
Ryan | 0:fe6280c7a52f | 23 | val =0.001; |
Ryan | 0:fe6280c7a52f | 24 | // Most ESC take standard servo commands so that is a 50hz signal and listens between 1ms and 3ms pulsewidth |
Ryan | 0:fe6280c7a52f | 25 | BLDCM1.period_ms(20); |
Ryan | 0:fe6280c7a52f | 26 | BLDCM2.period_ms(20); |
Ryan | 0:fe6280c7a52f | 27 | BLDCM3.period_ms(20); |
Ryan | 0:fe6280c7a52f | 28 | BLDCM4.period_ms(20); |
Ryan | 0:fe6280c7a52f | 29 | //////////////////////////////// |
Ryan | 0:fe6280c7a52f | 30 | while (1) { |
Ryan | 0:fe6280c7a52f | 31 | |
Ryan | 0:fe6280c7a52f | 32 | |
Ryan | 0:fe6280c7a52f | 33 | //Initailize motors |
Ryan | 0:fe6280c7a52f | 34 | |
Ryan | 0:fe6280c7a52f | 35 | if(pc.readable()){ |
Ryan | 0:fe6280c7a52f | 36 | switch (pc.getc()) { |
Ryan | 0:fe6280c7a52f | 37 | case 'u': |
Ryan | 0:fe6280c7a52f | 38 | val += 0.00005; |
Ryan | 0:fe6280c7a52f | 39 | break; |
Ryan | 0:fe6280c7a52f | 40 | case 'd': |
Ryan | 0:fe6280c7a52f | 41 | val -= 0.00005; |
Ryan | 0:fe6280c7a52f | 42 | break; |
Ryan | 0:fe6280c7a52f | 43 | case 'w': |
Ryan | 0:fe6280c7a52f | 44 | val += 0.00001; |
Ryan | 0:fe6280c7a52f | 45 | break; |
Ryan | 0:fe6280c7a52f | 46 | case 'x': |
Ryan | 0:fe6280c7a52f | 47 | val -= 0.00001; |
Ryan | 0:fe6280c7a52f | 48 | break; |
Ryan | 0:fe6280c7a52f | 49 | case 's': |
Ryan | 0:fe6280c7a52f | 50 | val = 0.001; |
Ryan | 0:fe6280c7a52f | 51 | break; |
Ryan | 0:fe6280c7a52f | 52 | case 'm': |
Ryan | 0:fe6280c7a52f | 53 | val = 0.0018; |
Ryan | 0:fe6280c7a52f | 54 | break; |
khaledelmadawi | 1:2143bcfd2ff1 | 55 | case 'l': |
khaledelmadawi | 1:2143bcfd2ff1 | 56 | val=0.5; |
khaledelmadawi | 1:2143bcfd2ff1 | 57 | break; |
Ryan | 0:fe6280c7a52f | 58 | } |
Ryan | 0:fe6280c7a52f | 59 | } |
Ryan | 0:fe6280c7a52f | 60 | |
Ryan | 0:fe6280c7a52f | 61 | BLDCM1.pulsewidth(val); |
Ryan | 0:fe6280c7a52f | 62 | BLDCM2.pulsewidth(val); |
Ryan | 0:fe6280c7a52f | 63 | BLDCM3.pulsewidth(val); |
Ryan | 0:fe6280c7a52f | 64 | BLDCM4.pulsewidth(val); |
Ryan | 0:fe6280c7a52f | 65 | wait(0.25); |
khaledelmadawi | 1:2143bcfd2ff1 | 66 | pc.printf("Volts (%f) Pulsewidth (%f) RPM (%f) \r\n",(((val*1000)*12)),(val),(((val*1000)*1200))); |
Ryan | 0:fe6280c7a52f | 67 | |
Ryan | 0:fe6280c7a52f | 68 | } |
Ryan | 0:fe6280c7a52f | 69 | } |