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

#include <chassisControllerPid.hpp>

Inheritance diagram for okapi::ChassisControllerPID:
okapi::ChassisController

Public Member Functions

 ChassisControllerPID (TimeUtil itimeUtil, std::shared_ptr< ChassisModel > imodel, std::unique_ptr< IterativePosPIDController > idistanceController, std::unique_ptr< IterativePosPIDController > iturnController, std::unique_ptr< IterativePosPIDController > iangleController, const AbstractMotor::GearsetRatioPair &igearset=AbstractMotor::gearset::green, const ChassisScales &iscales=ChassisScales({1, 1}, imev5GreenTPR), std::shared_ptr< Logger > ilogger=Logger::getDefaultLogger())
 ChassisController using PID control.
 
 ChassisControllerPID (const ChassisControllerPID &)=delete
 
 ChassisControllerPID (ChassisControllerPID &&other)=delete
 
ChassisControllerPIDoperator= (const ChassisControllerPID &other)=delete
 
ChassisControllerPIDoperator= (ChassisControllerPID &&other)=delete
 
 ~ChassisControllerPID () override
 
void moveDistance (QLength itarget) override
 Drives the robot straight for a distance (using closed-loop control).
 
void moveRaw (double itarget) override
 Drives the robot straight for a distance (using closed-loop control).
 
void moveDistanceAsync (QLength itarget) override
 Sets the target distance for the robot to drive straight (using closed-loop control).
 
void moveRawAsync (double itarget) override
 Sets the target distance for the robot to drive straight (using closed-loop control).
 
void turnAngle (QAngle idegTarget) override
 Turns the robot clockwise in place (using closed-loop control).
 
void turnRaw (double idegTarget) override
 Turns the robot clockwise in place (using closed-loop control).
 
void turnAngleAsync (QAngle idegTarget) override
 Sets the target angle for the robot to turn clockwise in place (using closed-loop control).
 
void turnRawAsync (double idegTarget) override
 Sets the target angle for the robot to turn clockwise in place (using closed-loop control).
 
void setTurnsMirrored (bool ishouldMirror) override
 Sets whether turns should be mirrored.
 
bool isSettled () override
 Checks whether the internal controllers are currently settled.
 
void waitUntilSettled () override
 Delays until the currently executing movement completes.
 
ChassisScales getChassisScales () const override
 Gets the ChassisScales.
 
AbstractMotor::GearsetRatioPair getGearsetRatioPair () const override
 Gets the GearsetRatioPair.
 
void setVelocityMode (bool ivelocityMode)
 Sets the velocity mode flag.
 
void setGains (const IterativePosPIDController::Gains &idistanceGains, const IterativePosPIDController::Gains &iturnGains, const IterativePosPIDController::Gains &iangleGains)
 Sets the gains for all controllers.
 
std::tuple< IterativePosPIDController::Gains, IterativePosPIDController::Gains, IterativePosPIDController::GainsgetGains () const
 Gets the current controller gains.
 
void startThread ()
 Starts the internal thread.
 
CrossplatformThreadgetThread () const
 Returns the underlying thread handle.
 
void stop () override
 Interrupts the current movement to stop the robot.
 
void setMaxVelocity (double imaxVelocity) override
 Sets a new maximum velocity in RPM [0-600].
 
double getMaxVelocity () const override
 
std::shared_ptr< ChassisModelgetModel () override
 
ChassisModelmodel () override
 
- Public Member Functions inherited from okapi::ChassisController
 ChassisController ()=default
 A ChassisController adds a closed-loop layer on top of a ChassisModel.
 
virtual ~ChassisController ()=default
 

Protected Types

enum  modeType { distance , angle , none }
 

Protected Member Functions

void loop ()
 
bool waitForDistanceSettled ()
 Wait for the distance setup (distancePid and anglePid) to settle.
 
bool waitForAngleSettled ()
 Wait for the angle setup (anglePid) to settle.
 
void stopAfterSettled ()
 Stops all the controllers and the ChassisModel.
 

Static Protected Member Functions

static void trampoline (void *context)
 

Protected Attributes

std::shared_ptr< Loggerlogger
 
bool normalTurns {true}
 
std::shared_ptr< ChassisModelchassisModel
 
TimeUtil timeUtil
 
std::unique_ptr< IterativePosPIDControllerdistancePid
 
std::unique_ptr< IterativePosPIDControllerturnPid
 
std::unique_ptr< IterativePosPIDControlleranglePid
 
ChassisScales scales
 
AbstractMotor::GearsetRatioPair gearsetRatioPair
 
bool velocityMode {true}
 
std::atomic_bool doneLooping {true}
 
std::atomic_bool doneLoopingSeen {true}
 
std::atomic_bool newMovement {false}
 
std::atomic_bool dtorCalled {false}
 
QTime threadSleepTime {10_ms}
 
modeType mode {none}
 
CrossplatformThreadtask {nullptr}
 

Detailed Description

Definition at line 18 of file chassisControllerPid.hpp.

Member Enumeration Documentation

◆ modeType

Enumerator
distance 
angle 
none 

Definition at line 270 of file chassisControllerPid.hpp.

Constructor & Destructor Documentation

◆ ChassisControllerPID() [1/3]

okapi::ChassisControllerPID::ChassisControllerPID ( TimeUtil  itimeUtil,
std::shared_ptr< ChassisModel imodel,
std::unique_ptr< IterativePosPIDController idistanceController,
std::unique_ptr< IterativePosPIDController iturnController,
std::unique_ptr< IterativePosPIDController iangleController,
const AbstractMotor::GearsetRatioPair igearset = AbstractMotor::gearset::green,
const ChassisScales iscales = ChassisScales({1, 1}, imev5GreenTPR),
std::shared_ptr< Logger ilogger = Logger::getDefaultLogger() 
)

ChassisController using PID control.

Puts the motors into encoder count units. Throws a std::invalid_argument exception if the gear ratio is zero.

Parameters
itimeUtilThe TimeUtil.
imodelThe ChassisModel used to read from sensors/write to motors.
idistanceControllerThe PID controller that controls chassis distance for driving straight.
iturnControllerThe PID controller that controls chassis angle for turning.
iangleControllerThe PID controller that controls chassis angle for driving straight.
igearsetThe internal gearset and external ratio used on the drive motors.
iscalesThe ChassisScales.
iloggerThe logger this instance will log to.

◆ ChassisControllerPID() [2/3]

okapi::ChassisControllerPID::ChassisControllerPID ( const ChassisControllerPID )
delete

◆ ChassisControllerPID() [3/3]

okapi::ChassisControllerPID::ChassisControllerPID ( ChassisControllerPID &&  other)
delete

◆ ~ChassisControllerPID()

okapi::ChassisControllerPID::~ChassisControllerPID ( )
override

Member Function Documentation

◆ getChassisScales()

ChassisScales okapi::ChassisControllerPID::getChassisScales ( ) const
overridevirtual

Gets the ChassisScales.

Implements okapi::ChassisController.

◆ getGains()

std::tuple< IterativePosPIDController::Gains, IterativePosPIDController::Gains, IterativePosPIDController::Gains > okapi::ChassisControllerPID::getGains ( ) const

Gets the current controller gains.

Returns
The current controller gains in the order: distance, turn, angle.

◆ getGearsetRatioPair()

AbstractMotor::GearsetRatioPair okapi::ChassisControllerPID::getGearsetRatioPair ( ) const
overridevirtual

Gets the GearsetRatioPair.

Implements okapi::ChassisController.

◆ getMaxVelocity()

double okapi::ChassisControllerPID::getMaxVelocity ( ) const
overridevirtual
Returns
The maximum velocity in RPM [0-600].

Implements okapi::ChassisController.

◆ getModel()

std::shared_ptr< ChassisModel > okapi::ChassisControllerPID::getModel ( )
overridevirtual
Returns
The internal ChassisModel.

Implements okapi::ChassisController.

◆ getThread()

CrossplatformThread * okapi::ChassisControllerPID::getThread ( ) const

Returns the underlying thread handle.

Returns
The underlying thread handle.

◆ isSettled()

bool okapi::ChassisControllerPID::isSettled ( )
overridevirtual

Checks whether the internal controllers are currently settled.

Returns
Whether this ChassisController is settled.

Implements okapi::ChassisController.

◆ loop()

void okapi::ChassisControllerPID::loop ( )
protected

◆ model()

ChassisModel & okapi::ChassisControllerPID::model ( )
overridevirtual
Returns
The internal ChassisModel.

Implements okapi::ChassisController.

◆ moveDistance()

void okapi::ChassisControllerPID::moveDistance ( QLength  itarget)
overridevirtual

Drives the robot straight for a distance (using closed-loop control).

// Drive forward 6 inches
chassis->moveDistance(6_in);
// Drive backward 0.2 meters
chassis->moveDistance(-0.2_m);
Drive chassis
The drive chassis, configured in main.cpp and used everywhere else.
Parameters
itargetdistance to travel

Implements okapi::ChassisController.

◆ moveDistanceAsync()

void okapi::ChassisControllerPID::moveDistanceAsync ( QLength  itarget)
overridevirtual

Sets the target distance for the robot to drive straight (using closed-loop control).

Parameters
itargetdistance to travel

Implements okapi::ChassisController.

◆ moveRaw()

void okapi::ChassisControllerPID::moveRaw ( double  itarget)
overridevirtual

Drives the robot straight for a distance (using closed-loop control).

// Drive forward by spinning the motors 400 degrees
chassis->moveRaw(400);
Parameters
itargetdistance to travel in motor degrees

Implements okapi::ChassisController.

◆ moveRawAsync()

void okapi::ChassisControllerPID::moveRawAsync ( double  itarget)
overridevirtual

Sets the target distance for the robot to drive straight (using closed-loop control).

Parameters
itargetdistance to travel in motor degrees

Implements okapi::ChassisController.

◆ operator=() [1/2]

ChassisControllerPID & okapi::ChassisControllerPID::operator= ( ChassisControllerPID &&  other)
delete

◆ operator=() [2/2]

ChassisControllerPID & okapi::ChassisControllerPID::operator= ( const ChassisControllerPID other)
delete

◆ setGains()

void okapi::ChassisControllerPID::setGains ( const IterativePosPIDController::Gains idistanceGains,
const IterativePosPIDController::Gains iturnGains,
const IterativePosPIDController::Gains iangleGains 
)

Sets the gains for all controllers.

Parameters
idistanceGainsThe distance controller gains.
iturnGainsThe turn controller gains.
iangleGainsThe angle controller gains.

◆ setMaxVelocity()

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

Sets a new maximum velocity in RPM [0-600].

In voltage mode, the max velocity is ignored and a max voltage should be set on the underlying ChassisModel instead.

Parameters
imaxVelocityThe new maximum velocity.

Implements okapi::ChassisController.

◆ setTurnsMirrored()

void okapi::ChassisControllerPID::setTurnsMirrored ( bool  ishouldMirror)
overridevirtual

Sets whether turns should be mirrored.

Parameters
ishouldMirrorwhether turns should be mirrored

Implements okapi::ChassisController.

◆ setVelocityMode()

void okapi::ChassisControllerPID::setVelocityMode ( bool  ivelocityMode)

Sets the velocity mode flag.

When the controller is in velocity mode, the control loop will set motor velocities. When the controller is in voltage mode (ivelocityMode = false), the control loop will set motor voltages. Additionally, when the controller is in voltage mode, it will not obey maximum velocity limits.

Parameters
ivelocityModeWhether the controller should be in velocity or voltage mode.

◆ startThread()

void okapi::ChassisControllerPID::startThread ( )

Starts the internal thread.

This method is called by the ChassisControllerBuilder when making a new instance of this class.

◆ stop()

void okapi::ChassisControllerPID::stop ( )
overridevirtual

Interrupts the current movement to stop the robot.

Implements okapi::ChassisController.

◆ stopAfterSettled()

void okapi::ChassisControllerPID::stopAfterSettled ( )
protected

Stops all the controllers and the ChassisModel.

◆ trampoline()

static void okapi::ChassisControllerPID::trampoline ( void *  context)
staticprotected

◆ turnAngle()

void okapi::ChassisControllerPID::turnAngle ( QAngle  idegTarget)
overridevirtual

Turns the robot clockwise in place (using closed-loop control).

// Turn 90 degrees clockwise
chassis->turnAngle(90_deg);
Parameters
idegTargetangle to turn for

Implements okapi::ChassisController.

◆ turnAngleAsync()

void okapi::ChassisControllerPID::turnAngleAsync ( QAngle  idegTarget)
overridevirtual

Sets the target angle for the robot to turn clockwise in place (using closed-loop control).

Parameters
idegTargetangle to turn for

Implements okapi::ChassisController.

◆ turnRaw()

void okapi::ChassisControllerPID::turnRaw ( double  idegTarget)
overridevirtual

Turns the robot clockwise in place (using closed-loop control).

// Turn clockwise by spinning the motors 200 degrees
chassis->turnRaw(200);
Parameters
idegTargetangle to turn for in motor degrees

Implements okapi::ChassisController.

◆ turnRawAsync()

void okapi::ChassisControllerPID::turnRawAsync ( double  idegTarget)
overridevirtual

Sets the target angle for the robot to turn clockwise in place (using closed-loop control).

Parameters
idegTargetangle to turn for in motor degrees

Implements okapi::ChassisController.

◆ waitForAngleSettled()

bool okapi::ChassisControllerPID::waitForAngleSettled ( )
protected

Wait for the angle setup (anglePid) to settle.

Returns
true if done settling; false if settling should be tried again

◆ waitForDistanceSettled()

bool okapi::ChassisControllerPID::waitForDistanceSettled ( )
protected

Wait for the distance setup (distancePid and anglePid) to settle.

Returns
true if done settling; false if settling should be tried again

◆ waitUntilSettled()

void okapi::ChassisControllerPID::waitUntilSettled ( )
overridevirtual

Delays until the currently executing movement completes.

Implements okapi::ChassisController.

Member Data Documentation

◆ anglePid

std::unique_ptr<IterativePosPIDController> okapi::ChassisControllerPID::anglePid
protected

Definition at line 238 of file chassisControllerPid.hpp.

◆ chassisModel

std::shared_ptr<ChassisModel> okapi::ChassisControllerPID::chassisModel
protected

Definition at line 234 of file chassisControllerPid.hpp.

◆ distancePid

std::unique_ptr<IterativePosPIDController> okapi::ChassisControllerPID::distancePid
protected

Definition at line 236 of file chassisControllerPid.hpp.

◆ doneLooping

std::atomic_bool okapi::ChassisControllerPID::doneLooping {true}
protected

Definition at line 242 of file chassisControllerPid.hpp.

◆ doneLoopingSeen

std::atomic_bool okapi::ChassisControllerPID::doneLoopingSeen {true}
protected

Definition at line 243 of file chassisControllerPid.hpp.

◆ dtorCalled

std::atomic_bool okapi::ChassisControllerPID::dtorCalled {false}
protected

Definition at line 245 of file chassisControllerPid.hpp.

◆ gearsetRatioPair

AbstractMotor::GearsetRatioPair okapi::ChassisControllerPID::gearsetRatioPair
protected

Definition at line 240 of file chassisControllerPid.hpp.

◆ logger

std::shared_ptr<Logger> okapi::ChassisControllerPID::logger
protected

Definition at line 232 of file chassisControllerPid.hpp.

◆ mode

modeType okapi::ChassisControllerPID::mode {none}
protected

Definition at line 271 of file chassisControllerPid.hpp.

◆ newMovement

std::atomic_bool okapi::ChassisControllerPID::newMovement {false}
protected

Definition at line 244 of file chassisControllerPid.hpp.

◆ normalTurns

bool okapi::ChassisControllerPID::normalTurns {true}
protected

Definition at line 233 of file chassisControllerPid.hpp.

◆ scales

ChassisScales okapi::ChassisControllerPID::scales
protected

Definition at line 239 of file chassisControllerPid.hpp.

◆ task

CrossplatformThread* okapi::ChassisControllerPID::task {nullptr}
protected

Definition at line 273 of file chassisControllerPid.hpp.

◆ threadSleepTime

QTime okapi::ChassisControllerPID::threadSleepTime {10_ms}
protected

Definition at line 246 of file chassisControllerPid.hpp.

◆ timeUtil

TimeUtil okapi::ChassisControllerPID::timeUtil
protected

Definition at line 235 of file chassisControllerPid.hpp.

◆ turnPid

std::unique_ptr<IterativePosPIDController> okapi::ChassisControllerPID::turnPid
protected

Definition at line 237 of file chassisControllerPid.hpp.

◆ velocityMode

bool okapi::ChassisControllerPID::velocityMode {true}
protected

Definition at line 241 of file chassisControllerPid.hpp.


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