Tony Lin
/
BX-car
hello
Fork of BX-car by
Diff: motor_api.cpp
- Revision:
- 10:9f0ce6ba7663
- Parent:
- 7:fd976e1ced33
--- a/motor_api.cpp Tue Jun 24 10:06:54 2014 +0000 +++ b/motor_api.cpp Thu Jun 26 14:29:53 2014 +0000 @@ -1,56 +1,33 @@ #include "mbed.h" #include "motor_api.h" - #define init_v 10 // period in 1.35 ~170ms - - - - - - - - BX_motor::BX_motor(char type){ - - - - - - //need N level???? +BX_motor::BX_motor(char type){ + //need N level???? engine_enable = new DigitalOut(PTE21); - - *engine_enable=1; - + *engine_enable=1; Type=type; switch (type){ - case 'A': - forward_A = new PwmOut(PTC3); - backward_A = new PwmOut(PTC4); + forward_A = new PwmOut(PTC3); + backward_A = new PwmOut(PTC4); forward_A->period_ms(init_v); backward_A->period_ms(init_v); - *forward_A=0.5f; - *backward_A=0.5f; - - break; + *forward_A=0.0f; + *backward_A=0.0f; + break; - - case 'B': - - forward_B = new PwmOut(PTC1); - backward_B = new PwmOut(PTE30); + case 'B': + forward_B = new PwmOut(PTE29); + backward_B = new PwmOut(PTE23); forward_B->period_ms(init_v); backward_B->period_ms(init_v); - *forward_B=0.5f; - *backward_B=0.5f; - break; - - - - } - + *forward_B=0.0f; + *backward_B=0.0f; + break; } +} // level: -1.0 ~1.0 @@ -59,36 +36,30 @@ Level=level; if(level >0){ - switch(Type){ - case 'A': *forward_A=level; - *backward_A=0; + *backward_A=0.01; break; case 'B': *forward_B=level; - *backward_B=0; + *backward_B=0.01; break; } - - }else if(level <0){ - - level=-1.0*level; - - switch(Type){ - + } + else if(level <0){ + level=-1.0*level; + switch(Type){ case 'A': - *forward_A=0; + *forward_A=0.01; *backward_A=level; break; case 'B': - *forward_B=0; + *forward_B=0.01; *backward_B=level; break; } - - } + } else{ switch(Type){ @@ -98,22 +69,11 @@ break; case 'B': - *forward_B=1.0f; + *forward_B=1.0f; *backward_B=1.0f; break; } - - - } - - - - - - - - - + } }