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 motor constants object for position PID.Gets the motor 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.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.voidsetThrottle(double throttle) Sets the throttle.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
-
setThrottle
Sets the throttle.- Parameters:
throttle- The throttle where -1 represents full reverse and 1 represents full forward.
-
setVoltage
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
-
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. -
getVelocityConstants
Gets the motor constants object for velocity PID.- Returns:
- Velocity motor constants object
-
getPositionConstants
Gets the motor constants object for position PID.- Returns:
- Position motor 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
-