Mitchell Hatfield / BridgeDriver

Dependents:   Component_Test_Interface

Fork of BridgeDriver by Jason T

Embed: (wiki syntax)

« Back to documentation index

BridgeDriver Class Reference

BridgeDriver Class Reference

BridgeDriver class For controlling the Test Controller bridges. More...

#include <BridgeDriver.h>

Public Types

enum  Motors
 

Channel pair labels.

More...

Public Member Functions

 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)
 Create BridgeDriver object.
 ~BridgeDriver ()
 Destroy BridgeDriver object.
void enablePwm (uint8_t enPwmA, uint8_t enPwmB, uint8_t enPwmC, uint8_t enPwmD)
 Enables/disables PWM for channel pairs.
void enablePwm (Motors motor, uint8_t enPwm)
 Enables/disables PWM for a given channel pair.
void enableBraking (uint8_t enBrakeA, uint8_t enBrakeB, uint8_t enBrakeC, uint8_t enBrakeD)
 Enables/disables braking for channel pairs.
void enableBraking (Motors motor, uint8_t enBrake)
 Enables/disables braking for given channel pair.
int forceBrake (uint8_t ch)
 Force a specific channel to GND without changing braking default Will fail if PWM is enabled on given channel.
int forceBrake (Motors motor)
 Force a specific motor (channel pair) to GND without changing braking default Will fail if PWM is disabled on given channel.
int forceFloat (uint8_t ch)
 Force a specific channel to float without changing braking default Will float both channels of a motor (channel pair) if PWM is enabled for the channel.
int forceFloat (Motors motor)
 Force a specific motor to float without changing braking default Will fail if PWM is disabled on given channel.
int drive (uint8_t state)
 Set all outputs with a single byte (bitwise control).
int drive (uint8_t ch, uint8_t on)
 Set the output of one channel.
float drive (Motors motor, float speed)
 Control the speed of a motor.
float drive (Motors motor, int8_t dir, float speed)
 Control the speed of a motor.
void diagnostic (TextLCD_I2C *lcd)
 Display diagnostic information on the LCD.
void setPWMperiod (float newPWMperiod)
 Change the PWM period.

Detailed Description

BridgeDriver class For controlling the Test Controller bridges.

Definition at line 28 of file BridgeDriver.h.


Member Enumeration Documentation

enum Motors

Channel pair labels.

MOTOR_A - Channel 1 and 2. MOTOR_B - Channel 3 and 4. MOTOR_C - Channel 5 and 6. MOTOR_D - Channel 7 and 8.

Definition at line 39 of file BridgeDriver.h.


Constructor & Destructor Documentation

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 
)

Create BridgeDriver object.

Enabling PWM for a channel pair links the channels so that they are controlled together. This should be used when connecting a motor between these channels. Disabling PWM for a channel pair allows individual on/off control for each channel.

MOTOR_A - Channel 1 and 2. MOTOR_B - Channel 3 and 4. MOTOR_C - Channel 5 and 6. MOTOR_D - Channel 7 and 8.

Parameters:
*i2cA pointer to the I2C bus that the Enable control and LED port expanders are on.
enPwmA(Optional) 1 enables PWM on channels 1 and 2 for motor control, 0 disables PWM on channels 1 and 2 for solenoid control. Defaults to 0.
enPwmB(Optional) 1 enables PWM on channels 3 and 4 for motor control, 0 disables PWM on channels 3 and 4 for solenoid control. Defaults to 0.
enPwmC(Optional) 1 enables PWM on channels 5 and 6 for motor control, 0 disables PWM on channels 5 and 6 for solenoid control. Defaults to 0.
enPwmD(Optional) 1 enables PWM on channels 7 and 8 for motor control, 0 disables PWM on channels 7 and 8 for solenoid control. Defaults to 0.
enAddr(Optional) Address of the Enable control port expander. May be necessary if not using a rev 1.0 board. TODO: update for rev 2.0.
ledAddr(Optional) Address of the LED control port expander. May be necessary if not using rev 1.0 or 2.0 board.

Definition at line 9 of file BridgeDriver.cpp.

~BridgeDriver (  )

Destroy BridgeDriver object.

Definition at line 54 of file BridgeDriver.cpp.


Member Function Documentation

void diagnostic ( TextLCD_I2C *  lcd )

Display diagnostic information on the LCD.

Parameters:
*lcdPointer to TextLCD object to display info on.

Definition at line 395 of file BridgeDriver.cpp.

int drive ( uint8_t  ch,
uint8_t  on 
)

Set the output of one channel.

Parameters:
chChannel to set.
onState to set. 1 drives high, 0 brakes (drives to GND) or floats depending on setting of enBrake.
Returns:
-1 on fauilure, 0 if set to 0, 1 if set to 1.

Definition at line 183 of file BridgeDriver.cpp.

float drive ( Motors  motor,
float  speed 
)

Control the speed of a motor.

Parameters:
motorMotor (channel pair) to control.
speedSpeed to set motor to. Acceptable range: -1.0 to 1.0. Speed of 0.0 will coast or brake depending on setting of enBrake.
Returns:
-1 on failure, speed of set output on success.

Definition at line 203 of file BridgeDriver.cpp.

int drive ( uint8_t  state )

Set all outputs with a single byte (bitwise control).

Will fail if PWM is enabled for any motor (channel pair).

Parameters:
stateSets all the outputs. Each bit controls one channel. 1 drives high, 0 brakes (drives to GND) or floats depending on setting of enBrake.
Returns:
-1 on failure, 0 if all outputs are set to 0, 1 if any output is set to 1.

Definition at line 160 of file BridgeDriver.cpp.

float drive ( Motors  motor,
int8_t  dir,
float  speed 
)

Control the speed of a motor.

Parameters:
motorMotor (channel pair) to control.
speedSpeed to set motor to. Acceptable range: 0.0 to 1.0. Speed of 0.0 will coast or brake depending on setting of enBrake.
dirSet direction to drive motor. 1: forward, -1: reverse, 0: brake, irregardless of setting of enBrake or speed.
Returns:
-1 on failure, speed of set output on success.

Definition at line 219 of file BridgeDriver.cpp.

void enableBraking ( Motors  motor,
uint8_t  enBrake 
)

Enables/disables braking for given channel pair.

Parameters:
enBrakeA1 drives output to GND when off, 0 floats output when off.

Definition at line 108 of file BridgeDriver.cpp.

void enableBraking ( uint8_t  enBrakeA,
uint8_t  enBrakeB,
uint8_t  enBrakeC,
uint8_t  enBrakeD 
)

Enables/disables braking for channel pairs.

Parameters:
enBrakeA1 drives output to GND when off, 0 floats output when off.
enBrakeB1 drives output to GND when off, 0 floats output when off.
enBrakeC1 drives output to GND when off, 0 floats output when off.
enBrakeD1 drives output to GND when off, 0 floats output when off.

Definition at line 101 of file BridgeDriver.cpp.

void enablePwm ( Motors  motor,
uint8_t  enPwm 
)

Enables/disables PWM for a given channel pair.

Enabling PWM for a channel pair links the channels so that they are controlled together. This should be used when connecting a motor between these channels. Disabling PWM for a channel pair allows individual on/off control for each channel.

MOTOR_A - Channel 1 and 2. MOTOR_B - Channel 3 and 4. MOTOR_C - Channel 5 and 6. MOTOR_D - Channel 7 and 8.

Parameters:
motorMotor (channel pair) to enale/disable PWM.
enPwm1 enables PWM on channel pair for motor control, 0 disables PWM on channel pair for solenoid control.

Definition at line 85 of file BridgeDriver.cpp.

void enablePwm ( uint8_t  enPwmA,
uint8_t  enPwmB,
uint8_t  enPwmC,
uint8_t  enPwmD 
)

Enables/disables PWM for channel pairs.

Enabling PWM for a channel pair links the channels so that they are controlled together. This should be used when connecting a motor between these channels. Disabling PWM for a channel pair allows individual on/off control for each channel.

MOTOR_A - Channel 1 and 2. MOTOR_B - Channel 3 and 4. MOTOR_C - Channel 5 and 6. MOTOR_D - Channel 7 and 8.

Parameters:
enPwmA1 enables PWM on channels 1 and 2 for motor control, 0 disables PWM on channels 1 and 2 for solenoid control.
enPwmB1 enables PWM on channels 3 and 4 for motor control, 0 disables PWM on channels 3 and 4 for solenoid control.
enPwmC1 enables PWM on channels 5 and 6 for motor control, 0 disables PWM on channels 5 and 6 for solenoid control.
enPwmD1 enables PWM on channels 7 and 8 for motor control, 0 disables PWM on channels 7 and 8 for solenoid control.

Definition at line 78 of file BridgeDriver.cpp.

int forceBrake ( uint8_t  ch )

Force a specific channel to GND without changing braking default Will fail if PWM is enabled on given channel.

Use forceBrake(Motors motor) to force braking on channels with PWM enabled.

Parameters:
chChannel to drive to GND
Returns:
0 on success, non 0 on failure.

Definition at line 112 of file BridgeDriver.cpp.

int forceBrake ( Motors  motor )

Force a specific motor (channel pair) to GND without changing braking default Will fail if PWM is disabled on given channel.

Use forceBrake(uint8_t ch) to force braking on channels with PWM disabled.

Parameters:
motorMotor (channel pair) to drive to GND
Returns:
0 on success, non 0 on failure.

Definition at line 123 of file BridgeDriver.cpp.

int forceFloat ( Motors  motor )

Force a specific motor to float without changing braking default Will fail if PWM is disabled on given channel.

Use forceFloat(uint8_t ch) to force floating on channels with PWM disabled.

Parameters:
motorMotor (channel pair) to float.
Returns:
0 on success, non 0 on failure.

Definition at line 144 of file BridgeDriver.cpp.

int forceFloat ( uint8_t  ch )

Force a specific channel to float without changing braking default Will float both channels of a motor (channel pair) if PWM is enabled for the channel.

Parameters:
chChannel to float.
Returns:
0 on success, non 0 on failure.

Definition at line 127 of file BridgeDriver.cpp.

void setPWMperiod ( float  newPWMperiod )

Change the PWM period.

Parameters:
newPWMperiodThe new PWM period. In seconds. System default is 0.0002 (5kHz). Changing to 50Hz in order to operate at a Servo Signal Frequency (50Hz = 20ms Period)

Definition at line 412 of file BridgeDriver.cpp.