frequency change?
Fork of BridgeDriver by
Diff: BridgeDriver.cpp
- Revision:
- 7:7dabd934ebe4
- Parent:
- 6:d4afd3284a04
- Child:
- 8:36e2cd31ccf3
--- a/BridgeDriver.cpp Thu Jul 24 21:30:41 2014 +0000 +++ b/BridgeDriver.cpp Thu Jul 24 21:48:32 2014 +0000 @@ -75,14 +75,14 @@ } void BridgeDriver::enablePwm(uint8_t enPwmA, uint8_t enPwmB, uint8_t enPwmC, uint8_t enPwmD){ - enablePwm(BRIDGE_A, enPwmA); - enablePwm(BRIDGE_B, enPwmB); - enablePwm(BRIDGE_C, enPwmC); - enablePwm(BRIDGE_D, enPwmD); + enablePwm(MOTOR_A, enPwmA); + enablePwm(MOTOR_B, enPwmB); + enablePwm(MOTOR_C, enPwmC); + enablePwm(MOTOR_D, enPwmD); } -void BridgeDriver::enablePwm(Bridges bridge, uint8_t enPwm){ - int bNum = static_cast<int>(bridge); //numeric bridge +void BridgeDriver::enablePwm(Motors motor, uint8_t enPwm){ + int bNum = static_cast<int>(motor); //numeric motor if(enPwm == _pwm[bNum]){ return; }else if(enPwm == 0){ //disable pwm @@ -98,14 +98,14 @@ } void BridgeDriver::enableBraking(uint8_t enBrakeA, uint8_t enBrakeB, uint8_t enBrakeC, uint8_t enBrakeD){ //1 - drives output to GND when off; 0 - floats output when off - enableBraking(BRIDGE_A, enBrakeA); - enableBraking(BRIDGE_B, enBrakeB); - enableBraking(BRIDGE_C, enBrakeC); - enableBraking(BRIDGE_D, enBrakeD); + enableBraking(MOTOR_A, enBrakeA); + enableBraking(MOTOR_B, enBrakeB); + enableBraking(MOTOR_C, enBrakeC); + enableBraking(MOTOR_D, enBrakeD); } -void BridgeDriver::enableBraking(Bridges bridge, uint8_t enBrake) { - _braking[static_cast<int>(bridge)] = enBrake; +void BridgeDriver::enableBraking(Motors motor, uint8_t enBrake) { + _braking[static_cast<int>(motor)] = enBrake; } int BridgeDriver::forceBrake(uint8_t ch){ //force a specific channel to GND without changing braking default @@ -119,13 +119,20 @@ } } -int BridgeDriver::forceBrake(Bridges bridge){ //force a specific motor to GND without changing braking default - return static_cast<int>(drive(bridge, 0, 0)); +int BridgeDriver::forceBrake(Motors motor){ //force a specific motor to GND without changing braking default + return static_cast<int>(drive(motor, 0, 0)); } int BridgeDriver::forceFloat(uint8_t ch){ //force a specific channel to float without changing braking default - if( _pwm[(ch-1)/2]){ - return -1; + int bNum = (ch-1)/2; + if( _pwm[bNum] ){ + 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); + *_d[2*bNum] = 0; + return *_d[2*bNum + 1] = 0; }else{ enableCh(ch-1, 0); setLed(ch-1, 0); @@ -133,8 +140,8 @@ } } -int BridgeDriver::forceFloat(Bridges bridge){ //force a specific motor to float without changing braking default - int bNum = static_cast<int>(bridge); //numeric bridge +int BridgeDriver::forceFloat(Motors motor){ //force a specific motor to float without changing braking default + int bNum = static_cast<int>(motor); //numeric motor if(_pwm[bNum] == 0){ return -1; @@ -192,27 +199,27 @@ } } -float BridgeDriver::drive(Bridges bridge, float speed){ //speed from -1 to 1, speed of 0 will coast or brake depending on setting of _braking - int bNum = static_cast<int>(bridge); //numeric bridge +float BridgeDriver::drive(Motors motor, float speed){ //speed from -1 to 1, speed of 0 will coast or brake depending on setting of _braking + int bNum = static_cast<int>(motor); //numeric motor if(_pwm[bNum] == 0){ return -20 - bNum; } if(speed == 0){ - return drive(bridge, 1, 0); + return drive(motor, 1, 0); }else if(speed > 0){ - return drive(bridge, 1, speed); + return drive(motor, 1, speed); }else{ - return drive(bridge, -1, -1*speed); + return drive(motor, -1, -1*speed); } } -float BridgeDriver::drive(Bridges bridge, int8_t dir, float speed){ +float BridgeDriver::drive(Motors motor, int8_t dir, float speed){ //dir: 1=fwd, -1=rev, 0=brake (regardless of setting of _braking //speed from 0 to 1, speed of 0 will coast or brake depending on setting of _braking - int bNum = static_cast<uint8_t>(bridge); //numeric bridge + int bNum = static_cast<uint8_t>(motor); //numeric motor if(_pwm[bNum] == 0){ return -10 - bNum;