shared

Dependencies:   mbed-rtos mbed

Fork of Boboobooo by kao yi

Committer:
Kruskal
Date:
Fri Oct 31 10:54:51 2014 +0000
Revision:
8:089b778962c4
Parent:
7:fe8665daf3e7
:D

Who changed what in which revision?

UserRevisionLine numberNew 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 //need N level????
backman 0:68c173249c01 16 engine_enable = new DigitalOut(PTE21);
backman 0:68c173249c01 17
backman 0:68c173249c01 18 *engine_enable=1;
backman 0:68c173249c01 19
backman 0:68c173249c01 20 Type=type;
backman 0:68c173249c01 21 switch (type){
backman 0:68c173249c01 22
backman 0:68c173249c01 23 case 'A':
backman 0:68c173249c01 24 forward_A = new PwmOut(PTC3);
backman 0:68c173249c01 25 backward_A = new PwmOut(PTC4);
backman 0:68c173249c01 26
backman 0:68c173249c01 27 forward_A->period_ms(init_v);
backman 0:68c173249c01 28 backward_A->period_ms(init_v);
backman 0:68c173249c01 29 *forward_A=0.5f;
backman 0:68c173249c01 30 *backward_A=0.5f;
backman 0:68c173249c01 31
backman 0:68c173249c01 32 break;
backman 0:68c173249c01 33
backman 0:68c173249c01 34
backman 0:68c173249c01 35 case 'B':
backman 0:68c173249c01 36
backman 0:68c173249c01 37 forward_B = new PwmOut(PTC1);
backman 0:68c173249c01 38 backward_B = new PwmOut(PTC2);
backman 0:68c173249c01 39 forward_B->period_ms(init_v);
backman 0:68c173249c01 40 backward_B->period_ms(init_v);
backman 0:68c173249c01 41 *forward_B=0.5f;
backman 0:68c173249c01 42 *backward_B=0.5f;
backman 0:68c173249c01 43 break;
backman 0:68c173249c01 44
backman 0:68c173249c01 45
backman 0:68c173249c01 46
backman 0:68c173249c01 47 }
backman 0:68c173249c01 48
backman 0:68c173249c01 49 }
backman 0:68c173249c01 50
backman 0:68c173249c01 51
backman 0:68c173249c01 52 // level: -1.0 ~1.0
backman 0:68c173249c01 53 void BX_motor::rotate(float level){
backman 0:68c173249c01 54
backman 0:68c173249c01 55 Level=level;
backman 0:68c173249c01 56
backman 0:68c173249c01 57 if(level >0){
backman 0:68c173249c01 58
backman 0:68c173249c01 59 switch(Type){
backman 0:68c173249c01 60
backman 0:68c173249c01 61 case 'A':
backman 0:68c173249c01 62 *forward_A=level;
Kruskal 8:089b778962c4 63 *backward_A=0.1;
backman 0:68c173249c01 64 break;
backman 0:68c173249c01 65 case 'B':
backman 0:68c173249c01 66 *forward_B=level;
Kruskal 8:089b778962c4 67 *backward_B=0.1;
backman 0:68c173249c01 68 break;
backman 0:68c173249c01 69 }
backman 0:68c173249c01 70
backman 0:68c173249c01 71 }else if(level <0){
backman 0:68c173249c01 72
backman 0:68c173249c01 73 level=-1.0*level;
backman 0:68c173249c01 74
backman 0:68c173249c01 75 switch(Type){
backman 0:68c173249c01 76
backman 0:68c173249c01 77 case 'A':
Kruskal 8:089b778962c4 78 *forward_A=0.1;
backman 0:68c173249c01 79 *backward_A=level;
backman 0:68c173249c01 80 break;
backman 0:68c173249c01 81 case 'B':
Kruskal 8:089b778962c4 82 *forward_B=0.1;
backman 0:68c173249c01 83 *backward_B=level;
backman 0:68c173249c01 84 break;
backman 0:68c173249c01 85 }
backman 0:68c173249c01 86
backman 0:68c173249c01 87 }
Kruskal 7:fe8665daf3e7 88 else{
backman 0:68c173249c01 89 switch(Type){
backman 0:68c173249c01 90
backman 0:68c173249c01 91 case 'A':
backman 0:68c173249c01 92 *forward_A=1.0f;
backman 0:68c173249c01 93 *backward_A=1.0f;
backman 0:68c173249c01 94
backman 0:68c173249c01 95 break;
backman 0:68c173249c01 96 case 'B':
backman 0:68c173249c01 97 *forward_B=1.0f;
backman 0:68c173249c01 98 *backward_B=1.0f;
backman 0:68c173249c01 99 break;
backman 0:68c173249c01 100 }
backman 0:68c173249c01 101
backman 0:68c173249c01 102
Kruskal 7:fe8665daf3e7 103 }
Kruskal 7:fe8665daf3e7 104
backman 0:68c173249c01 105 }
backman 0:68c173249c01 106
backman 0:68c173249c01 107
backman 0:68c173249c01 108