WPILibC++ 2024.3.2
frc::PWMMotorController Class Reference

Common base class for all PWM Motor Controllers. More...

#include <frc/motorcontrol/PWMMotorController.h>

Inheritance diagram for frc::PWMMotorController:
frc::MotorController frc::MotorSafety wpi::Sendable wpi::SendableHelper< PWMMotorController > frc::DMC60 frc::Jaguar frc::PWMSparkFlex frc::PWMSparkMax frc::PWMTalonFX frc::PWMTalonSRX frc::PWMVenom frc::PWMVictorSPX frc::SD540 frc::Spark frc::Talon frc::Victor frc::VictorSP

Public Member Functions

 PWMMotorController (PWMMotorController &&)=default
 
PWMMotorControlleroperator= (PWMMotorController &&)=default
 
void Set (double value) override
 Set the PWM value. More...
 
void SetVoltage (units::volt_t output) override
 Sets the voltage output of the PWMMotorController. More...
 
double Get () const override
 Get the recently set value of the PWM. More...
 
void SetInverted (bool isInverted) override
 Common interface for inverting direction of a motor controller. More...
 
bool GetInverted () const override
 Common interface for returning the inversion state of a motor controller. More...
 
void Disable () override
 Common interface for disabling a motor. More...
 
void StopMotor () override
 Called to stop the motor when the timeout expires. More...
 
std::string GetDescription () const override
 Returns a description to print when an error occurs. More...
 
int GetChannel () const
 
void EnableDeadbandElimination (bool eliminateDeadband)
 Optionally eliminate the deadband from a motor controller. More...
 
void AddFollower (PWMMotorController &follower)
 Make the given PWM motor controller follow the output of this one. More...
 
template<std::derived_from< PWMMotorController > T>
void AddFollower (T &&follower)
 Make the given PWM motor controller follow the output of this one. More...
 
- Public Member Functions inherited from frc::MotorController
virtual ~MotorController ()=default
 
virtual void Set (double speed)=0
 Common interface for setting the speed of a motor controller. More...
 
virtual void SetVoltage (units::volt_t output)
 Sets the voltage output of the MotorController. More...
 
virtual double Get () const =0
 Common interface for getting the current set speed of a motor controller. More...
 
virtual void SetInverted (bool isInverted)=0
 Common interface for inverting direction of a motor controller. More...
 
virtual bool GetInverted () const =0
 Common interface for returning the inversion state of a motor controller. More...
 
virtual void Disable ()=0
 Common interface for disabling a motor. More...
 
virtual void StopMotor ()=0
 Common interface to stop the motor until Set is called again. More...
 
- Public Member Functions inherited from frc::MotorSafety
 MotorSafety ()
 
virtual ~MotorSafety ()
 
 MotorSafety (MotorSafety &&rhs)
 
MotorSafetyoperator= (MotorSafety &&rhs)
 
void Feed ()
 Feed the motor safety object. More...
 
void SetExpiration (units::second_t expirationTime)
 Set the expiration time for the corresponding motor safety object. More...
 
units::second_t GetExpiration () const
 Retrieve the timeout value for the corresponding motor safety object. More...
 
bool IsAlive () const
 Determine if the motor is still operating or has timed out. More...
 
void SetSafetyEnabled (bool enabled)
 Enable/disable motor safety for this device. More...
 
bool IsSafetyEnabled () const
 Return the state of the motor safety enabled flag. More...
 
void Check ()
 Check if this motor has exceeded its timeout. More...
 
virtual void StopMotor ()=0
 Called to stop the motor when the timeout expires. More...
 
virtual std::string GetDescription () const =0
 Returns a description to print when an error occurs. More...
 
- Public Member Functions inherited from wpi::Sendable
virtual ~Sendable ()=default
 
virtual void InitSendable (SendableBuilder &builder)=0
 Initializes this Sendable object. More...
 
- Public Member Functions inherited from wpi::SendableHelper< PWMMotorController >
 SendableHelper (const SendableHelper &rhs)=default
 
 SendableHelper (SendableHelper &&rhs)
 
SendableHelperoperator= (const SendableHelper &rhs)=default
 
SendableHelperoperator= (SendableHelper &&rhs)
 

Protected Member Functions

 PWMMotorController (std::string_view name, int channel)
 Constructor for a PWM Motor Controller connected via PWM. More...
 
void InitSendable (wpi::SendableBuilder &builder) override
 Initializes this Sendable object. More...
 
- Protected Member Functions inherited from wpi::SendableHelper< PWMMotorController >
 SendableHelper ()=default
 
 ~SendableHelper ()
 

Protected Attributes

PWM m_pwm
 PWM instances for motor controller. More...
 

Friends

class DMA
 

Additional Inherited Members

- Static Public Member Functions inherited from frc::MotorSafety
static void CheckMotors ()
 Check the motors to see if any have timed out. More...
 

Detailed Description

Common base class for all PWM Motor Controllers.

Constructor & Destructor Documentation

◆ PWMMotorController() [1/2]

frc::PWMMotorController::PWMMotorController ( PWMMotorController &&  )
default

◆ PWMMotorController() [2/2]

frc::PWMMotorController::PWMMotorController ( std::string_view  name,
int  channel 
)
protected

Constructor for a PWM Motor Controller connected via PWM.

Parameters
nameName to use for SendableRegistry
channelThe PWM channel that the controller is attached to. 0-9 are on-board, 10-19 are on the MXP port

Member Function Documentation

◆ AddFollower() [1/2]

void frc::PWMMotorController::AddFollower ( PWMMotorController follower)

Make the given PWM motor controller follow the output of this one.

Parameters
followerThe motor controller follower.

◆ AddFollower() [2/2]

template<std::derived_from< PWMMotorController > T>
void frc::PWMMotorController::AddFollower ( T &&  follower)
inline

Make the given PWM motor controller follow the output of this one.

Parameters
followerThe motor controller follower.

◆ Disable()

void frc::PWMMotorController::Disable ( )
overridevirtual

Common interface for disabling a motor.

Implements frc::MotorController.

◆ EnableDeadbandElimination()

void frc::PWMMotorController::EnableDeadbandElimination ( bool  eliminateDeadband)

Optionally eliminate the deadband from a motor controller.

Parameters
eliminateDeadbandIf true, set the motor curve on the motor controller to eliminate the deadband in the middle of the range. Otherwise, keep the full range without modifying any values.

◆ Get()

double frc::PWMMotorController::Get ( ) const
overridevirtual

Get the recently set value of the PWM.

This value is affected by the inversion property. If you want the value that is sent directly to the MotorController, use PWM::GetSpeed() instead.

Returns
The most recently set value for the PWM between -1.0 and 1.0.

Implements frc::MotorController.

◆ GetChannel()

int frc::PWMMotorController::GetChannel ( ) const

◆ GetDescription()

std::string frc::PWMMotorController::GetDescription ( ) const
overridevirtual

Returns a description to print when an error occurs.

Returns
Description to print when an error occurs.

Implements frc::MotorSafety.

◆ GetInverted()

bool frc::PWMMotorController::GetInverted ( ) const
overridevirtual

Common interface for returning the inversion state of a motor controller.

Returns
isInverted The state of inversion, true is inverted.

Implements frc::MotorController.

◆ InitSendable()

void frc::PWMMotorController::InitSendable ( wpi::SendableBuilder builder)
overrideprotectedvirtual

Initializes this Sendable object.

Parameters
buildersendable builder

Implements wpi::Sendable.

◆ operator=()

PWMMotorController & frc::PWMMotorController::operator= ( PWMMotorController &&  )
default

◆ Set()

void frc::PWMMotorController::Set ( double  value)
overridevirtual

Set the PWM value.

The PWM value is set using a range of -1.0 to 1.0, appropriately scaling the value for the FPGA.

Parameters
valueThe speed value between -1.0 and 1.0 to set.

Implements frc::MotorController.

◆ SetInverted()

void frc::PWMMotorController::SetInverted ( bool  isInverted)
overridevirtual

Common interface for inverting direction of a motor controller.

Parameters
isInvertedThe state of inversion, true is inverted.

Implements frc::MotorController.

◆ SetVoltage()

void frc::PWMMotorController::SetVoltage ( units::volt_t  output)
overridevirtual

Sets the voltage output of the PWMMotorController.

Compensates for the current bus voltage to ensure that the desired voltage is output even if the battery voltage is below 12V - highly useful when the voltage outputs are "meaningful" (e.g. they come from a feedforward calculation).

NOTE: This function must be called regularly in order for voltage compensation to work properly - unlike the ordinary set function, it is not "set it and forget it."

Parameters
outputThe voltage to output.

Reimplemented from frc::MotorController.

◆ StopMotor()

void frc::PWMMotorController::StopMotor ( )
overridevirtual

Called to stop the motor when the timeout expires.

Implements frc::MotorSafety.

Friends And Related Function Documentation

◆ DMA

friend class DMA
friend

Member Data Documentation

◆ m_pwm

PWM frc::PWMMotorController::m_pwm
protected

PWM instances for motor controller.


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