- Don't think anything was changed or updated.... simply viewed the class
Dependents: Component_Test_Interface
Fork of BridgeDriver by
Diff: BridgeDriver.cpp
- Revision:
- 4:87768972db3f
- Parent:
- 3:247939286d2c
- Child:
- 6:d4afd3284a04
--- a/BridgeDriver.cpp Fri Jul 18 23:13:09 2014 +0000 +++ b/BridgeDriver.cpp Mon Jul 21 19:03:42 2014 +0000 @@ -5,7 +5,6 @@ #include "MCP23017.h" -//TO-DO: check order of setting output and enabling/disabling channel BridgeDriver::BridgeDriver( I2C *i2c, uint8_t enPwmA, uint8_t enPwmB, uint8_t enPwmC, uint8_t enPwmD, uint8_t enAddr, uint8_t ledAddr) : _i2c(i2c), @@ -137,15 +136,11 @@ if(_pwm[bNum] == 0){ return -1; }else{ - if(_dir[bNum] != 0){ - setPwm(2*bNum, 0); - setPwm(2*bNum + 1, 0); - _dir[bNum] = 0; - } + setPwm(2*bNum, 0); //channel is disabled in setPwm() + setPwm(2*bNum + 1, 0); //channel is disabled in setPwm() + _dir[bNum] = 0; setLed(2*bNum, 0); setLed(2*bNum + 1, 0); - enableCh(2*bNum, 0); //enable/disable channels as necessary for braking/coasting - enableCh(2*bNum + 1, 0); *_d[2*bNum] = 0; return *_d[2*bNum + 1] = 0; } @@ -166,7 +161,7 @@ enableCh(i, 1); }else{ enableCh(i, 0); - *_d[i] = 0; //brake output + *_d[i] = 0; //float/coast output } } } @@ -177,10 +172,11 @@ if( _pwm[(ch-1)/2]){ return -1; }else if(on){ //on + *_d[ch-1] = 1; enableCh(ch-1, 1); setLed(ch-1, 1); - return *_d[ch-1] = 1; //off, brake - }else if(_braking[(ch-1)/2]){ + return 1; + }else if(_braking[(ch-1)/2]){ //off, brake *_d[ch-1] = 0; enableCh(ch-1, 1); setLed(ch-1, 0); @@ -225,52 +221,48 @@ setPwm(2*bNum + 1, 0); _dir[bNum] = 0; } - setLed(2*bNum, 0); - setLed(2*bNum + 1, 0); *_d[2*bNum] = 0; *_d[2*bNum + 1] = 0; enableCh(2*bNum, 1); //enable channels for braking enableCh(2*bNum + 1, 1); + setLed(2*bNum, 0); + setLed(2*bNum + 1, 0); return 0; }else if(speed == 0){ //coast - if(_dir[bNum] != 0){ - setPwm(2*bNum, 0); - setPwm(2*bNum + 1, 0); - _dir[bNum] = 0; - } + setPwm(2*bNum, 0); //channel is disabled in setPwm() + setPwm(2*bNum + 1, 0); //channel is disabled in setPwm() + _dir[bNum] = 0; setLed(2*bNum, 0); setLed(2*bNum + 1, 0); - enableCh(2*bNum, 0); //coast channels - enableCh(2*bNum + 1, 0); *_d[2*bNum] = 0; return *_d[2*bNum + 1] = 0; - }else if(dir == 1){ + }else if(dir == 1){ //forward if(_dir[bNum] != 1){ setPwm(2*bNum, 1); setPwm(2*bNum + 1, 0); _dir[bNum] = 1; } - setLed(2*bNum, 1); - setLed(2*bNum + 1, 0); *_p[2*bNum] = speed; *_d[2*bNum + 1] = 0; enableCh(2*bNum, 1); //enable channels enableCh(2*bNum + 1, 1); + setLed(2*bNum, 1); + setLed(2*bNum + 1, 0); return speed; - }else if(dir == -1){ + }else if(dir == -1){ //reverse if(_dir[bNum] != -1){ setPwm(2*bNum, 0); setPwm(2*bNum + 1, 1); _dir[bNum] = -1; } - setLed(2*bNum, 0); - setLed(2*bNum + 1, 1); *_d[2*bNum] = 0; *_p[2*bNum + 1] = speed; enableCh(2*bNum, 1); //enable channels enableCh(2*bNum + 1, 1); + setLed(2*bNum, 0); + setLed(2*bNum + 1, 1); return speed; } return -2; @@ -378,7 +370,7 @@ _p[ch] = new PwmOut(PIN_CH8); break; } - _p[ch]->period(0.001); + _p[ch]->period(PWM_PERIOD); _pwmCh = _pwmCh | (1 << ch); } }