SubZero Common
Common library components for an FRC CommandRobot
Loading...
Searching...
No Matches
subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder > Class Template Reference

Combines a motor, motor drvier, relative encoder, and absolute encoder into a single wrapper; helpful for absolute positioning, setting velocities, or tuning PID values. More...

#include <PidMotorController.h>

+ Inheritance diagram for subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >:
+ Collaboration diagram for subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >:

Public Member Functions

 PidMotorController (std::string name, TMotor &motor, TRelativeEncoder &encoder, TController &controller, PidSettings pidSettings, TAbsoluteEncoder *absEncoder, units::revolutions_per_minute_t maxRpm)
 Construct a new PidMotorController.
 
void Set (double percentage) override
 Set the motor to a percentage of max voltage.
 
void Set (units::volt_t volts) override
 Set a motor to a voltage.
 
void SetPidTolerance (double tolerance) override
 Absolute positioning is considered 'Done' when within this zone.
 
void Update () override
 ! Call this every loop in Periodic !
 
void RunWithVelocity (units::revolutions_per_minute_t rpm) override
 Set to this velocity.
 
void RunWithVelocity (double percentage) override
 Set to a percentage of max RPM.
 
void RunToPosition (double position) override
 Enables absolute positioning and sets the target to the position.
 
virtual void ResetEncoder () override
 
double GetEncoderPosition () override
 
std::optional< double > GetAbsoluteEncoderPosition () override
 
void SetEncoderConversionFactor (double factor) override
 Sets the multiplier for going between encoder ticks and actual distance.
 
void SetAbsoluteEncoderConversionFactor (double factor) override
 Sets the multiplier for going between encoder ticks and actual distance.
 
void Stop () override
 Disable absolute positioning and stop the motor.
 
const PidSettingsGetPidSettings () override
 
void UpdatePidSettings (PidSettings settings) override
 
- Public Member Functions inherited from subzero::IPidMotorController
 IPidMotorController (std::string name)
 

Protected Attributes

TMotor & m_motor
 
TController & m_controller
 
TRelativeEncoder & m_encoder
 
TAbsoluteEncoder * m_absEncoder
 
PidSettings m_settings
 
frc::PIDController m_pidController
 
bool m_absolutePositionEnabled = false
 
double m_absoluteTarget = 0
 
const units::revolutions_per_minute_t m_maxRpm
 

Additional Inherited Members

- Public Attributes inherited from subzero::IPidMotorController
const std::string m_name
 

Detailed Description

template<typename TMotor, typename TController, typename TRelativeEncoder, typename TAbsoluteEncoder>
class subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >

Combines a motor, motor drvier, relative encoder, and absolute encoder into a single wrapper; helpful for absolute positioning, setting velocities, or tuning PID values.

Template Parameters
TMotor
TController
TRelativeEncoder
TAbsoluteEncoder

Definition at line 28 of file PidMotorController.h.

Constructor & Destructor Documentation

◆ PidMotorController()

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::PidMotorController ( std::string name,
TMotor & motor,
TRelativeEncoder & encoder,
TController & controller,
PidSettings pidSettings,
TAbsoluteEncoder * absEncoder,
units::revolutions_per_minute_t maxRpm )
explicit

Construct a new PidMotorController.

Parameters
nameDisplay name in SmartDashboard
motor
encoder
controller
pidSettingsInitial PID settings
absEncoderSet to nullptr for a disconnected encoder
maxRpmMax RPM of the motor; used to set velocity based on percentage

Member Function Documentation

◆ GetAbsoluteEncoderPosition()

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
std::optional< double > subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::GetAbsoluteEncoderPosition ( )
overridevirtual

◆ GetEncoderPosition()

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
double subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::GetEncoderPosition ( void )
inlineoverridevirtual

Implements subzero::IPidMotorController.

Definition at line 101 of file PidMotorController.h.

◆ GetPidSettings()

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
const PidSettings & subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::GetPidSettings ( void )
inlineoverridevirtual

Implements subzero::IPidMotorController.

Definition at line 135 of file PidMotorController.h.

◆ ResetEncoder()

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
virtual void subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::ResetEncoder ( void )
inlineoverridevirtual

Implements subzero::IPidMotorController.

Definition at line 96 of file PidMotorController.h.

◆ RunToPosition()

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
void subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::RunToPosition ( double position)
overridevirtual

Enables absolute positioning and sets the target to the position.

Parameters
position

Implements subzero::IPidMotorController.

◆ RunWithVelocity() [1/2]

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
void subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::RunWithVelocity ( double percentage)
overridevirtual

Set to a percentage of max RPM.

Parameters
percentage

Implements subzero::IPidMotorController.

◆ RunWithVelocity() [2/2]

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
void subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::RunWithVelocity ( units::revolutions_per_minute_t rpm)
overridevirtual

Set to this velocity.

Parameters
rpm

Implements subzero::IPidMotorController.

◆ Set() [1/2]

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
void subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::Set ( double percentage)
overridevirtual

Set the motor to a percentage of max voltage.

Parameters
percentage

Implements subzero::IPidMotorController.

◆ Set() [2/2]

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
void subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::Set ( units::volt_t volts)
overridevirtual

Set a motor to a voltage.

Parameters
volts

Implements subzero::IPidMotorController.

◆ SetAbsoluteEncoderConversionFactor()

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
void subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::SetAbsoluteEncoderConversionFactor ( double factor)
inlineoverridevirtual

Sets the multiplier for going between encoder ticks and actual distance.

Parameters
factor

Implements subzero::IPidMotorController.

Definition at line 123 of file PidMotorController.h.

◆ SetEncoderConversionFactor()

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
void subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::SetEncoderConversionFactor ( double factor)
inlineoverridevirtual

Sets the multiplier for going between encoder ticks and actual distance.

Parameters
factor

Implements subzero::IPidMotorController.

Definition at line 113 of file PidMotorController.h.

◆ SetPidTolerance()

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
void subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::SetPidTolerance ( double tolerance)
overridevirtual

Absolute positioning is considered 'Done' when within this zone.

Parameters
tolerance

Implements subzero::IPidMotorController.

◆ Stop()

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
void subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::Stop ( )
overridevirtual

Disable absolute positioning and stop the motor.

Implements subzero::IPidMotorController.

◆ Update()

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
void subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::Update ( )
overridevirtual

! Call this every loop in Periodic !

Implements subzero::IPidMotorController.

◆ UpdatePidSettings()

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
void subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::UpdatePidSettings ( PidSettings settings)
overridevirtual

Member Data Documentation

◆ m_absEncoder

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
TAbsoluteEncoder* subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::m_absEncoder
protected

Definition at line 143 of file PidMotorController.h.

◆ m_absolutePositionEnabled

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
bool subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::m_absolutePositionEnabled = false
protected

Definition at line 146 of file PidMotorController.h.

◆ m_absoluteTarget

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
double subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::m_absoluteTarget = 0
protected

Definition at line 147 of file PidMotorController.h.

◆ m_controller

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
TController& subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::m_controller
protected

Definition at line 141 of file PidMotorController.h.

◆ m_encoder

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
TRelativeEncoder& subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::m_encoder
protected

Definition at line 142 of file PidMotorController.h.

◆ m_maxRpm

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
const units::revolutions_per_minute_t subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::m_maxRpm
protected

Definition at line 148 of file PidMotorController.h.

◆ m_motor

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
TMotor& subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::m_motor
protected

Definition at line 140 of file PidMotorController.h.

◆ m_pidController

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
frc::PIDController subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::m_pidController
protected

Definition at line 145 of file PidMotorController.h.

◆ m_settings

template<typename TMotor , typename TController , typename TRelativeEncoder , typename TAbsoluteEncoder >
PidSettings subzero::PidMotorController< TMotor, TController, TRelativeEncoder, TAbsoluteEncoder >::m_settings
protected

Definition at line 144 of file PidMotorController.h.


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