ExpansionHubMotor

class wpilib.ExpansionHubMotor(usb_id: SupportsInt | SupportsIndex, channel: SupportsInt | SupportsIndex)

Bases: pybind11_object

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

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

Parameters:
  • usb_id – The USB port ID the hub is connected to

  • channel – The motor channel

class FollowDirection(value: SupportsInt | SupportsIndex)

Bases: pybind11_object

The direction to follow a leader motor in when using the follow method.

Members:

ALIGNED : Follow the leader motor in the same direction.

OPPOSED : Follow the leader motor in the opposite direction.

ALIGNED = <FollowDirection.ALIGNED: 0>
OPPOSED = <FollowDirection.OPPOSED: 1>
ExpansionHubMotor.FollowDirection.name -> str
property value
class NeutralMode(value: SupportsInt | SupportsIndex)

Bases: pybind11_object

Neutral mode applied when the motor output is commanded to 0.

Members:

COAST : Allow the motor to coast when output is zero.

BRAKE : Actively brake the motor when output is zero.

BRAKE = <NeutralMode.BRAKE: 1>
COAST = <NeutralMode.COAST: 0>
ExpansionHubMotor.NeutralMode.name -> str
property value
follow(leader: wpilib._wpilib.ExpansionHubMotor, direction: wpilib._wpilib.ExpansionHubMotor.FollowDirection) None

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:
  • leader – The motor to follow

  • direction – The direction to follow the leader

get_current() wpimath.units.amperes

Gets the current being pulled by the motor.

Returns:

Motor current

get_encoder_position() float

Gets the current position of the motor encoder. Scaled into distancePerCount units.

Returns:

Encoder position

get_encoder_velocity() float

Gets the current velocity of the motor encoder. Scaled into distancePerCount units.

Returns:

Encoder velocity

get_position_constants() wpilib._wpilib.ExpansionHubPositionConstants

Gets the PID constants object for position PID.

Returns:

Position PID constants object

get_velocity_constants() wpilib._wpilib.ExpansionHubVelocityConstants

Gets the PID constants object for velocity PID.

Returns:

Velocity PID constants object

is_hub_connected() bool

Gets if the underlying ExpansionHub is connected.

Returns:

True if hub is connected, otherwise false

reset_encoder() None

Reset the encoder count to 0.

set_distance_per_count(per_count: SupportsFloat | SupportsIndex) None

Sets the distance per count of the encoder. Used to scale encoder readings.

Parameters:

per_count – The distance moved per count of the encoder

set_enabled(enabled: bool) None

Sets if the motor output is enabled or not. Defaults to false.

Parameters:

enabled – True to enable, false to disable

set_neutral_mode(mode: wpilib._wpilib.ExpansionHubMotor.NeutralMode) None

Sets if the motor should brake or coast when 0 is commanded. Defaults to BRAKE mode.

Parameters:

mode – Neutral mode to apply when output is zero.

set_position_setpoint(setpoint: SupportsFloat | SupportsIndex) None

Command the motor to drive to a specific position setpoint. This value will be scaled by SetDistancePerCount and influenced by the PID constants.

Parameters:

setpoint – The position setpoint to drive the motor to

set_reversed(reversed: bool) None

Sets if the motor and encoder should be reversed.

Parameters:

reversed – True to reverse encoder, false otherwise

set_throttle(throttle: SupportsFloat | SupportsIndex) None

Sets the throttle.

Parameters:

throttle – The throttle where -1 indicates full reverse and 1 indicates full forward.

set_velocity_setpoint(setpoint: SupportsFloat | SupportsIndex) None

Command the motor to drive to a specific velocity setpoint. This value will be scaled by SetDistancePerCount and influenced by the PID constants.

Parameters:

setpoint – The velocity setpoint to drive the motor to

set_voltage(voltage: wpimath.units.volts) None

Sets the voltage to run the motor at. This value will be continuously scaled to match the input voltage.

Parameters:

voltage – The voltage to drive the motor at

unfollow() None

Stops following the currently set leader motor.