ExpansionHubMotor
- class wpilib.ExpansionHubMotor(usbId: SupportsInt | SupportsIndex, channel: SupportsInt | SupportsIndex)
Bases:
pybind11_objectThis class controls a specific motor and encoder hooked up to an ExpansionHub.
Constructs a servo at the requested channel on a specific USB port.
- Parameters:
usbId – The USB port ID the hub is connected to
channel – The motor channel
- follow(leader: wpilib._wpilib.ExpansionHubMotor) 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
- getCurrent() wpimath.units.amperes
Gets the current being pulled by the motor.
- Returns:
Motor current
- getEncoderPosition() float
Gets the current position of the motor encoder. Scaled into distancePerCount units.
- Returns:
Encoder position
- getEncoderVelocity() float
Gets the current velocity of the motor encoder. Scaled into distancePerCount units.
- Returns:
Encoder velocity
- getPositionConstants() wpilib._wpilib.ExpansionHubPositionConstants
Gets the PID constants object for position PID.
- Returns:
Position PID constants object
- getVelocityConstants() wpilib._wpilib.ExpansionHubVelocityConstants
Gets the PID constants object for velocity PID.
- Returns:
Velocity PID constants object
- isHubConnected() bool
Gets if the underlying ExpansionHub is connected.
- Returns:
True if hub is connected, otherwise false
- resetEncoder() None
Reset the encoder count to 0.
- setDistancePerCount(perCount: SupportsFloat | SupportsIndex) None
Sets the distance per count of the encoder. Used to scale encoder readings.
- Parameters:
perCount – The distance moved per count of the encoder
- setEnabled(enabled: bool) None
Sets if the motor output is enabled or not. Defaults to false.
- Parameters:
enabled – True to enable, false to disable
- setFloatOn0(floatOn0: bool) None
Sets if the motor should float or brake when 0 is commanded. Defaults to false.
- Parameters:
floatOn0 – True to float when commanded 0, false to brake
- setPositionSetpoint(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
- setReversed(reversed: bool) None
Sets if the motor and encoder should be reversed.
- Parameters:
reversed – True to reverse encoder, false otherwise
- setThrottle(throttle: SupportsFloat | SupportsIndex) None
Sets the throttle.
- Parameters:
throttle – The throttle where -1 indicates full reverse and 1 indicates full forward.
- setVelocitySetpoint(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
- setVoltage(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