class
XDriveModel
Contents
Base classes
- class ChassisModel
- A version of the ReadOnlyChassisModel that also supports write methods, such as setting motor speed.
Derived classes
- class ThreeEncoderXDriveModel
Constructors, destructors, conversion operators
- XDriveModel(std::shared_ptr<AbstractMotor> itopLeftMotor, std::shared_ptr<AbstractMotor> itopRightMotor, std::shared_ptr<AbstractMotor> ibottomRightMotor, std::shared_ptr<AbstractMotor> ibottomLeftMotor, std::shared_ptr<ContinuousRotarySensor> ileftEnc, std::shared_ptr<ContinuousRotarySensor> irightEnc, double imaxVelocity, double imaxVoltage)
- Model for an x drive (wheels at 45 deg from a skid steer drive).
Public functions
- void forward(double ipower) override
- Drive the robot forwards (using open-loop control).
- void driveVector(double iforwardSpeed, double iyaw) 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 ipower) override
- Turn the robot clockwise (using open-loop control).
- void strafe(double ipower)
- Drive the robot side-ways (using open-loop control) where positive ipower is to the right and negative ipower is to the left.
- void strafeVector(double istrafeSpeed, double iyaw)
- Strafe the robot in an arc (using open-loop control) where positive istrafeSpeed is to the right and negative istrafeSpeed is to the left.
- 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 xArcade(double irightSpeed, double iforwardSpeed, double iyaw, double ithreshold = 0) virtual
- Drive the robot with an arcade drive layout.
- void fieldOrientedXArcade(double ixSpeed, double iySpeed, double iyaw, QAngle iangle, double ithreshold = 0) virtual
- Drive the robot with a field-oriented arcade drive layout.
- void left(double ispeed) override
- Power the left side motors.
- void right(double ispeed) override
- Power the right side 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 getTopLeftMotor() const -> std::shared_ptr<AbstractMotor>
- Returns the top left motor.
- auto getTopRightMotor() const -> std::shared_ptr<AbstractMotor>
- Returns the top right motor.
- auto getBottomRightMotor() const -> std::shared_ptr<AbstractMotor>
- Returns the bottom right motor.
- auto getBottomLeftMotor() const -> std::shared_ptr<AbstractMotor>
- Returns the bottom left motor.
Protected variables
- double maxVelocity
- double maxVoltage
- std::shared_ptr<AbstractMotor> topLeftMotor
- std::shared_ptr<AbstractMotor> topRightMotor
- std::shared_ptr<AbstractMotor> bottomRightMotor
- std::shared_ptr<AbstractMotor> bottomLeftMotor
- std::shared_ptr<ContinuousRotarySensor> leftSensor
- std::shared_ptr<ContinuousRotarySensor> rightSensor
Function documentation
okapi:: XDriveModel:: XDriveModel(std::shared_ptr<AbstractMotor> itopLeftMotor,
std::shared_ptr<AbstractMotor> itopRightMotor,
std::shared_ptr<AbstractMotor> ibottomRightMotor,
std::shared_ptr<AbstractMotor> ibottomLeftMotor,
std::shared_ptr<ContinuousRotarySensor> ileftEnc,
std::shared_ptr<ContinuousRotarySensor> irightEnc,
double imaxVelocity,
double imaxVoltage)
Model for an x drive (wheels at 45 deg from a skid steer drive).
Parameters | |
---|---|
itopLeftMotor | The top left motor. |
itopRightMotor | The top right motor. |
ibottomRightMotor | The bottom right motor. |
ibottomLeftMotor | The bottom left motor. |
ileftEnc | The left side encoder. |
irightEnc | The right side encoder. |
imaxVelocity | |
imaxVoltage |
When all motors are powered +100%, the robot should move forward in a straight line.
void okapi:: XDriveModel:: forward(double ipower) override
Drive the robot forwards (using open-loop control).
Uses velocity mode.
void okapi:: XDriveModel:: driveVector(double iforwardSpeed,
double iyaw) override
Drive the robot in an arc (using open-loop control).
Parameters | |
---|---|
iforwardSpeed | speed in the forward direction |
iyaw | speed around the vertical axis |
Uses velocity mode. The algorithm is (approximately): leftPower = forwardSpeed + yaw rightPower = forwardSpeed - yaw
void okapi:: XDriveModel:: driveVectorVoltage(double iforwardSpeed,
double iyaw) override
Drive the robot in an arc.
Parameters | |
---|---|
iforwardSpeed | |
iyaw | speed around the vertical axis |
Uses voltage mode. The algorithm is (approximately): leftPower = forwardSpeed + yaw rightPower = forwardSpeed - yaw
void okapi:: XDriveModel:: rotate(double ipower) override
Turn the robot clockwise (using open-loop control).
Parameters | |
---|---|
ipower | motor power |
Uses velocity mode.
void okapi:: XDriveModel:: strafe(double ipower)
Drive the robot side-ways (using open-loop control) where positive ipower is to the right and negative ipower is to the left.
Uses velocity mode.
void okapi:: XDriveModel:: strafeVector(double istrafeSpeed,
double iyaw)
Strafe the robot in an arc (using open-loop control) where positive istrafeSpeed is to the right and negative istrafeSpeed is to the left.
Parameters | |
---|---|
istrafeSpeed | speed to the right |
iyaw | speed around the vertical axis |
Uses velocity mode. The algorithm is (approximately): topLeftPower = -1 * istrafeSpeed + yaw topRightPower = istrafeSpeed - yaw bottomRightPower = -1 * istrafeSpeed - yaw bottomLeftPower = istrafeSpeed + yaw
void okapi:: XDriveModel:: stop() override
Stop the robot (set all the motors to 0).
Uses velocity mode.
void okapi:: XDriveModel:: 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.
void okapi:: XDriveModel:: 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.
void okapi:: XDriveModel:: curvature(double iforwardSpeed,
double icurvature,
double ithreshold = 0) override
Drive the robot with a curvature drive layout.
Parameters | |
---|---|
iforwardSpeed | speed 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.
void okapi:: XDriveModel:: xArcade(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:: XDriveModel:: fieldOrientedXArcade(double ixSpeed,
double iySpeed,
double iyaw,
QAngle iangle,
double ithreshold = 0) virtual
Drive the robot with a field-oriented arcade drive layout.
Parameters | |
---|---|
ixSpeed | forward speed – (+1 ) forward, (-1 ) backward |
iySpeed | sideways speed – (+1 ) right, (-1 ) left |
iyaw | turn speed – (+1 ) clockwise, (-1 ) counter-clockwise |
iangle | current chassis angle (0_deg = no correction, winds clockwise) |
ithreshold | deadband on joystick values |
Uses voltage mode. For example: Both fieldOrientedXArcade(1, 0, 0, 0_deg)
and fieldOrientedXArcade(1, 0, 0, 90_deg)
will drive the chassis in the forward/north direction. In other words, no matter the robot's heading, the robot will move forward/north when you tell it to move forward/north and will move right/east when you tell it to move right/east.
void okapi:: XDriveModel:: left(double ispeed) override
Power the left side motors.
Parameters | |
---|---|
ispeed | The motor power. |
Uses velocity mode.
void okapi:: XDriveModel:: right(double ispeed) override
Power the right side motors.
Parameters | |
---|---|
ispeed | The motor power. |
Uses velocity mode.
std::valarray<std::int32_t> okapi:: XDriveModel:: getSensorVals() const override
Read the sensors.
Returns | sensor readings in the format {left, right} |
---|
void okapi:: XDriveModel:: setBrakeMode(AbstractMotor:: brakeMode mode) override
Set the brake mode for each motor.
Parameters | |
---|---|
mode | new brake mode |
void okapi:: XDriveModel:: setEncoderUnits(AbstractMotor:: encoderUnits units) override
Set the encoder units for each motor.
Parameters | |
---|---|
units | new motor encoder units |
void okapi:: XDriveModel:: setGearing(AbstractMotor:: gearset gearset) override
Set the gearset for each motor.
Parameters | |
---|---|
gearset | new motor gearset |
void okapi:: XDriveModel:: 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:: XDriveModel:: getMaxVelocity() const override
Returns | The current maximum velocity. |
---|
void okapi:: XDriveModel:: setMaxVoltage(double imaxVoltage) override
Sets a new maximum voltage in mV in the range [0-12000]
.
Parameters | |
---|---|
imaxVoltage | The new maximum voltage. |
double okapi:: XDriveModel:: getMaxVoltage() const override
Returns | The maximum voltage in mV in the range [0-12000] . |
---|
std::shared_ptr<AbstractMotor> okapi:: XDriveModel:: getTopLeftMotor() const
Returns the top left motor.
Returns | the top left motor |
---|
std::shared_ptr<AbstractMotor> okapi:: XDriveModel:: getTopRightMotor() const
Returns the top right motor.
Returns | the top right motor |
---|
std::shared_ptr<AbstractMotor> okapi:: XDriveModel:: getBottomRightMotor() const
Returns the bottom right motor.
Returns | the bottom right motor |
---|
std::shared_ptr<AbstractMotor> okapi:: XDriveModel:: getBottomLeftMotor() const
Returns the bottom left motor.
Returns | the bottom left motor |
---|