Valkyrie 2026
Loading...
Searching...
No Matches
valor::BaseController Class Referenceabstract

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

#include <valkyrie/controllers/BaseController.h>

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

Classes

class  Signal

Public Types

enum class  OperationalMode { NON_OPERATIONAL , TUNING , OPERATIONAL }
enum class  ControlMode {
  VOLTAGE , CURRENT , DUTY_CYCLE , SPEED ,
  POSITION
}
using Output = std::variant<units::volt_t, units::ampere_t, units::scalar_t>

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
constexpr units::turns_per_second_t GetMaxMechanismSpeed ()
 Get the mechanisms's maximum speed.
constexpr double GetGearRatio () const
constexpr void SetVoltageCompensation (units::volt_t _voltageCompensation)
 Setup the voltage compensation for the motor.
constexpr units::volt_t GetVoltageCompensation () const
virtual constexpr void Reset ()
 Resets the motor and any state.
virtual Signal< units::turn_t > GetPosition () const =0
 Get the motors position.
virtual Signal< units::ampere_t > GetCurrent () const =0
 Get the motors output current.
virtual Signal< units::volt_t > GetVoltage () const =0
virtual Signal< units::turns_per_second_t > GetSpeed () const =0
 Get the motors speed.
virtual Signal< units::turns_per_second_squared_t > GetAcceleration () const =0
virtual void SetEncoderPosition (units::turn_t position)=0
void SetPosition (units::turn_t position, Output feedforward=0, int slot=0)
void SetSpeed (units::turns_per_second_t speed, Output feedforward=0, int slot=0)
void SetPower (Output 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 SetNeutralMode (valor::NeutralMode mode, bool saveImmediately=false)=0
 Set the neutral mode of 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 GetAbsoluteEncoderPosition () const =0
virtual units::volt_t CalculateAppliedVoltage ()=0
virtual void SetSimState (units::turn_t pos, units::turns_per_second_t vel, units::turns_per_second_squared_t accel)=0
virtual void SetSimState (frc::sim::DCMotorSim &sim)
virtual void SetSimState (frc::sim::FlywheelSim &sim)
virtual void SetSimState (frc::sim::SingleJointedArmSim &sim)
void LoggablePeriodic () override
 Periodic callback for logging updates.
Public Member Functions inherited from valor::Loggable
 Loggable (std::string_view name)
 Construct a Loggable that registers a top-level table name.
 Loggable (std::shared_ptr< nt::NetworkTable > table)
 Construct a Loggable that uses an existing NetworkTable.
 Loggable ()=default
 Default construct an uninitialized 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.
bool WriteLog (std::string_view field, bool data)
double WriteLog (std::string_view field, double data)
void WriteLog (std::string_view field, const std::vector< double > &data)
template<typename U>
requires units::traits::is_unit_t_v<U>
U WriteLog (std::string_view field, U data)
void WriteLog (std::string_view field, std::string_view data)
template<typename E>
requires std::is_enum_v<E>
void WriteLog (std::string_view field, E data)
template<typename T>
requires wpi::StructSerializable<T> && (!std::is_arithmetic_v<T>)
void WriteLog (std::string_view field, const T &data)
template<typename T>
requires wpi::StructSerializable<T> && (!std::is_arithmetic_v<T>)
void WriteLog (std::string_view field, const std::vector< T > &data)
bool ReadLog (std::string_view field, bool defaultValue)
double ReadLog (std::string_view field, double defaultValue)
template<typename U>
requires units::traits::is_unit_t_v<U>
U ReadLog (std::string_view field, U defaultValue)

Public Attributes

frc::DCMotor motorSpec

Protected Member Functions

virtual void PositionSetter (units::turn_t position, Output feedforward=0, int slot=0)=0
 Send the motor to a specific position.
virtual void SpeedSetter (units::turns_per_second_t speed, Output feedforward=0, int slot=0)=0
 Send the motor to a specific speed.
virtual void PowerSetter (Output out)=0

Protected Attributes

double rotorToSensor
double sensorToMech
units::volt_t voltageCompensation

Additional Inherited Members

Static Public Member Functions inherited from valor::Loggable
static constexpr Loggable & GetRoot ()

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 { };
BaseController(frc::DCMotor _motorSpec)
Construct a new Valor Controller object.
Definition BaseController.h:95

Member Function Documentation

◆ GetCurrent()

virtual Signal< units::ampere_t > valor::BaseController::GetCurrent ( ) const
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::CorePhoenixController, and valor::NeoController.

◆ GetMaxMechanismSpeed()

units::turns_per_second_t valor::BaseController::GetMaxMechanismSpeed ( )
inlineconstexpr

Get the mechanisms's maximum speed.

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

◆ GetPosition()

virtual Signal< units::turn_t > valor::BaseController::GetPosition ( ) const
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::CorePhoenixController, and valor::NeoController.

◆ GetSpeed()

virtual Signal< units::turns_per_second_t > valor::BaseController::GetSpeed ( ) const
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::CorePhoenixController, and valor::NeoController.

◆ LoggablePeriodic()

void valor::BaseController::LoggablePeriodic ( )
inlineoverridevirtual

Periodic callback for logging updates.

If a derived class needs to perform periodic updates to published values, override this method. It is intended to be called by the logging framework; this base class provides an empty implementation.

Reimplemented from valor::Loggable.

Reimplemented in valor::CorePhoenixController, and valor::NeoController.

◆ 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,
Output feedforward = 0,
int slot = 0 )
protectedpure 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
slotThe slot to use for PID gains

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

◆ Reset()

virtual constexpr void valor::BaseController::Reset ( )
inlineconstexprvirtual

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

Reimplemented in valor::CorePhoenixController.

◆ 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
saveImmediatelySend the config change immediately to the motor controller

Implemented in valor::CorePhoenixController, and valor::NeoController.

◆ 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::CorePhoenixController, 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
saveImmediatelySend the config change immediately to the motor controller

◆ SetNeutralMode()

virtual void valor::BaseController::SetNeutralMode ( valor::NeutralMode mode,
bool saveImmediately = false )
pure virtual

Set the neutral mode of the motor.

Parameters
modeThe neutral mode of the motor
saveImmediatelySend the config change immediately to the motor controller

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

◆ 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
saveImmediatelySend the config change immediately to the motor controller

Implemented in valor::NeoController, and 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
saveImmediatelySend the config change immediately to the motor controller

Implemented in valor::CorePhoenixController, and valor::NeoController.

◆ 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
followerInvertedWhether the follower is inverted or not. This is an absolute inversion, NOT relative to the master.

Implemented in valor::CorePhoenixController, and valor::NeoController.

◆ SetVoltageCompensation()

void valor::BaseController::SetVoltageCompensation ( units::volt_t _voltageCompensation)
inlineconstexpr

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,
Output feedforward = 0,
int slot = 0 )
protectedpure 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
slotThe slot to use for PID gains

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


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