BaseMotor
An abstract implementation of the Motor interface. This class provides a base for motor implementations, handling common functionalities like power inversion, power limits, lazy setting, and deadband.
Key Concepts
- Inversion: The motor's power can be inverted for both setting (
isSetInverted) and getting (isGetInverted). This is useful if the motor is physically mounted in reverse. - Power Limits: You can set a minimum (
minPower) and maximum (maxPower) power value. Any power set outside this range will be clamped. - Lazy Mode: When enabled (
isLazy), the motor power is only physically updated if the new power value differs from the last set power by more thanmaxLazyPowerGap. This can reduce unnecessary hardware calls. - Deadband: A
deadbandcan be set to prevent the motor from moving at very low power values, which can cause whining or unnecessary heat. Any power with an absolute value less than the deadband will be treated as zero.
Methods
getMinPower()
Returns the configured minimum power for the motor.
setMinPower(double minPower)
Sets the minimum power for the motor. Any power value set below this will be clamped to this minimum.
getMaxPower()
Returns the configured maximum power for the motor.
setMaxPower(double maxPower)
Sets the maximum power for the motor. Any power value set above this will be clamped to this maximum.
isLazy()
Returns true if lazy mode is enabled, false otherwise.
setLazy(boolean isLazy)
Enables or disables lazy mode.
getMaxPowerGap()
Returns the maximum power gap used in lazy mode.
setMaxPowerGap(double maxPowerGap)
Sets the maximum power gap for lazy mode.
getDeadband()
Returns the configured deadband value.
setDeadband(double deadband)
Sets the motor's deadband. Power values with a magnitude smaller than this will be set to 0.
setIsSetInverted(boolean isSetInverted)
Configures whether the power value is inverted when setPower() is called.
setIsGetInverted(boolean isGetInverted)
Configures whether the power value is inverted when getPower() is called.
setIsInverted(boolean isInverted)
A convenience method to set both the set and get inversion states simultaneously.
getPower()
Gets the last power value set to the motor, respecting the get inversion flag.
setPower(double power)
Sets the power of the motor. This method applies clamping, deadband, inversion, and lazy mode logic before calling the abstract abstractSetPower() method.
abstractSetPower(double power)
An abstract method that must be implemented by subclasses to physically set the motor's power.
abstractGetPower()
An abstract method that can be overridden by subclasses to get the physical motor's power. By default, it returns the last power value set.