Valor 6800 1.0
Loading...
Searching...
No Matches
valor::BaseController Class Referenceabstract

Abstract class that all Valor controllers's should implement. More...

#include <BaseController.h>

Inheritance diagram for valor::BaseController:
valor::Loggable valor::NeoController valor::PhoenixController< VelocityOutput, PositionOutput >

Public Types

enum class  OperationalMode { NonOperational , Tuning , Operational }
 
enum class  TuningMode {
  Voltage , Current , DutyCycle , Speed ,
  Position
}
 

Public Member Functions

 BaseController (frc::DCMotor _motorSpec)
 Construct a new Valor Controller object.
 
void OnLoggingStart () override
 Hook invoked when logging is started for this object.
 
virtual void applyConfig ()=0
 
OperationalMode getOpMode ()
 
TuningMode getTuneMode ()
 
units::turns_per_second_t getMaxMechSpeed ()
 Get the mechanisms's maximum speed.
 
void setVoltageCompensation (units::volt_t _voltageCompensation)
 Setup the voltage compensation for the motor.
 
units::volt_t getVoltageCompensation ()
 
virtual void reset ()=0
 Resets the motor and any state.
 
virtual units::turn_t getPosition ()=0
 Get the motors position.
 
virtual units::ampere_t getCurrent ()=0
 Get the motors output current.
 
virtual units::turns_per_second_t getSpeed ()=0
 Get the motors speed.
 
virtual void setEncoderPosition (units::turn_t position)=0
 
virtual void positionSetter (units::turn_t position, int slot=0)=0
 Send the motor to a specific position.
 
void setPosition (units::turn_t position, int slot=0)
 
virtual void setPositionWithFeedForward (units::turn_t position, units::turns_per_second_t feedforwardVelocity, int slot=0)
 Send the motor to a specific position with a velocity feedforward.
 
virtual void speedSetter (units::turns_per_second_t speed, int slot=0)=0
 Send the motor to a specific speed.
 
void setSpeed (units::turns_per_second_t speed, int slot=0)
 
virtual void powerSetter (units::volt_t voltage)
 
virtual void powerSetter (units::ampere_t current)
 
virtual void powerSetter (double dutyCycle)
 
template<typename T >
void setPower (T power)
 
virtual void setupFollower (int canID, bool followerInverted=false)=0
 If a motor is paired with another motor, setup that other motor as a follower.
 
virtual void setPIDF (valor::PIDF pidf, int slot=0, bool saveImmediately=false)=0
 Change the PIDF values for the motor.
 
void setLimits (units::turn_t reverse, units::turn_t forward, bool saveImmediately=false)
 Set both soft limits for the motor.
 
virtual void setForwardLimit (units::turn_t forward, bool saveImmediately=false)=0
 Set the forward soft limit for the motor.
 
virtual void setReverseLimit (units::turn_t reverse, bool saveImmediately=false)=0
 Set the reverse soft limit for the motor.
 
virtual void setGearRatios (double rotorToSensor, double sensorToMech, bool saveImmediately=false)=0
 Set the gear ratios for the motor.
 
virtual void setOpenLoopRamp (units::second_t time, bool saveImmediately=false)=0
 
virtual units::turn_t getAbsEncoderPosition ()=0
 
virtual units::volt_t calculateAppliedVoltage ()=0
 
virtual void setSimState (frc::sim::DCMotorSim &)=0
 
- Public Member Functions inherited from valor::Loggable
void LogChild (std::string_view name, Loggable *child)
 Register a child Loggable under a named subtree.
 
void LogChild (std::string_view name, wpi::Sendable *child)
 Register a child Sendable under a named subtree.
 
void setLoggingPeriod (units::millisecond_t period)
 Set the minimum period between LoggablePeriodic() invocations.
 
template<>
decltype(Loggable::subscribers) ::iterator addSubscriber (std::string_view field, const std::vector< bool > &defaultValue)
 
template<>
void WriteLogImpl (nt::Publisher *pub, const std::vector< bool > &data)
 
template<>
std::vector< boolReadLogImpl (nt::Subscriber *sub)
 

Public Attributes

frc::DCMotor motorSpec
 
double rotorToSensor
 
double sensorToMech
 

Protected Attributes

units::volt_t voltageCompensation
 

Additional Inherited Members

- Static Public Member Functions inherited from valor::Loggable
static units::millisecond_t GetLoggingTime ()
 
- Protected Member Functions inherited from valor::Loggable
 Loggable (std::string_view name)
 Construct a Loggable that registers a top-level table name.
 
 Loggable ()
 Default construct an uninitialized Loggable.
 
virtual ~Loggable ()=default
 Virtual destructor.
 
virtual void LoggablePeriodic ()
 Periodic callback for logging updates.
 
template<typename T >
T WriteLog (std::string_view field, const T &data)
 Publish a value to NetworkTables under the given field.
 
template<typename T >
ReadLog (std::string_view field, const T &defaultValue={})
 Read a value from NetworkTables for the given field.
 

Detailed Description

Abstract class that all Valor controllers's should implement.

Template Parameters
TMotor data type

To make developer's lives easier and to prevent any mistakes in a quick build season, BaseController is used to organize code and abstract a lot of the base code that is often repetitive in all motor controllers.

The idea is that motor controllers on the robot implement BaseController and logic for that motor controller is run by the implemented class. Setup for the motors should also occur in the implemented BaseController, and the motor pointer itself also lives in this class.

Helper methods exist to make it easier for subsystems to control motors in a variety of ways.

Usage:

public class ValorFalconController : public BaseController { };
Abstract class that all Valor controllers's should implement.
Definition BaseController.h:53
T ReadLog(std::string_view field, const T &defaultValue={})
Read a value from NetworkTables for the given field.
Definition Loggable.h:343

Member Function Documentation

◆ getCurrent()

virtual units::ampere_t valor::BaseController::getCurrent ( )
pure virtual

Get the motors output current.

Get the instantaneous current of the motor that the controller owns

Returns
units::ampere_t Instantaneous amperage of the motor

Implemented in valor::NeoController, and valor::PhoenixController< VelocityOutput, PositionOutput >.

◆ getMaxMechSpeed()

units::turns_per_second_t valor::BaseController::getMaxMechSpeed ( )
inline

Get the mechanisms's maximum speed.

Returns
units::turns_per_second_t Mechanism's maximum angular speed (at the mech)

◆ getPosition()

virtual units::turn_t valor::BaseController::getPosition ( )
pure virtual

Get the motors position.

To be defined by the implemented BaseController class

Returns
units::turn_t Position of the motor

Implemented in valor::NeoController, and valor::PhoenixController< VelocityOutput, PositionOutput >.

◆ getSpeed()

virtual units::turns_per_second_t valor::BaseController::getSpeed ( )
pure virtual

Get the motors speed.

To be defined by the implemented BaseController class

Returns
units::turns_per_second_t Speed of the motor

Implemented in valor::NeoController, and valor::PhoenixController< VelocityOutput, PositionOutput >.

◆ OnLoggingStart()

void valor::BaseController::OnLoggingStart ( )
inlineoverridevirtual

Hook invoked when logging is started for this object.

Derived classes may override to perform initialization when the NetworkTables table becomes active for this Loggable.

Reimplemented from valor::Loggable.

◆ positionSetter()

virtual void valor::BaseController::positionSetter ( units::turn_t position,
int slot = 0 )
pure virtual

Send the motor to a specific position.

Will use the motor's native trapezoidal motion profile to get the motor to that position. Can be tuned using the velocity and acceleration components of valor::PIDF via setPIDF

To be defined by the implemented BaseController class

Parameters
positionThe position to send the motor to

Implemented in valor::PhoenixController< VelocityOutput, PositionOutput >, and valor::NeoController.

◆ reset()

virtual void valor::BaseController::reset ( )
pure virtual

Resets the motor and any state.

Clear the encoders for the motor and set to 0.

Additionally, should be called by the constructor to set default values before any logic is run.

To be defined by the implemented BaseController class

Implemented in valor::NeoController, and valor::PhoenixController< VelocityOutput, PositionOutput >.

◆ setForwardLimit()

virtual void valor::BaseController::setForwardLimit ( units::turn_t forward,
bool saveImmediately = false )
pure virtual

Set the forward soft limit for the motor.

Soft limits restrict the reverse and forward direction to a certain range.

Parameters
forwardThe forward soft limit

Implemented in valor::NeoController, and valor::PhoenixController< VelocityOutput, PositionOutput >.

◆ setGearRatios()

virtual void valor::BaseController::setGearRatios ( double rotorToSensor,
double sensorToMech,
bool saveImmediately = false )
pure virtual

Set the gear ratios for the motor.

Used to convert between the motor's rotor and the output shaft of the mechanism

To be defined by the implemented BaseController class

Parameters
rotorToSensorThe gear ratio from rotor to where the sensor is. Should be 1 if no external sensor
sensorToMechThe gear ratio from the sensor to the mechanism's output shaft. Should be the gear ratio if no external sensor
saveImmediatelyTell the underlying controller to apply the changes immediately, or to wait until a manual apply has been called

Implemented in valor::PhoenixController< VelocityOutput, PositionOutput >, and valor::NeoController.

◆ setLimits()

void valor::BaseController::setLimits ( units::turn_t reverse,
units::turn_t forward,
bool saveImmediately = false )
inline

Set both soft limits for the motor.

Soft limits restrict the reverse and forward direction to a certain range.

Calls out to the pure virtual functions setForwardLimit and setReverseLimit

Parameters
reverseThe reverse soft limit
forwardThe forward soft limit

◆ setPIDF()

virtual void valor::BaseController::setPIDF ( valor::PIDF pidf,
int slot = 0,
bool saveImmediately = false )
pure virtual

Change the PIDF values for the motor.

valor::PIDF has some default values already set and tested, but if the system requires some changes, use this method to change those defaults.

Parameters
pidfThe new PIDF values to use for the system
slotSet which slot of the motor to apply the PIDF. 0 if slots aren't compatible

Implemented in valor::NeoController, and valor::PhoenixController< VelocityOutput, PositionOutput >.

◆ setPositionWithFeedForward()

virtual void valor::BaseController::setPositionWithFeedForward ( units::turn_t position,
units::turns_per_second_t feedforwardVelocity,
int slot = 0 )
inlinevirtual

Send the motor to a specific position with a velocity feedforward.

The controller converts the desired mechanism velocity to a feedforward voltage using its own kV and kS gains, then adds it to the closed-loop output. Useful when the setpoint is known to be moving (e.g. a turret tracking a field-stationary target while the chassis rotates).

Reimplemented in valor::PhoenixController< VelocityOutput, PositionOutput >.

◆ setReverseLimit()

virtual void valor::BaseController::setReverseLimit ( units::turn_t reverse,
bool saveImmediately = false )
pure virtual

Set the reverse soft limit for the motor.

Soft limits restrict the reverse and reverse direction to a certain range.

Parameters
reverseThe reverse soft limit

Implemented in valor::NeoController, and valor::PhoenixController< VelocityOutput, PositionOutput >.

◆ setupFollower()

virtual void valor::BaseController::setupFollower ( int canID,
bool followerInverted = false )
pure virtual

If a motor is paired with another motor, setup that other motor as a follower.

The follower motor will need a CAN ID, and then it will mimic and assume all other parameters of the lead motor

To be defined by the implemented BaseController class

Parameters
canIDThe CAN ID of the follower motor

Implemented in valor::NeoController, and valor::PhoenixController< VelocityOutput, PositionOutput >.

◆ setVoltageCompensation()

void valor::BaseController::setVoltageCompensation ( units::volt_t _voltageCompensation)
inline

Setup the voltage compensation for the motor.

Note
Make sure to call first before setting up any PIDF profiles

◆ speedSetter()

virtual void valor::BaseController::speedSetter ( units::turns_per_second_t speed,
int slot = 0 )
pure virtual

Send the motor to a specific speed.

Will use the motor's native trapezoidal motion profile to get the motor to that position. Can be tuned using the PIDF components of valor::PIDF via setPIDF

To be defined by the implemented BaseController class

Parameters
speedThe speed to set the motor to

Implemented in valor::NeoController, and valor::PhoenixController< VelocityOutput, PositionOutput >.


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