譯文 張
/
7_7Boboobooo
123
Fork of Boboobooo by
motor_api.cpp@12:a3cee7619b77, 2014-07-10 (annotated)
- Committer:
- even
- Date:
- Thu Jul 10 10:22:14 2014 +0000
- Revision:
- 12:a3cee7619b77
- Parent:
- 0:68c173249c01
lots of weird things
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
backman | 0:68c173249c01 | 1 | #include "mbed.h" |
backman | 0:68c173249c01 | 2 | #include "motor_api.h" |
backman | 0:68c173249c01 | 3 | |
backman | 0:68c173249c01 | 4 | #define init_v 10 // period in 1.35 ~170ms |
backman | 0:68c173249c01 | 5 | |
backman | 0:68c173249c01 | 6 | |
backman | 0:68c173249c01 | 7 | |
backman | 0:68c173249c01 | 8 | |
backman | 0:68c173249c01 | 9 | |
backman | 0:68c173249c01 | 10 | |
backman | 0:68c173249c01 | 11 | |
backman | 0:68c173249c01 | 12 | |
backman | 0:68c173249c01 | 13 | BX_motor::BX_motor(char type){ |
backman | 0:68c173249c01 | 14 | |
backman | 0:68c173249c01 | 15 | |
backman | 0:68c173249c01 | 16 | |
backman | 0:68c173249c01 | 17 | |
backman | 0:68c173249c01 | 18 | |
backman | 0:68c173249c01 | 19 | //need N level???? |
backman | 0:68c173249c01 | 20 | engine_enable = new DigitalOut(PTE21); |
backman | 0:68c173249c01 | 21 | |
backman | 0:68c173249c01 | 22 | *engine_enable=1; |
backman | 0:68c173249c01 | 23 | |
backman | 0:68c173249c01 | 24 | Type=type; |
backman | 0:68c173249c01 | 25 | switch (type){ |
backman | 0:68c173249c01 | 26 | |
backman | 0:68c173249c01 | 27 | case 'A': |
backman | 0:68c173249c01 | 28 | forward_A = new PwmOut(PTC3); |
backman | 0:68c173249c01 | 29 | backward_A = new PwmOut(PTC4); |
backman | 0:68c173249c01 | 30 | |
backman | 0:68c173249c01 | 31 | forward_A->period_ms(init_v); |
backman | 0:68c173249c01 | 32 | backward_A->period_ms(init_v); |
backman | 0:68c173249c01 | 33 | *forward_A=0.5f; |
backman | 0:68c173249c01 | 34 | *backward_A=0.5f; |
backman | 0:68c173249c01 | 35 | |
backman | 0:68c173249c01 | 36 | break; |
backman | 0:68c173249c01 | 37 | |
backman | 0:68c173249c01 | 38 | |
backman | 0:68c173249c01 | 39 | case 'B': |
backman | 0:68c173249c01 | 40 | |
backman | 0:68c173249c01 | 41 | forward_B = new PwmOut(PTC1); |
backman | 0:68c173249c01 | 42 | backward_B = new PwmOut(PTC2); |
backman | 0:68c173249c01 | 43 | forward_B->period_ms(init_v); |
backman | 0:68c173249c01 | 44 | backward_B->period_ms(init_v); |
backman | 0:68c173249c01 | 45 | *forward_B=0.5f; |
backman | 0:68c173249c01 | 46 | *backward_B=0.5f; |
backman | 0:68c173249c01 | 47 | break; |
backman | 0:68c173249c01 | 48 | |
backman | 0:68c173249c01 | 49 | |
backman | 0:68c173249c01 | 50 | |
backman | 0:68c173249c01 | 51 | } |
backman | 0:68c173249c01 | 52 | |
backman | 0:68c173249c01 | 53 | } |
backman | 0:68c173249c01 | 54 | |
backman | 0:68c173249c01 | 55 | |
backman | 0:68c173249c01 | 56 | // level: -1.0 ~1.0 |
backman | 0:68c173249c01 | 57 | void BX_motor::rotate(float level){ |
backman | 0:68c173249c01 | 58 | |
backman | 0:68c173249c01 | 59 | Level=level; |
backman | 0:68c173249c01 | 60 | |
backman | 0:68c173249c01 | 61 | if(level >0){ |
backman | 0:68c173249c01 | 62 | |
backman | 0:68c173249c01 | 63 | switch(Type){ |
backman | 0:68c173249c01 | 64 | |
backman | 0:68c173249c01 | 65 | case 'A': |
backman | 0:68c173249c01 | 66 | *forward_A=level; |
backman | 0:68c173249c01 | 67 | *backward_A=0; |
backman | 0:68c173249c01 | 68 | break; |
backman | 0:68c173249c01 | 69 | case 'B': |
backman | 0:68c173249c01 | 70 | *forward_B=level; |
backman | 0:68c173249c01 | 71 | *backward_B=0; |
backman | 0:68c173249c01 | 72 | break; |
backman | 0:68c173249c01 | 73 | } |
backman | 0:68c173249c01 | 74 | |
backman | 0:68c173249c01 | 75 | }else if(level <0){ |
backman | 0:68c173249c01 | 76 | |
backman | 0:68c173249c01 | 77 | level=-1.0*level; |
backman | 0:68c173249c01 | 78 | |
backman | 0:68c173249c01 | 79 | switch(Type){ |
backman | 0:68c173249c01 | 80 | |
backman | 0:68c173249c01 | 81 | case 'A': |
backman | 0:68c173249c01 | 82 | *forward_A=0; |
backman | 0:68c173249c01 | 83 | *backward_A=level; |
backman | 0:68c173249c01 | 84 | break; |
backman | 0:68c173249c01 | 85 | case 'B': |
backman | 0:68c173249c01 | 86 | *forward_B=0; |
backman | 0:68c173249c01 | 87 | *backward_B=level; |
backman | 0:68c173249c01 | 88 | break; |
backman | 0:68c173249c01 | 89 | } |
backman | 0:68c173249c01 | 90 | |
backman | 0:68c173249c01 | 91 | } |
backman | 0:68c173249c01 | 92 | else{ |
backman | 0:68c173249c01 | 93 | switch(Type){ |
backman | 0:68c173249c01 | 94 | |
backman | 0:68c173249c01 | 95 | case 'A': |
backman | 0:68c173249c01 | 96 | *forward_A=1.0f; |
backman | 0:68c173249c01 | 97 | *backward_A=1.0f; |
backman | 0:68c173249c01 | 98 | |
backman | 0:68c173249c01 | 99 | break; |
backman | 0:68c173249c01 | 100 | case 'B': |
backman | 0:68c173249c01 | 101 | *forward_B=1.0f; |
backman | 0:68c173249c01 | 102 | *backward_B=1.0f; |
backman | 0:68c173249c01 | 103 | break; |
backman | 0:68c173249c01 | 104 | } |
backman | 0:68c173249c01 | 105 | |
backman | 0:68c173249c01 | 106 | |
backman | 0:68c173249c01 | 107 | } |
backman | 0:68c173249c01 | 108 | |
backman | 0:68c173249c01 | 109 | |
backman | 0:68c173249c01 | 110 | |
backman | 0:68c173249c01 | 111 | |
backman | 0:68c173249c01 | 112 | |
backman | 0:68c173249c01 | 113 | |
backman | 0:68c173249c01 | 114 | |
backman | 0:68c173249c01 | 115 | |
backman | 0:68c173249c01 | 116 | |
backman | 0:68c173249c01 | 117 | } |
backman | 0:68c173249c01 | 118 | |
backman | 0:68c173249c01 | 119 | |
backman | 0:68c173249c01 | 120 |