grovemd: allow seperate directions for each DC motor

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Jon Trulson
2015-03-18 12:20:19 -06:00
committed by Mihai Tudor Panu
parent d380658b40
commit 970d6a083f
4 changed files with 24 additions and 15 deletions

View File

@ -108,12 +108,13 @@ bool GroveMD::setPWMFrequencyPrescale(uint8_t freq)
return writePacket(SET_PWM_FREQ, freq, GROVEMD_NOOP);
}
bool GroveMD::setDirection(DIRECTION_T dir)
bool GroveMD::setMotorDirections(DC_DIRECTION_T dirA, DC_DIRECTION_T dirB)
{
uint8_t dir = ((dirB & 0x03) << 2) | (dirA & 0x03);
return writePacket(SET_DIRECTION, dir, GROVEMD_NOOP);
}
bool GroveMD::enableStepper(DIRECTION_T dir, uint8_t speed)
bool GroveMD::enableStepper(STEP_DIRECTION_T dir, uint8_t speed)
{
return writePacket(STEPPER_ENABLE, dir, speed);
}

View File

@ -79,10 +79,15 @@ namespace upm {
STEPPER_NUM_STEPS = 0x1c
} REG_T;
// legal directions
typedef enum { DIR_CCW = 0x0a,
DIR_CW = 0x05
} DIRECTION_T;
// legal directions for the stepper
typedef enum { STEP_DIR_CCW = 0x0a,
STEP_DIR_CW = 0x05
} STEP_DIRECTION_T;
// legal directions for individual DC motors
typedef enum { DIR_CCW = 0x02,
DIR_CW = 0x01
} DC_DIRECTION_T;
/**
* grovemd constructor
@ -130,22 +135,23 @@ namespace upm {
bool setPWMFrequencyPrescale(uint8_t freq=0x03);
/**
* For controlling DC motors, set the direction
* For controlling DC motors, set the directions of motors A & B
*
* @param dir direction, CW or CCW
* @param dirA direction for motor A, DIR_CW or DIR_CCW
* @param dirB direction for motor B, DIR_CW or DIR_CCW
* @return true if command successful
*/
bool setDirection(DIRECTION_T dir);
bool setMotorDirections(DC_DIRECTION_T dirA, DC_DIRECTION_T dirB);
/**
* For controlling a stepper motor, set a direction, speed and
* then enable.
*
* @param dir direction, CW or CCW
* @param dir direction, STEP_DIR_CW or STEP_DIR_CCW
* @param speed motor speed. Valid range is 1-255, higher is slower.
* @return true if command successful
*/
bool enableStepper(DIRECTION_T dir, uint8_t speed);
bool enableStepper(STEP_DIRECTION_T dir, uint8_t speed);
/**
* For controlling a stepper motor, stop the stepper motor.