Add ability to drive the wheels with direct pwm duty
This commit is contained in:
parent
4432e3cca3
commit
3906d7954d
2 changed files with 29 additions and 0 deletions
|
@ -191,6 +191,14 @@ namespace create {
|
||||||
*/
|
*/
|
||||||
bool driveWheels(const float& leftWheel, const float& rightWheel);
|
bool driveWheels(const float& leftWheel, const float& rightWheel);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Set the direct for the left and right wheels.
|
||||||
|
* \param leftWheel pwm in the range [-1, 1]
|
||||||
|
* \param rightWheel pwm in the range [-1, 1]
|
||||||
|
* \return true if successful, false otherwise
|
||||||
|
*/
|
||||||
|
bool driveWheelsPwm(const float& leftWheel, const float& rightWheel);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Set the forward and angular velocity of Create.
|
* \brief Set the forward and angular velocity of Create.
|
||||||
* \param xVel in m/s
|
* \param xVel in m/s
|
||||||
|
|
|
@ -424,6 +424,27 @@ namespace create {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Create::driveWheelsPwm(const float& leftWheel, const float& rightWheel)
|
||||||
|
{
|
||||||
|
static const int16_t PWM_COUNTS = 255;
|
||||||
|
|
||||||
|
if (leftWheel < -1.0 || leftWheel > 1.0 ||
|
||||||
|
rightWheel < -1.0 || rightWheel > 1.0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int16_t leftPwm = roundf(leftWheel * PWM_COUNTS);
|
||||||
|
int16_t rightPwm = roundf(rightWheel * PWM_COUNTS);
|
||||||
|
|
||||||
|
uint8_t cmd[5] = { OC_DRIVE_PWM,
|
||||||
|
rightPwm >> 8,
|
||||||
|
rightPwm & 0xff,
|
||||||
|
leftPwm >> 8,
|
||||||
|
leftPwm & 0xff
|
||||||
|
};
|
||||||
|
|
||||||
|
return serial->send(cmd, 5);
|
||||||
|
}
|
||||||
|
|
||||||
bool Create::drive(const float& xVel, const float& angularVel) {
|
bool Create::drive(const float& xVel, const float& angularVel) {
|
||||||
// Compute left and right wheel velocities
|
// Compute left and right wheel velocities
|
||||||
float leftVel = xVel - ((model.getAxleLength() / 2.0) * angularVel);
|
float leftVel = xVel - ((model.getAxleLength() / 2.0) * angularVel);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue