|
Valkyrie 2026
|
Abstract class that all Valor controllers's should implement. More...
#include <valkyrie/controllers/BaseController.h>
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 | GetOperationalMode () const |
| TuningMode | GetTuningMode () const |
| constexpr units::turns_per_second_t | GetMaxMechanismSpeed () |
| Get the mechanisms's maximum speed. | |
| constexpr void | SetVoltageCompensation (units::volt_t _voltageCompensation) |
| Setup the voltage compensation for the motor. | |
| constexpr units::volt_t | GetVoltageCompensation () |
| virtual constexpr void | Reset () |
| Resets the motor and any state. | |
| virtual units::turn_t | GetPosition () const =0 |
| Get the motors position. | |
| virtual units::ampere_t | GetCurrent () const =0 |
| Get the motors output current. | |
| virtual units::turns_per_second_t | GetSpeed () const =0 |
| Get the motors speed. | |
| 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) |
| constexpr void | SetDefaultTuningMode (TuningMode mode) |
| 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 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. | |
| void | SetPeriodicLevel (LogLevel level) |
| Set the logging level for LoggablePeriodic. | |
| template<typename T> | |
| T | WriteLog (std::string_view field, const T &data, LogLevel level=LogLevel::Normal) |
| Publish a value to NetworkTables under the given field. | |
| template<typename T> | |
| T | ReadLog (std::string_view field, const T &defaultValue={}) |
| Read a value from NetworkTables for the given field. | |
| 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< bool > | ReadLogImpl (nt::Subscriber *sub) |
Public Attributes | |
| frc::DCMotor | motorSpec |
| double | rotorToSensor |
| double | sensorToMech |
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 Member Functions inherited from valor::Loggable | |
| virtual void | LoggablePeriodic () |
| Periodic callback for logging updates. | |
Protected Attributes | |
| units::volt_t | voltageCompensation |
Additional Inherited Members | |
| Static Public Member Functions inherited from valor::Loggable | |
| static units::millisecond_t | GetLoggingTime () |
| static constexpr Loggable & | GetRoot () |
Abstract class that all Valor controllers's should implement.
| T | Motor 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:
|
pure virtual |
Get the motors output current.
Get the instantaneous current of the motor that the controller owns
Implemented in valor::CorePhoenixController, and valor::NeoController.
|
inlineconstexpr |
Get the mechanisms's maximum speed.
|
pure virtual |
Get the motors position.
To be defined by the implemented BaseController class
Implemented in valor::CorePhoenixController, and valor::NeoController.
|
pure virtual |
Get the motors speed.
To be defined by the implemented BaseController class
Implemented in valor::CorePhoenixController, and valor::NeoController.
|
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.
|
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
| position | The position to send the motor to |
| slot | The slot to use for PID gains |
Implemented in valor::NeoController, and valor::PhoenixController< VelocityOutput, PositionOutput >.
|
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.
|
pure virtual |
Set the forward soft limit for the motor.
Soft limits restrict the reverse and forward direction to a certain range.
| forward | The forward soft limit |
| saveImmediately | Send the config change immediately to the motor controller |
Implemented in valor::CorePhoenixController, and valor::NeoController.
|
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
| rotorToSensor | The gear ratio from rotor to where the sensor is. Should be 1 if no external sensor |
| sensorToMech | The gear ratio from the sensor to the mechanism's output shaft. Should be the gear ratio if no external sensor |
| saveImmediately | Tell 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.
|
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
| reverse | The reverse soft limit |
| forward | The forward soft limit |
| saveImmediately | Send the config change immediately to the motor controller |
|
pure virtual |
Set the neutral mode of the motor.
| mode | The neutral mode of the motor |
| saveImmediately | Send the config change immediately to the motor controller |
Implemented in valor::CorePhoenixController, valor::NeoController, and valor::PhoenixController< VelocityOutput, PositionOutput >.
|
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.
| pidf | The new PIDF values to use for the system |
| slot | Set which slot of the motor to apply the PIDF. 0 if slots aren't compatible |
| saveImmediately | Send the config change immediately to the motor controller |
Implemented in valor::NeoController, and valor::PhoenixController< VelocityOutput, PositionOutput >.
|
pure virtual |
Set the reverse soft limit for the motor.
Soft limits restrict the reverse and reverse direction to a certain range.
| reverse | The reverse soft limit |
| saveImmediately | Send the config change immediately to the motor controller |
Implemented in valor::CorePhoenixController, and valor::NeoController.
|
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
| canID | The CAN ID of the follower motor |
| followerInverted | Whether the follower is inverted or not. This is an absolute inversion, NOT relative to the master. |
Implemented in valor::CorePhoenixController, and valor::NeoController.
|
inlineconstexpr |
Setup the voltage compensation for the motor.
|
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
| speed | The speed to set the motor to |
| slot | The slot to use for PID gains |
Implemented in valor::NeoController, and valor::PhoenixController< VelocityOutput, PositionOutput >.