LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
Loading...
Searching...
No Matches
okapi::XDriveModel Class Reference

#include <xDriveModel.hpp>

Inheritance diagram for okapi::XDriveModel:
okapi::ChassisModel okapi::ReadOnlyChassisModel okapi::ThreeEncoderXDriveModel

Public Member Functions

 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).
 
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.
 
virtual void xArcade (double irightSpeed, double iforwardSpeed, double iyaw, double ithreshold=0)
 Drive the robot with an arcade drive layout.
 
virtual void fieldOrientedXArcade (double ixSpeed, double iySpeed, double iyaw, QAngle iangle, double ithreshold=0)
 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.
 
std::valarray< std::int32_t > getSensorVals () const 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.
 
double getMaxVelocity () const override
 
void setMaxVoltage (double imaxVoltage) override
 Sets a new maximum voltage in mV in the range [0-12000].
 
double getMaxVoltage () const override
 
std::shared_ptr< AbstractMotorgetTopLeftMotor () const
 Returns the top left motor.
 
std::shared_ptr< AbstractMotorgetTopRightMotor () const
 Returns the top right motor.
 
std::shared_ptr< AbstractMotorgetBottomRightMotor () const
 Returns the bottom right motor.
 
std::shared_ptr< AbstractMotorgetBottomLeftMotor () const
 Returns the bottom left motor.
 
- Public Member Functions inherited from okapi::ChassisModel
 ChassisModel ()=default
 
 ChassisModel (const ChassisModel &)=delete
 
ChassisModeloperator= (const ChassisModel &)=delete
 
- Public Member Functions inherited from okapi::ReadOnlyChassisModel
virtual ~ReadOnlyChassisModel ()=default
 

Protected Attributes

double maxVelocity
 
double maxVoltage
 
std::shared_ptr< AbstractMotortopLeftMotor
 
std::shared_ptr< AbstractMotortopRightMotor
 
std::shared_ptr< AbstractMotorbottomRightMotor
 
std::shared_ptr< AbstractMotorbottomLeftMotor
 
std::shared_ptr< ContinuousRotarySensorleftSensor
 
std::shared_ptr< ContinuousRotarySensorrightSensor
 

Detailed Description

Definition at line 14 of file xDriveModel.hpp.

Constructor & Destructor Documentation

◆ XDriveModel()

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).

When all motors are powered +100%, the robot should move forward in a straight line.

Parameters
itopLeftMotorThe top left motor.
itopRightMotorThe top right motor.
ibottomRightMotorThe bottom right motor.
ibottomLeftMotorThe bottom left motor.
ileftEncThe left side encoder.
irightEncThe right side encoder.

Member Function Documentation

◆ arcade()

void okapi::XDriveModel::arcade ( double  iforwardSpeed,
double  iyaw,
double  ithreshold = 0 
)
overridevirtual

Drive the robot with an arcade drive layout.

Uses voltage mode.

Parameters
iforwardSpeedspeed in the forward direction
iyawspeed around the vertical axis
ithresholddeadband on joystick values

Implements okapi::ChassisModel.

◆ curvature()

void okapi::XDriveModel::curvature ( double  iforwardSpeed,
double  icurvature,
double  ithreshold = 0 
)
overridevirtual

Drive the robot with a curvature drive layout.

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.

Parameters
iforwardSpeedspeed forward direction
icurvaturecurvature (inverse of radius) to drive in
ithresholddeadband on joystick values

Implements okapi::ChassisModel.

◆ driveVector()

void okapi::XDriveModel::driveVector ( double  iforwardSpeed,
double  iyaw 
)
overridevirtual

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

Uses velocity mode. The algorithm is (approximately): leftPower = forwardSpeed + yaw rightPower = forwardSpeed - yaw

Parameters
iforwardSpeedspeed in the forward direction
iyawspeed around the vertical axis

Implements okapi::ChassisModel.

◆ driveVectorVoltage()

void okapi::XDriveModel::driveVectorVoltage ( double  iforwardSpeed,
double  iyaw 
)
overridevirtual

Drive the robot in an arc.

Uses voltage mode. The algorithm is (approximately): leftPower = forwardSpeed + yaw rightPower = forwardSpeed - yaw

Parameters
iforwadSpeedspeed in the forward direction
iyawspeed around the vertical axis

Implements okapi::ChassisModel.

◆ fieldOrientedXArcade()

virtual 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.

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.

Parameters
ixSpeedforward speed – (+1) forward, (-1) backward
iySpeedsideways speed – (+1) right, (-1) left
iyawturn speed – (+1) clockwise, (-1) counter-clockwise
ianglecurrent chassis angle (0_deg = no correction, winds clockwise)
ithresholddeadband on joystick values

◆ forward()

void okapi::XDriveModel::forward ( double  ipower)
overridevirtual

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

Uses velocity mode.

Parameters
ispeedmotor power

Implements okapi::ChassisModel.

◆ getBottomLeftMotor()

std::shared_ptr< AbstractMotor > okapi::XDriveModel::getBottomLeftMotor ( ) const

Returns the bottom left motor.

Returns
the bottom left motor

◆ getBottomRightMotor()

std::shared_ptr< AbstractMotor > okapi::XDriveModel::getBottomRightMotor ( ) const

Returns the bottom right motor.

Returns
the bottom right motor

◆ getMaxVelocity()

double okapi::XDriveModel::getMaxVelocity ( ) const
overridevirtual
Returns
The current maximum velocity.

Implements okapi::ChassisModel.

◆ getMaxVoltage()

double okapi::XDriveModel::getMaxVoltage ( ) const
overridevirtual
Returns
The maximum voltage in mV in the range [0-12000].

Implements okapi::ChassisModel.

◆ getSensorVals()

std::valarray< std::int32_t > okapi::XDriveModel::getSensorVals ( ) const
overridevirtual

Read the sensors.

Returns
sensor readings in the format {left, right}

Implements okapi::ReadOnlyChassisModel.

◆ getTopLeftMotor()

std::shared_ptr< AbstractMotor > okapi::XDriveModel::getTopLeftMotor ( ) const

Returns the top left motor.

Returns
the top left motor

◆ getTopRightMotor()

std::shared_ptr< AbstractMotor > okapi::XDriveModel::getTopRightMotor ( ) const

Returns the top right motor.

Returns
the top right motor

◆ left()

void okapi::XDriveModel::left ( double  ispeed)
overridevirtual

Power the left side motors.

Uses velocity mode.

Parameters
ispeedThe motor power.

Implements okapi::ChassisModel.

◆ resetSensors()

void okapi::XDriveModel::resetSensors ( )
overridevirtual

Reset the sensors to their zero point.

Implements okapi::ChassisModel.

◆ right()

void okapi::XDriveModel::right ( double  ispeed)
overridevirtual

Power the right side motors.

Uses velocity mode.

Parameters
ispeedThe motor power.

Implements okapi::ChassisModel.

◆ rotate()

void okapi::XDriveModel::rotate ( double  ipower)
overridevirtual

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

Uses velocity mode.

Parameters
ipowermotor power

Implements okapi::ChassisModel.

◆ setBrakeMode()

void okapi::XDriveModel::setBrakeMode ( AbstractMotor::brakeMode  mode)
overridevirtual

Set the brake mode for each motor.

Parameters
modenew brake mode

Implements okapi::ChassisModel.

◆ setEncoderUnits()

void okapi::XDriveModel::setEncoderUnits ( AbstractMotor::encoderUnits  units)
overridevirtual

Set the encoder units for each motor.

Parameters
unitsnew motor encoder units

Implements okapi::ChassisModel.

◆ setGearing()

void okapi::XDriveModel::setGearing ( AbstractMotor::gearset  gearset)
overridevirtual

Set the gearset for each motor.

Parameters
gearsetnew motor gearset

Implements okapi::ChassisModel.

◆ setMaxVelocity()

void okapi::XDriveModel::setMaxVelocity ( double  imaxVelocity)
overridevirtual

Sets a new maximum velocity in RPM.

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.

Parameters
imaxVelocityThe new maximum velocity.

Implements okapi::ChassisModel.

◆ setMaxVoltage()

void okapi::XDriveModel::setMaxVoltage ( double  imaxVoltage)
overridevirtual

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

Parameters
imaxVoltageThe new maximum voltage.

Implements okapi::ChassisModel.

◆ stop()

void okapi::XDriveModel::stop ( )
overridevirtual

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

Uses velocity mode.

Implements okapi::ChassisModel.

◆ strafe()

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.

Parameters
ispeedmotor power

◆ strafeVector()

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.

Uses velocity mode. The algorithm is (approximately): topLeftPower = -1 * istrafeSpeed + yaw topRightPower = istrafeSpeed - yaw bottomRightPower = -1 * istrafeSpeed - yaw bottomLeftPower = istrafeSpeed + yaw

Parameters
istrafeSpeedspeed to the right
iyawspeed around the vertical axis

◆ tank()

void okapi::XDriveModel::tank ( double  ileftSpeed,
double  irightSpeed,
double  ithreshold = 0 
)
overridevirtual

Drive the robot with a tank drive layout.

Uses voltage mode.

Parameters
ileftSpeedleft side speed
irightSpeedright side speed
ithresholddeadband on joystick values

Implements okapi::ChassisModel.

◆ xArcade()

virtual void okapi::XDriveModel::xArcade ( double  irightSpeed,
double  iforwardSpeed,
double  iyaw,
double  ithreshold = 0 
)
virtual

Drive the robot with an arcade drive layout.

Uses voltage mode.

Parameters
irightSpeedspeed to the right
iforwardSpeedspeed in the forward direction
iyawspeed around the vertical axis
ithresholddeadband on joystick values

Member Data Documentation

◆ bottomLeftMotor

std::shared_ptr<AbstractMotor> okapi::XDriveModel::bottomLeftMotor
protected

Definition at line 269 of file xDriveModel.hpp.

◆ bottomRightMotor

std::shared_ptr<AbstractMotor> okapi::XDriveModel::bottomRightMotor
protected

Definition at line 268 of file xDriveModel.hpp.

◆ leftSensor

std::shared_ptr<ContinuousRotarySensor> okapi::XDriveModel::leftSensor
protected

Definition at line 270 of file xDriveModel.hpp.

◆ maxVelocity

double okapi::XDriveModel::maxVelocity
protected

Definition at line 264 of file xDriveModel.hpp.

◆ maxVoltage

double okapi::XDriveModel::maxVoltage
protected

Definition at line 265 of file xDriveModel.hpp.

◆ rightSensor

std::shared_ptr<ContinuousRotarySensor> okapi::XDriveModel::rightSensor
protected

Definition at line 271 of file xDriveModel.hpp.

◆ topLeftMotor

std::shared_ptr<AbstractMotor> okapi::XDriveModel::topLeftMotor
protected

Definition at line 266 of file xDriveModel.hpp.

◆ topRightMotor

std::shared_ptr<AbstractMotor> okapi::XDriveModel::topRightMotor
protected

Definition at line 267 of file xDriveModel.hpp.


The documentation for this class was generated from the following file: