okapi::HDriveModel class

Base classes

class ChassisModel
A version of the ReadOnlyChassisModel that also supports write methods, such as setting motor speed.

Constructors, destructors, conversion operators

HDriveModel(std::shared_ptr<AbstractMotor> ileftSideMotor, std::shared_ptr<AbstractMotor> irightSideMotor, std::shared_ptr<AbstractMotor> imiddleMotor, std::shared_ptr<ContinuousRotarySensor> ileftEnc, std::shared_ptr<ContinuousRotarySensor> irightEnc, std::shared_ptr<ContinuousRotarySensor> imiddleEnc, double imaxVelocity, double imaxVoltage)
Model for an h-drive (wheels parallel with robot's direction of motion, with an additional wheel perpendicular to those).

Public functions

void forward(double ispeed) override
Drive the robot forwards (using open-loop control).
void driveVector(double iySpeed, double izRotation) override
Drive the robot in an arc (using open-loop control).
void driveVectorVoltage(double iforwardSpeed, double iyaw) override
Drive the robot in an arc.
void rotate(double ispeed) override
Turn the robot clockwise (using open-loop control).
void stop() override
Stop the robot (set all the motors to 0).
void tank(double ileftSpeed, double irightSpeed, double ithreshold = 0) override
Drive the robot with a tank drive layout.
void arcade(double iforwardSpeed, double iyaw, double ithreshold = 0) override
Drive the robot with an arcade drive layout.
void curvature(double iforwardSpeed, double icurvature, double ithreshold = 0) override
Drive the robot with a curvature drive layout.
void hArcade(double irightSpeed, double iforwardSpeed, double iyaw, double ithreshold = 0) virtual
Drive the robot with an arcade drive layout.
void hCurvature(double irightSpeed, double iforwardSpeed, double icurvature, double ithreshold = 0) virtual
Drive the robot with an curvature drive layout.
void left(double ispeed) override
Power the left side motors.
void right(double ispeed) override
Power the right side motors.
void middle(double ispeed) virtual
Power the middle motors.
auto getSensorVals() const -> std::valarray<std::int32_t> override
Read the sensors.
void resetSensors() override
Reset the sensors to their zero point.
void setBrakeMode(AbstractMotor::brakeMode mode) override
Set the brake mode for each motor.
void setEncoderUnits(AbstractMotor::encoderUnits units) override
Set the encoder units for each motor.
void setGearing(AbstractMotor::gearset gearset) override
Set the gearset for each motor.
void setMaxVelocity(double imaxVelocity) override
Sets a new maximum velocity in RPM.
auto getMaxVelocity() const -> double override
void setMaxVoltage(double imaxVoltage) override
Sets a new maximum voltage in mV in the range [0-12000].
auto getMaxVoltage() const -> double override
auto getLeftSideMotor() const -> std::shared_ptr<AbstractMotor>
Returns the left side motor.
auto getRightSideMotor() const -> std::shared_ptr<AbstractMotor>
Returns the left side motor.
auto getMiddleMotor() const -> std::shared_ptr<AbstractMotor>

Protected variables

double maxVelocity
double maxVoltage
std::shared_ptr<AbstractMotor> leftSideMotor
std::shared_ptr<AbstractMotor> rightSideMotor
std::shared_ptr<AbstractMotor> middleMotor
std::shared_ptr<ContinuousRotarySensor> leftSensor
std::shared_ptr<ContinuousRotarySensor> rightSensor
std::shared_ptr<ContinuousRotarySensor> middleSensor

Function documentation

okapi::HDriveModel::HDriveModel(std::shared_ptr<AbstractMotor> ileftSideMotor, std::shared_ptr<AbstractMotor> irightSideMotor, std::shared_ptr<AbstractMotor> imiddleMotor, std::shared_ptr<ContinuousRotarySensor> ileftEnc, std::shared_ptr<ContinuousRotarySensor> irightEnc, std::shared_ptr<ContinuousRotarySensor> imiddleEnc, double imaxVelocity, double imaxVoltage)

Model for an h-drive (wheels parallel with robot's direction of motion, with an additional wheel perpendicular to those).

Parameters
ileftSideMotor The left side motor.
irightSideMotor The right side motor.
imiddleMotor The middle (perpendicular) motor.
ileftEnc The left side encoder.
irightEnc The right side encoder.
imiddleEnc The middle encoder.
imaxVelocity
imaxVoltage

When the left and right side motors are powered +100%, the robot should move forward in a straight line. When the middle motor is powered +100%, the robot should strafe right in a straight line.

void okapi::HDriveModel::forward(double ispeed) override

Drive the robot forwards (using open-loop control).

Parameters
ispeed motor power

Uses velocity mode. Sets the middle motor to zero velocity.

void okapi::HDriveModel::driveVector(double iySpeed, double izRotation) override

Drive the robot in an arc (using open-loop control).

Parameters
iySpeed speed on y axis (forward)
izRotation speed around z axis (up)

Uses velocity mode. Sets the middle motor to zero velocity.

The algorithm is (approximately): leftPower = ySpeed + zRotation rightPower = ySpeed - zRotation

void okapi::HDriveModel::driveVectorVoltage(double iforwardSpeed, double iyaw) override

Drive the robot in an arc.

Parameters
iforwardSpeed
iyaw speed around the vertical axis

Uses voltage mode. Sets the middle motor to zero velocity.

The algorithm is (approximately): leftPower = forwardSpeed + yaw rightPower = forwardSpeed - yaw

void okapi::HDriveModel::rotate(double ispeed) override

Turn the robot clockwise (using open-loop control).

Parameters
ispeed motor power

Uses velocity mode. Sets the middle motor to zero velocity.

void okapi::HDriveModel::stop() override

Stop the robot (set all the motors to 0).

Uses velocity mode.

void okapi::HDriveModel::tank(double ileftSpeed, double irightSpeed, double ithreshold = 0) override

Drive the robot with a tank drive layout.

Parameters
ileftSpeed left side speed
irightSpeed right side speed
ithreshold deadband on joystick values

Uses voltage mode. Sets the middle motor to zero velocity.

void okapi::HDriveModel::arcade(double iforwardSpeed, double iyaw, double ithreshold = 0) override

Drive the robot with an arcade drive layout.

Parameters
iforwardSpeed speed in the forward direction
iyaw speed around the vertical axis
ithreshold deadband on joystick values

Uses voltage mode. Sets the middle motor to zero velocity.

void okapi::HDriveModel::curvature(double iforwardSpeed, double icurvature, double ithreshold = 0) override

Drive the robot with a curvature drive layout.

Parameters
iforwardSpeed speed in the forward direction
icurvature curvature (inverse of radius) to drive in
ithreshold deadband on joystick values

The robot drives in constant radius turns where you control the curvature (inverse of radius) you drive in. This is advantageous because the forward speed will not affect the rate of turning. The algorithm switches to arcade if the forward speed is 0. Uses voltage mode. Sets the middle motor to zero velocity.

void okapi::HDriveModel::hArcade(double irightSpeed, double iforwardSpeed, double iyaw, double ithreshold = 0) virtual

Drive the robot with an arcade drive layout.

Parameters
irightSpeed speed to the right
iforwardSpeed speed in the forward direction
iyaw speed around the vertical axis
ithreshold deadband on joystick values

Uses voltage mode.

void okapi::HDriveModel::hCurvature(double irightSpeed, double iforwardSpeed, double icurvature, double ithreshold = 0) virtual

Drive the robot with an curvature drive layout.

Parameters
irightSpeed speed to the right
iforwardSpeed speed in the forward direction
icurvature curvature (inverse of radius) to drive in
ithreshold deadband on joystick values

Uses voltage mode.

void okapi::HDriveModel::left(double ispeed) override

Power the left side motors.

Parameters
ispeed The motor power.

Uses velocity mode.

void okapi::HDriveModel::right(double ispeed) override

Power the right side motors.

Parameters
ispeed The motor power.

Uses velocity mode.

void okapi::HDriveModel::middle(double ispeed) virtual

Power the middle motors.

Parameters
ispeed The motor power.

Uses velocity mode.

std::valarray<std::int32_t> okapi::HDriveModel::getSensorVals() const override

Read the sensors.

Returns sensor readings in the format {left, right, middle}

void okapi::HDriveModel::setBrakeMode(AbstractMotor::brakeMode mode) override

Set the brake mode for each motor.

Parameters
mode new brake mode

void okapi::HDriveModel::setEncoderUnits(AbstractMotor::encoderUnits units) override

Set the encoder units for each motor.

Parameters
units new motor encoder units

void okapi::HDriveModel::setGearing(AbstractMotor::gearset gearset) override

Set the gearset for each motor.

Parameters
gearset new motor gearset

void okapi::HDriveModel::setMaxVelocity(double imaxVelocity) override

Sets a new maximum velocity in RPM.

Parameters
imaxVelocity The new maximum velocity.

The usable maximum depends on the maximum velocity of the currently installed gearset. If the configured maximum velocity is greater than the attainable maximum velocity from the currently installed gearset, the ChassisModel will still scale to that velocity.

double okapi::HDriveModel::getMaxVelocity() const override

Returns The current maximum velocity.

void okapi::HDriveModel::setMaxVoltage(double imaxVoltage) override

Sets a new maximum voltage in mV in the range [0-12000].

Parameters
imaxVoltage The new maximum voltage.

double okapi::HDriveModel::getMaxVoltage() const override

Returns The maximum voltage in mV in the range [0-12000].

std::shared_ptr<AbstractMotor> okapi::HDriveModel::getLeftSideMotor() const

Returns the left side motor.

Returns the left side motor

std::shared_ptr<AbstractMotor> okapi::HDriveModel::getRightSideMotor() const

Returns the left side motor.

Returns the left side motor

std::shared_ptr<AbstractMotor> okapi::HDriveModel::getMiddleMotor() const

Returns The middle motor.