- Don't think anything was changed or updated.... simply viewed the class
Dependents: Component_Test_Interface
Fork of BridgeDriver by
BridgeDriver.h
- Committer:
- jason701802
- Date:
- 2014-07-24
- Revision:
- 7:7dabd934ebe4
- Parent:
- 5:c1f32ce026f6
- Child:
- 8:36e2cd31ccf3
File content as of revision 7:7dabd934ebe4:
#include "mbed.h" #include "MCP23017.h" #include "TextLCD.h" //if using diagnostic #ifndef BRIDGEDRIVER_H #define BRIDGEDRIVER_H #define PWM_PERIOD 0.001 //pin definitions #define PIN_CH1 P1_18 //hardware PWM1[1] #define PIN_CH2 P2_0 //hardware PWM1[1] #define PIN_CH3 P1_20 //hardware PWM1[2] #define PIN_CH4 P2_1 //hardware PWM1[2] #define PIN_CH5 P1_21 //hardware PWM1[3] #define PIN_CH6 P1_23 //hardware PWM1[4] #define PIN_CH7 P1_24 //hardware PWM1[5] #define PIN_CH8 P1_26 //hardware PWM1[6] #define EN_ADDR 0x40 //i2c address of enable pin port expander #define LED_ADDR 0x4E //i2c address of button and LED port expander class BridgeDriver{ public: enum Motors{ MOTOR_A, MOTOR_B, MOTOR_C, MOTOR_D }; BridgeDriver( I2C *i2c, uint8_t enPwmA = 0, uint8_t enPwmB = 0, uint8_t enPwmC = 0, uint8_t enPwmD = 0, uint8_t enAddr = EN_ADDR, uint8_t ledAddr = LED_ADDR); ~BridgeDriver(); void enablePwm(uint8_t enPwmA, uint8_t enPwmB, uint8_t enPwmC, uint8_t enPwmD); void enablePwm(Motors motor, uint8_t enPwm); void 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 void enableBraking(Motors motor, uint8_t enBrake); int forceBrake(uint8_t ch); //force a specific channel to GND without changing braking default int forceBrake(Motors motor); //force a specific motor to GND without changing braking default int forceFloat(uint8_t ch); //force a specific channel to float without changing braking default int forceFloat(Motors motor); //force a specific motor to float without changing braking default int drive(uint8_t state); int drive(uint8_t ch, uint8_t on); float drive(Motors motor, float speed); //speed from -1 to 1, speed of 0 will coast or brake depending on setting of _braking float drive(Motors motor, int8_t dir, float speed); //dir: 1=fwd, -1=rev, 0=brake (irregardless of setting of _braking //speed from 0 to 1, speed of 0 will coast or brake depending on setting of _braking void diagnostic(TextLCD_I2C *lcd); private: DigitalOut *_d[8]; PwmOut *_p[8]; MCP23017 *_EnCtl; MCP23017 *_IO; I2C *_i2c; uint8_t _enAddr; uint8_t _ledAddr; uint8_t _pwm[4]; //enabled full bridges uint8_t _pwmCh; //currently actie PWM pins int8_t _dir[4]; //dir of 1 means lower # ch is driving, dir of -1 means higher number ch is driving uint8_t _braking[4]; uint8_t _oldLedState; //for setLed functions. Kept external to overload function void enableCh(uint8_t ch, uint8_t en); void setLed(uint8_t ch, uint8_t en); void setLed(uint8_t state); void setPwm(uint8_t ch, uint8_t en); }; #endif