|
Valor 6800 1.0
|
Abstract class that all Valor controllers's should implement. More...
#include <BaseController.h>
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< bool > | ReadLogImpl (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 > | |
| T | ReadLog (std::string_view field, const T &defaultValue={}) |
| Read a value from NetworkTables for the given field. | |
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::NeoController, and valor::PhoenixController< VelocityOutput, PositionOutput >.
|
inline |
Get the mechanisms's maximum speed.
|
pure virtual |
Get the motors position.
To be defined by the implemented BaseController class
Implemented in valor::NeoController, and valor::PhoenixController< VelocityOutput, PositionOutput >.
|
pure virtual |
Get the motors speed.
To be defined by the implemented BaseController class
Implemented in valor::NeoController, and valor::PhoenixController< VelocityOutput, PositionOutput >.
|
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.
|
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
| position | The position to send the motor to |
Implemented in valor::PhoenixController< VelocityOutput, PositionOutput >, and valor::NeoController.
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 >.
|
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 |
Implemented in valor::NeoController, and valor::PhoenixController< VelocityOutput, PositionOutput >.
|
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::PhoenixController< VelocityOutput, PositionOutput >, 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 |
|
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 |
Implemented in valor::NeoController, and valor::PhoenixController< VelocityOutput, PositionOutput >.
|
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 >.
|
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 |
Implemented in valor::NeoController, and valor::PhoenixController< VelocityOutput, PositionOutput >.
|
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 |
Implemented in valor::NeoController, and valor::PhoenixController< VelocityOutput, PositionOutput >.
|
inline |
Setup the voltage compensation for the motor.
|
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
| speed | The speed to set the motor to |
Implemented in valor::NeoController, and valor::PhoenixController< VelocityOutput, PositionOutput >.