Motor

open class Motor : DcMotorImplEx

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 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(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
Link copied to clipboard
open var mode: DcMotor.RunMode

Inherited properties

Link copied to clipboard
protected open var controller: DcMotorController
Link copied to clipboard
protected open var direction: DcMotorSimple.Direction
Link copied to clipboard
protected open var motorType: MotorConfigurationType
Link copied to clipboard
protected open var portNumber: Int
Link copied to clipboard

Functions

Link copied to clipboard
Link copied to clipboard
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
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
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 setMaxPower(magnitude: Double)
Sets the maximum power magnitude (applies for both negative and positive powers) this motor can run at.
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 setPowerDeltaThreshold(magnitude: Double)
Set the delta in power required to propagate a hardware write.
Link copied to clipboard
open fun setPowerRefreshRate(refreshRate: Measure<Time>)
Set the refresh rate of the motor that will be a minimum time between hardware writes.
Link copied to clipboard
Set a system controller to use for RUN_TO_POSITION.
Link copied to clipboard
open fun setRunUsingEncoderController(controller: SystemController, bufferFraction: Double, maxAchievableTicksPerSecond: Double)
Set a system controller to use for RUN_USING_ENCODER.
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, 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
Call to use encoder overflow (exceeding 32767 ticks/sec) correction on getVelocity.

Inherited functions

Link copied to clipboard
protected open fun adjustAngularRate(angularRate: Double): Double
Link copied to clipboard
protected open fun adjustPosition(position: Int): Int
Link copied to clipboard
protected open fun adjustPower(power: Double): Double
Link copied to clipboard
open fun close()
Link copied to clipboard
Link copied to clipboard
open fun getController(): DcMotorController
Link copied to clipboard
open fun getCurrent(unit: CurrentUnit): Double
Link copied to clipboard
open fun getCurrentAlert(unit: CurrentUnit): Double
Link copied to clipboard
open fun getDeviceName(): String
Link copied to clipboard
open fun getDirection(): DcMotorSimple.Direction
Link copied to clipboard
open fun getManufacturer(): HardwareDevice.Manufacturer
Link copied to clipboard
open fun getMode(): DcMotor.RunMode
Link copied to clipboard
open fun getMotorType(): MotorConfigurationType
Link copied to clipboard
protected open fun getOperationalDirection(): DcMotorSimple.Direction
Link copied to clipboard
open fun getPIDCoefficients(mode: DcMotor.RunMode): PIDCoefficients
Link copied to clipboard
open fun getPIDFCoefficients(mode: DcMotor.RunMode): PIDFCoefficients
Link copied to clipboard
open fun getPortNumber(): Int
Link copied to clipboard
open fun getPower(): Double
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun getVersion(): Int
Link copied to clipboard
open fun getZeroPowerBehavior(): DcMotor.ZeroPowerBehavior
Link copied to clipboard
protected open fun internalSetMode(mode: DcMotor.RunMode)
Link copied to clipboard
protected open fun internalSetPower(power: Double)
Link copied to clipboard
protected open fun internalSetTargetPosition(position: Int)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun setCurrentAlert(current: Double, unit: CurrentUnit)
Link copied to clipboard
open fun setDirection(direction: DcMotorSimple.Direction)
Link copied to clipboard
open fun setMode(mode: DcMotor.RunMode)
Link copied to clipboard
open fun setMotorDisable()
Link copied to clipboard
open fun setMotorEnable()
Link copied to clipboard
open fun setMotorType(motorType: MotorConfigurationType)
Link copied to clipboard
open fun setPIDCoefficients(mode: DcMotor.RunMode, pidCoefficients: PIDCoefficients)
Link copied to clipboard
open fun setPIDFCoefficients(mode: DcMotor.RunMode, pidfCoefficients: PIDFCoefficients)
Link copied to clipboard
Link copied to clipboard
open fun setPowerFloat()
Link copied to clipboard
open fun setTargetPosition(position: Int)
Link copied to clipboard
Link copied to clipboard
open fun setZeroPowerBehavior(zeroPowerBehavior: DcMotor.ZeroPowerBehavior)