Class ExpansionHubMotor
java.lang.Object
org.wpilib.hardware.expansionhub.ExpansionHubMotor
- All Implemented Interfaces:
AutoCloseable
This class controls a specific motor and encoder hooked up to an ExpansionHub.
-
Constructor Summary
ConstructorsConstructorDescriptionExpansionHubMotor(int usbId, int channel) Constructs a servo at the requested channel on a specific USB port. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes a motor so another instance can be constructed.voidfollow(ExpansionHubMotor leader) Sets this motor to follow another motor on the same hub.Gets the current being pulled by the motor.doubleGets the current position of the motor encoder.doubleGets the current velocity of the motor encoder.Gets the PID constants object for position PID.Gets the PID constants object for velocity PID.booleanGets if the underlying ExpansionHub is connected.voidReset the encoder count to 0.voidsetDistancePerCount(double perCount) Sets the distance per count of the encoder.voidsetDutyCycle(double dutyCycle) Sets the duty cycle.voidsetEnabled(boolean enabled) Sets if the motor output is enabled or not.voidsetFloatOn0(boolean floatOn0) Sets if the motor should float or brake when 0 is commanded.voidsetPositionSetpoint(double setpoint) Command the motor to drive to a specific position setpoint.voidsetReversed(boolean reversed) Sets if the motor and encoder should be reversed.voidsetVelocitySetpoint(double setpoint) Command the motor to drive to a specific velocity setpoint.voidsetVoltage(Voltage voltage) Sets the voltage to run the motor at.
-
Constructor Details
-
ExpansionHubMotor
Constructs a servo at the requested channel on a specific USB port.- Parameters:
usbId- The USB port ID the hub is connected tochannel- The motor channel
-
-
Method Details
-
close
Closes a motor so another instance can be constructed.- Specified by:
closein interfaceAutoCloseable
-
setDutyCycle
Sets the duty cycle.- Parameters:
dutyCycle- The duty cycle between -1 and 1 (sign indicates direction).
-
setVoltage
Sets the voltage to run the motor at. This value will be continously scaled to match the input voltage.- Parameters:
voltage- The voltage to drive the motor at
-
setPositionSetpoint
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
-
setVelocitySetpoint
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
-
setEnabled
Sets if the motor output is enabled or not. Defaults to false.- Parameters:
enabled- True to enable, false to disable
-
setFloatOn0
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
-
getCurrent
-
setDistancePerCount
Sets the distance per count of the encoder. Used to scale encoder readings.- Parameters:
perCount- The distance moved per count of the encoder
-
isHubConnected
Gets if the underlying ExpansionHub is connected.- Returns:
- True if hub is connected, otherwise false
-
getEncoderVelocity
Gets the current velocity of the motor encoder. Scaled into distancePerCount units.- Returns:
- Encoder velocity
-
getEncoderPosition
Gets the current position of the motor encoder. Scaled into distancePerCount units.- Returns:
- Encoder position
-
setReversed
Sets if the motor and encoder should be reversed.- Parameters:
reversed- True to reverse encoder, false otherwise
-
resetEncoder
Reset the encoder count to 0. -
getVelocityPidConstants
Gets the PID constants object for velocity PID.- Returns:
- Velocity PID constants object
-
getPositionPidConstants
Gets the PID constants object for position PID.- Returns:
- Position PID constants object
-
follow
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
-