Clark Lin
/
BX-car_s
QQQ
Fork of BX-car_s by
motor_api.cpp@23:d6d4e8adf7fe, 2014-07-02 (annotated)
- Committer:
- physicsgood
- Date:
- Wed Jul 02 13:33:49 2014 +0000
- Revision:
- 23:d6d4e8adf7fe
- Parent:
- 20:4ed21397e775
QQQQ
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 | BX_motor::BX_motor(char type){ |
backman | 0:68c173249c01 | 6 | //need N level???? |
backman | 0:68c173249c01 | 7 | engine_enable = new DigitalOut(PTE21); |
backman | 0:68c173249c01 | 8 | |
backman | 0:68c173249c01 | 9 | *engine_enable=1; |
backman | 0:68c173249c01 | 10 | |
backman | 0:68c173249c01 | 11 | Type=type; |
backman | 0:68c173249c01 | 12 | switch (type){ |
backman | 0:68c173249c01 | 13 | |
backman | 0:68c173249c01 | 14 | case 'A': |
backman | 0:68c173249c01 | 15 | forward_A = new PwmOut(PTC3); |
backman | 0:68c173249c01 | 16 | backward_A = new PwmOut(PTC4); |
backman | 0:68c173249c01 | 17 | |
backman | 0:68c173249c01 | 18 | forward_A->period_ms(init_v); |
backman | 0:68c173249c01 | 19 | backward_A->period_ms(init_v); |
backman | 0:68c173249c01 | 20 | *forward_A=0.5f; |
backman | 0:68c173249c01 | 21 | *backward_A=0.5f; |
backman | 0:68c173249c01 | 22 | |
backman | 0:68c173249c01 | 23 | break; |
backman | 0:68c173249c01 | 24 | |
backman | 0:68c173249c01 | 25 | |
backman | 0:68c173249c01 | 26 | case 'B': |
backman | 0:68c173249c01 | 27 | |
backman | 11:03d5aa2511c4 | 28 | forward_B = new PwmOut(PTE29); |
backman | 11:03d5aa2511c4 | 29 | backward_B = new PwmOut(PTE23); |
backman | 0:68c173249c01 | 30 | forward_B->period_ms(init_v); |
backman | 0:68c173249c01 | 31 | backward_B->period_ms(init_v); |
backman | 0:68c173249c01 | 32 | *forward_B=0.5f; |
backman | 0:68c173249c01 | 33 | *backward_B=0.5f; |
backman | 0:68c173249c01 | 34 | break; |
backman | 0:68c173249c01 | 35 | |
backman | 0:68c173249c01 | 36 | |
backman | 0:68c173249c01 | 37 | |
backman | 0:68c173249c01 | 38 | } |
backman | 0:68c173249c01 | 39 | |
backman | 0:68c173249c01 | 40 | } |
backman | 0:68c173249c01 | 41 | |
backman | 0:68c173249c01 | 42 | |
backman | 0:68c173249c01 | 43 | // level: -1.0 ~1.0 |
backman | 0:68c173249c01 | 44 | void BX_motor::rotate(float level){ |
backman | 0:68c173249c01 | 45 | |
backman | 0:68c173249c01 | 46 | Level=level; |
backman | 0:68c173249c01 | 47 | |
backman | 0:68c173249c01 | 48 | if(level >0){ |
backman | 0:68c173249c01 | 49 | |
backman | 0:68c173249c01 | 50 | switch(Type){ |
backman | 0:68c173249c01 | 51 | |
backman | 0:68c173249c01 | 52 | case 'A': |
backman | 0:68c173249c01 | 53 | *forward_A=level; |
backman | 0:68c173249c01 | 54 | *backward_A=0; |
backman | 0:68c173249c01 | 55 | break; |
backman | 0:68c173249c01 | 56 | case 'B': |
backman | 0:68c173249c01 | 57 | *forward_B=level; |
backman | 0:68c173249c01 | 58 | *backward_B=0; |
backman | 0:68c173249c01 | 59 | break; |
backman | 0:68c173249c01 | 60 | } |
backman | 0:68c173249c01 | 61 | |
backman | 0:68c173249c01 | 62 | }else if(level <0){ |
backman | 0:68c173249c01 | 63 | |
backman | 0:68c173249c01 | 64 | level=-1.0*level; |
backman | 0:68c173249c01 | 65 | |
backman | 0:68c173249c01 | 66 | switch(Type){ |
backman | 0:68c173249c01 | 67 | |
backman | 0:68c173249c01 | 68 | case 'A': |
backman | 0:68c173249c01 | 69 | *forward_A=0; |
backman | 0:68c173249c01 | 70 | *backward_A=level; |
backman | 0:68c173249c01 | 71 | break; |
backman | 0:68c173249c01 | 72 | case 'B': |
backman | 0:68c173249c01 | 73 | *forward_B=0; |
backman | 0:68c173249c01 | 74 | *backward_B=level; |
backman | 0:68c173249c01 | 75 | break; |
backman | 0:68c173249c01 | 76 | } |
backman | 0:68c173249c01 | 77 | |
backman | 0:68c173249c01 | 78 | } |
backman | 0:68c173249c01 | 79 | else{ |
backman | 0:68c173249c01 | 80 | switch(Type){ |
backman | 0:68c173249c01 | 81 | |
backman | 0:68c173249c01 | 82 | case 'A': |
backman | 0:68c173249c01 | 83 | *forward_A=1.0f; |
backman | 0:68c173249c01 | 84 | *backward_A=1.0f; |
backman | 0:68c173249c01 | 85 | |
backman | 0:68c173249c01 | 86 | break; |
backman | 0:68c173249c01 | 87 | case 'B': |
backman | 0:68c173249c01 | 88 | *forward_B=1.0f; |
backman | 0:68c173249c01 | 89 | *backward_B=1.0f; |
backman | 0:68c173249c01 | 90 | break; |
backman | 0:68c173249c01 | 91 | } |
backman | 0:68c173249c01 | 92 | |
backman | 0:68c173249c01 | 93 | |
backman | 0:68c173249c01 | 94 | } |
backman | 0:68c173249c01 | 95 | |
backman | 0:68c173249c01 | 96 | |
backman | 0:68c173249c01 | 97 | |
backman | 0:68c173249c01 | 98 | |
backman | 0:68c173249c01 | 99 | |
backman | 0:68c173249c01 | 100 | |
backman | 0:68c173249c01 | 101 | |
backman | 0:68c173249c01 | 102 | |
backman | 0:68c173249c01 | 103 | |
backman | 0:68c173249c01 | 104 | } |
backman | 0:68c173249c01 | 105 | |
backman | 0:68c173249c01 | 106 | |
backman | 0:68c173249c01 | 107 |