WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
wpi::ExpansionHubMotor Class Reference

This class controls a specific motor and encoder hooked up to an ExpansionHub. More...

#include <wpi/hardware/expansionhub/ExpansionHubMotor.hpp>

Public Member Functions

 ExpansionHubMotor (int usbId, int channel)
 Constructs a servo at the requested channel on a specific USB port.
 ~ExpansionHubMotor () noexcept
void SetDutyCycle (double dutyCycle)
 Sets the duty cycle.
void SetVoltage (wpi::units::volt_t voltage)
 Sets the voltage to run the motor at.
void SetPositionSetpoint (double setpoint)
 Command the motor to drive to a specific position setpoint.
void SetVelocitySetpoint (double setpoint)
 Command the motor to drive to a specific velocity setpoint.
void SetEnabled (bool enabled)
 Sets if the motor output is enabled or not.
void SetFloatOn0 (bool floatOn0)
 Sets if the motor should float or brake when 0 is commanded.
wpi::units::ampere_t GetCurrent () const
 Gets the current being pulled by the motor.
void SetDistancePerCount (double perCount)
 Sets the distance per count of the encoder.
double GetEncoderVelocity () const
 Gets the current velocity of the motor encoder.
double GetEncoderPosition () const
 Gets the current position of the motor encoder.
void SetReversed (bool reversed)
 Sets if the motor and encoder should be reversed.
void ResetEncoder ()
 Reset the encoder count to 0.
ExpansionHubPidConstantsGetVelocityPidConstants ()
 Gets the PID constants object for velocity PID.
ExpansionHubPidConstantsGetPositionPidConstants ()
 Gets the PID constants object for position PID.
bool IsHubConnected ()
 Gets if the underlying ExpansionHub is connected.
void Follow (const ExpansionHubMotor &leader)
 Sets this motor to follow another motor on the same hub.

Detailed Description

This class controls a specific motor and encoder hooked up to an ExpansionHub.

Constructor & Destructor Documentation

◆ ExpansionHubMotor()

wpi::ExpansionHubMotor::ExpansionHubMotor ( int usbId,
int channel )

Constructs a servo at the requested channel on a specific USB port.

Parameters
usbIdThe USB port ID the hub is connected to
channelThe motor channel

◆ ~ExpansionHubMotor()

wpi::ExpansionHubMotor::~ExpansionHubMotor ( )
noexcept

Member Function Documentation

◆ Follow()

void wpi::ExpansionHubMotor::Follow ( const ExpansionHubMotor & leader)

Sets this motor to follow another motor on the same hub.

This does not support following motors that are also followers. Additionally, the direction of both motors will be the same.

Parameters
leaderThe motor to follow

◆ GetCurrent()

wpi::units::ampere_t wpi::ExpansionHubMotor::GetCurrent ( ) const

Gets the current being pulled by the motor.

Returns
Motor current

◆ GetEncoderPosition()

double wpi::ExpansionHubMotor::GetEncoderPosition ( ) const

Gets the current position of the motor encoder.

Scaled into distancePerCount units.

Returns
Encoder position

◆ GetEncoderVelocity()

double wpi::ExpansionHubMotor::GetEncoderVelocity ( ) const

Gets the current velocity of the motor encoder.

Scaled into distancePerCount units.

Returns
Encoder velocity

◆ GetPositionPidConstants()

ExpansionHubPidConstants & wpi::ExpansionHubMotor::GetPositionPidConstants ( )

Gets the PID constants object for position PID.

Returns
Position PID constants object

◆ GetVelocityPidConstants()

ExpansionHubPidConstants & wpi::ExpansionHubMotor::GetVelocityPidConstants ( )

Gets the PID constants object for velocity PID.

Returns
Velocity PID constants object

◆ IsHubConnected()

bool wpi::ExpansionHubMotor::IsHubConnected ( )
inline

Gets if the underlying ExpansionHub is connected.

Returns
True if hub is connected, otherwise false

◆ ResetEncoder()

void wpi::ExpansionHubMotor::ResetEncoder ( )

Reset the encoder count to 0.

◆ SetDistancePerCount()

void wpi::ExpansionHubMotor::SetDistancePerCount ( double perCount)

Sets the distance per count of the encoder.

Used to scale encoder readings.

Parameters
perCountThe distance moved per count of the encoder

◆ SetDutyCycle()

void wpi::ExpansionHubMotor::SetDutyCycle ( double dutyCycle)

Sets the duty cycle.

Parameters
dutyCycleThe duty cycle between -1 and 1 (sign indicates direction).

◆ SetEnabled()

void wpi::ExpansionHubMotor::SetEnabled ( bool enabled)

Sets if the motor output is enabled or not.

Defaults to false.

Parameters
enabledTrue to enable, false to disable

◆ SetFloatOn0()

void wpi::ExpansionHubMotor::SetFloatOn0 ( bool floatOn0)

Sets if the motor should float or brake when 0 is commanded.

Defaults to false.

Parameters
floatOn0True to float when commanded 0, false to brake

◆ SetPositionSetpoint()

void wpi::ExpansionHubMotor::SetPositionSetpoint ( double setpoint)

Command the motor to drive to a specific position setpoint.

This value will be scaled by SetDistancePerCount and influenced by the PID constants.

Parameters
setpointThe position setpoint to drive the motor to

◆ SetReversed()

void wpi::ExpansionHubMotor::SetReversed ( bool reversed)

Sets if the motor and encoder should be reversed.

Parameters
reversedTrue to reverse encoder, false otherwise

◆ SetVelocitySetpoint()

void wpi::ExpansionHubMotor::SetVelocitySetpoint ( double setpoint)

Command the motor to drive to a specific velocity setpoint.

This value will be scaled by SetDistancePerCount and influenced by the PID constants.

Parameters
setpointThe velocity setpoint to drive the motor to

◆ SetVoltage()

void wpi::ExpansionHubMotor::SetVoltage ( wpi::units::volt_t voltage)

Sets the voltage to run the motor at.

This value will be continously scaled to match the input voltage.

Parameters
voltageThe voltage to drive the motor at

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