Motor

open class Motor : SimpleRotator, DcMotorEx

Drop-in replacement for a DcMotor that uses custom control algorithms to operate RUN_USING_ENCODER and RUN_TO_POSITION modes. Internally integrates a gain scheduler to allow for more precise system coefficients against gravity and other external forces. This class effectively wraps an entire DcMotor and regulates all of the operations.

This class is designed to be down casted to a DcMotor where used, integrating with the current motor modes while providing faster, predictable control systems.

Author

Lucas Bubner, 2024

Since

4.0.0

Constructors

Link copied to clipboard
constructor(@NonNull motor: DcMotor)
Wrap a DcMotor to use in the Motor class.

Types

Link copied to clipboard
open inner class GainScheduling
Gain scheduler builder which will interpolate on build and populate gains.

Properties

Link copied to clipboard
protected val controller: DcMotorControllerEx
Link copied to clipboard
The encoder object that is used for position and velocity readings on this motor.
Link copied to clipboard
@get:NonNull
open var mode: DcMotor.RunMode
Link copied to clipboard
protected val port: Int

Functions

Link copied to clipboard
open fun debug(@NonNull motor: DcMotor, @NonNull name: String, @NonNull telemetry: Telemetry)
Utility for debugging an encoder on telemetry with current encoder/power information.
Link copied to clipboard
Link copied to clipboard
open fun getController(): DcMotorController
Returns the underlying motor controller on which this motor is situated.
Link copied to clipboard
open fun getCurrent(@NonNull unit: CurrentUnit): Double
Returns the current consumed by this motor.
Link copied to clipboard
open fun getCurrentAlert(@NonNull unit: CurrentUnit): Double
Returns the current alert for this motor.
Link copied to clipboard
Link copied to clipboard
open fun getMotorType(): MotorConfigurationType
Returns the assigned type for this motor.
Link copied to clipboard
open fun getPIDCoefficients(@NonNull mode: DcMotor.RunMode): PIDCoefficients
Returns the PID control coefficients used when running in the indicated mode on this motor.
Link copied to clipboard
open fun getPIDFCoefficients(@NonNull mode: DcMotor.RunMode): PIDFCoefficients
Returns the PIDF control coefficients used when running in the indicated mode on this motor.
Link copied to clipboard
open fun getPortNumber(): Int
Returns the port number on the underlying motor controller on which this motor is situated.
Link copied to clipboard
Returns whether the motor is currently in a float power level.
Link copied to clipboard
Returns the current target encoder position for this motor.
Link copied to clipboard
Note that this method will try to access the RUN_TO_POSITION controller to access information there.
Link copied to clipboard
open fun getVelocity(): Double

open fun getVelocity(@NonNull unit: AngleUnit): Double
Returns the current velocity of the motor, in angular units per second
Link copied to clipboard
open fun getZeroPowerBehavior(): DcMotor.ZeroPowerBehavior
Returns the current behavior of the motor were a power level of zero to be applied.
Link copied to clipboard
open fun isBusy(): Boolean
Note that this method will try to access the RUN_TO_POSITION controller to access information there.
Link copied to clipboard
Returns whether this motor is energized
Link copied to clipboard
Returns whether the current consumption of this motor exceeds the alert threshold.
Link copied to clipboard
open fun resetEncoder()
Reset the encoder value without stopping the motor.
Link copied to clipboard
Call to build a list of encoder tick positions where you want your RUN_TO_POSITION system controller gains to be.
Link copied to clipboard
Call to build a list of encoder tick positions where you want your RUN_USING_ENCODER system controller gains to be.
Link copied to clipboard
open fun setCurrentAlert(current: Double, @NonNull unit: CurrentUnit)
Sets the current alert for this motor
Link copied to clipboard
open fun setMotorDisable()
Individually de-energizes this particular motor
Link copied to clipboard
open fun setMotorEnable()
Individually energizes this particular motor
Link copied to clipboard
open fun setMotorType(@NonNull motorType: MotorConfigurationType)
Sets the assigned type of this motor.
Link copied to clipboard
open fun setNominalVoltage(@NonNull nominalVoltage: Measure<Voltage>)
Sets the nominal voltage to use for power calculations.
Link copied to clipboard
open fun setNominalVoltageSensor(@NonNull nominalVoltageSensorMapping: HardwareMap.DeviceMapping<VoltageSensor>)
Sets a voltage sensor to use for nominal power calculation.
Link copied to clipboard
open fun setPIDCoefficients(@NonNull mode: DcMotor.RunMode, @NonNull pidCoefficients: PIDCoefficients)
Sets the PID control coefficients for one of the PID modes of this motor.
Link copied to clipboard
open fun setPIDFCoefficients(@NonNull mode: DcMotor.RunMode, @NonNull pidfCoefficients: PIDFCoefficients)
This method is a superset enhancement to setPIDCoefficients.
Link copied to clipboard
A shorthand for setting the P coefficient for the RUN_TO_POSITION mode.
Link copied to clipboard
open fun setPower(power: Double)
Update system controllers and propagate new power levels to the motor.
Link copied to clipboard
open fun setPowerFloat()
Sets the zero power behavior of the motor to FLOAT, then applies zero power to that motor.
Link copied to clipboard
Set a system controller to use for RUN_TO_POSITION.
Link copied to clipboard
open fun setRunUsingEncoderController(bufferFraction: Double, @NonNull controller: SystemController)
open fun setRunUsingEncoderController(bufferFraction: Double, maxAchievableTicksPerSecond: Double, @Nullable controller: SystemController)
Set a system controller to use for RUN_USING_ENCODER.
Link copied to clipboard
open fun setTargetPosition(position: Int)
Sets the desired encoder target position to which the motor should advance or retreat and then actively hold thereat.
Link copied to clipboard
open fun setTargetPositionTolerance(tolerance: Int)
Note that this method will try to access the RUN_TO_POSITION controller to access information there.
Link copied to clipboard
open fun setVelocity(vel: Double)
Switches the motor to velocity control and tries to set the ticks/sec target.
open fun setVelocity(angVel: Double, @NonNull unit: AngleUnit)
Switches the motor to velocity control and tries to set the angular velocity of the motor based on the intrinsic MotorConfigurationType configuration.
Link copied to clipboard
A shorthand for setting the PIDF coefficients for the RUN_USING_ENCODER mode.
Link copied to clipboard
open fun setZeroPowerBehavior(@NonNull zeroPowerBehavior: DcMotor.ZeroPowerBehavior)
Sets the behavior of the motor when a power level of zero is applied.
Link copied to clipboard
Call to use encoder overflow (exceeding 32767 ticks/sec) correction on getVelocity.

Inherited functions

Link copied to clipboard
open fun close()
abstract fun close()
Link copied to clipboard
Link copied to clipboard
abstract fun getDeviceName(): String
Link copied to clipboard
open fun getDirection(): DcMotorSimple.Direction
abstract fun getDirection(): DcMotorSimple.Direction
Link copied to clipboard
open fun getManufacturer(): HardwareDevice.Manufacturer
abstract fun getManufacturer(): HardwareDevice.Manufacturer
Link copied to clipboard
abstract fun getMode(): DcMotor.RunMode
Link copied to clipboard
open fun getPower(): Double
abstract fun getPower(): Double
Link copied to clipboard
open fun getVersion(): Int
abstract fun getVersion(): Int
Link copied to clipboard
open fun setDirection(@NonNull direction: DcMotorSimple.Direction)
abstract fun setDirection(p: DcMotorSimple.Direction)
Link copied to clipboard
open fun setMaxPower(magnitude: Double)
Sets the maximum power magnitude (applies for both negative and positive powers) this motor can run at.
Link copied to clipboard
abstract fun setMode(p: DcMotor.RunMode)
Link copied to clipboard
open fun setPowerDeltaThreshold(magnitude: Double)
Set the delta in power required to propagate a hardware write.
Link copied to clipboard
open fun setPowerRefreshRate(@NonNull refreshRate: Measure<Time>)
Set the refresh rate of the motor that will be a minimum time between hardware writes.