Class MockDcMotorEx
java.lang.Object
org.firstinspires.ftc.teamcode.fakestuff.MockDcMotorEx
- All Implemented Interfaces:
com.qualcomm.robotcore.hardware.DcMotor
,com.qualcomm.robotcore.hardware.DcMotorEx
,com.qualcomm.robotcore.hardware.DcMotorSimple
,com.qualcomm.robotcore.hardware.HardwareDevice
This appears as a normal
DcMotorEx
to your program, and it even updates the position for
you over time based on the set velocity and can determine the velocity the motor is running at
based on the set power (approximated as a percentage of the maximum velocity). It also handles
DcMotor.RunMode
.RUN_TO_POSITION mode, running at the set
power until the position is reached. Remember that this simulated class is perfect, without the
natural variance of a real motor. Have your test put this "device" into the
HardwareMap
with the correct name so that the test
subject can get it.-
Nested Class Summary
Nested classes/interfaces inherited from interface com.qualcomm.robotcore.hardware.DcMotor
com.qualcomm.robotcore.hardware.DcMotor.RunMode, com.qualcomm.robotcore.hardware.DcMotor.ZeroPowerBehavior
Nested classes/interfaces inherited from interface com.qualcomm.robotcore.hardware.DcMotorSimple
com.qualcomm.robotcore.hardware.DcMotorSimple.Direction
Nested classes/interfaces inherited from interface com.qualcomm.robotcore.hardware.HardwareDevice
com.qualcomm.robotcore.hardware.HardwareDevice.Manufacturer
-
Constructor Summary
ConstructorsConstructorDescriptionMockDcMotorEx
(com.qualcomm.robotcore.hardware.DcMotorSimple.Direction direction, com.qualcomm.robotcore.hardware.configuration.typecontainers.MotorConfigurationType motorType, com.qualcomm.robotcore.util.ElapsedTime elapsedTime) MockDcMotorEx
(com.qualcomm.robotcore.hardware.DcMotorSimple.Direction direction, com.qualcomm.robotcore.util.ElapsedTime elapsedTime) MockDcMotorEx
(com.qualcomm.robotcore.util.ElapsedTime elapsedTime) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Calls setPowerFloat() (matches the original implementation)Returns "This motor shares a connection with its friends."com.qualcomm.robotcore.hardware.DcMotorController
Unsupported Operationdouble
getCurrent
(org.firstinspires.ftc.robotcore.external.navigation.CurrentUnit unit) Unsupported Operationdouble
getCurrentAlert
(org.firstinspires.ftc.robotcore.external.navigation.CurrentUnit unit) Unsupported Operationint
Returns "Mockery 0 RPM motor"com.qualcomm.robotcore.hardware.DcMotorSimple.Direction
com.qualcomm.robotcore.hardware.HardwareDevice.Manufacturer
ReturnsHardwareDevice.Manufacturer
.UNKNOWNcom.qualcomm.robotcore.hardware.DcMotor.RunMode
getMode()
com.qualcomm.robotcore.hardware.configuration.typecontainers.MotorConfigurationType
com.qualcomm.robotcore.hardware.PIDCoefficients
getPIDCoefficients
(com.qualcomm.robotcore.hardware.DcMotor.RunMode mode) com.qualcomm.robotcore.hardware.PIDFCoefficients
getPIDFCoefficients
(com.qualcomm.robotcore.hardware.DcMotor.RunMode mode) int
Should return -1, which is the SDK's default before it gets setdouble
getPower()
boolean
Returns if the motor is simply floating, completely unpowered.int
int
double
double
getVelocity
(org.firstinspires.ftc.robotcore.external.navigation.AngleUnit unit) int
Returns 51825com.qualcomm.robotcore.hardware.DcMotor.ZeroPowerBehavior
boolean
isBusy()
This implementation, and seemingly the SDK's, returns whether or not the current position is the target position (the target has been reached, we're not still moving towards it).boolean
boolean
Unsupported Operationvoid
Sets theDcMotorSimple.Direction
to FORWARD.void
setCurrentAlert
(double current, org.firstinspires.ftc.robotcore.external.navigation.CurrentUnit unit) Unsupported Operationvoid
setDirection
(com.qualcomm.robotcore.hardware.DcMotorSimple.Direction direction) void
setMaxVelocityTicks
(double maxVelocityTicks) For use by your test - sets the maximum velocity of the motor in ticks per secondvoid
setMode
(com.qualcomm.robotcore.hardware.DcMotor.RunMode mode) void
void
void
setMotorType
(com.qualcomm.robotcore.hardware.configuration.typecontainers.MotorConfigurationType motorType) void
setPIDCoefficients
(com.qualcomm.robotcore.hardware.DcMotor.RunMode mode, com.qualcomm.robotcore.hardware.PIDCoefficients pidCoefficients) void
setPIDFCoefficients
(com.qualcomm.robotcore.hardware.DcMotor.RunMode mode, com.qualcomm.robotcore.hardware.PIDFCoefficients pidfCoefficients) void
setPosition
(int position) void
setPositionPIDFCoefficients
(double p) void
setPower
(double power) void
The name of this method is confusing.void
setTargetPosition
(int position) void
setTargetPositionTolerance
(int tolerance) void
setTicksPerRotation
(double ticksPerRotation) For use by your test - sets the ticks counted by the encoder on each rotation of the motorvoid
setVelocity
(double angularRate) void
setVelocity
(double angularRate, org.firstinspires.ftc.robotcore.external.navigation.AngleUnit unit) void
setVelocityPIDFCoefficients
(double p, double i, double d, double f) void
setZeroPowerBehavior
(com.qualcomm.robotcore.hardware.DcMotor.ZeroPowerBehavior zeroPowerBehavior)
-
Constructor Details
-
MockDcMotorEx
public MockDcMotorEx(com.qualcomm.robotcore.util.ElapsedTime elapsedTime) -
MockDcMotorEx
public MockDcMotorEx(com.qualcomm.robotcore.hardware.DcMotorSimple.Direction direction, com.qualcomm.robotcore.util.ElapsedTime elapsedTime) -
MockDcMotorEx
public MockDcMotorEx(com.qualcomm.robotcore.hardware.DcMotorSimple.Direction direction, @NonNull com.qualcomm.robotcore.hardware.configuration.typecontainers.MotorConfigurationType motorType, com.qualcomm.robotcore.util.ElapsedTime elapsedTime)
-
-
Method Details
-
setMotorEnable
public void setMotorEnable()- Specified by:
setMotorEnable
in interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
setMotorDisable
public void setMotorDisable()- Specified by:
setMotorDisable
in interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
isMotorEnabled
public boolean isMotorEnabled()- Specified by:
isMotorEnabled
in interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
setVelocity
public void setVelocity(double angularRate) - Specified by:
setVelocity
in interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
getVelocity
public double getVelocity()- Specified by:
getVelocity
in interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
setPIDCoefficients
public void setPIDCoefficients(com.qualcomm.robotcore.hardware.DcMotor.RunMode mode, com.qualcomm.robotcore.hardware.PIDCoefficients pidCoefficients) - Specified by:
setPIDCoefficients
in interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
setPIDFCoefficients
public void setPIDFCoefficients(com.qualcomm.robotcore.hardware.DcMotor.RunMode mode, com.qualcomm.robotcore.hardware.PIDFCoefficients pidfCoefficients) throws UnsupportedOperationException - Specified by:
setPIDFCoefficients
in interfacecom.qualcomm.robotcore.hardware.DcMotorEx
- Throws:
UnsupportedOperationException
-
setVelocityPIDFCoefficients
public void setVelocityPIDFCoefficients(double p, double i, double d, double f) - Specified by:
setVelocityPIDFCoefficients
in interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
setPositionPIDFCoefficients
public void setPositionPIDFCoefficients(double p) - Specified by:
setPositionPIDFCoefficients
in interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
getPIDCoefficients
public com.qualcomm.robotcore.hardware.PIDCoefficients getPIDCoefficients(com.qualcomm.robotcore.hardware.DcMotor.RunMode mode) - Specified by:
getPIDCoefficients
in interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
getPIDFCoefficients
public com.qualcomm.robotcore.hardware.PIDFCoefficients getPIDFCoefficients(com.qualcomm.robotcore.hardware.DcMotor.RunMode mode) - Specified by:
getPIDFCoefficients
in interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
setTargetPositionTolerance
public void setTargetPositionTolerance(int tolerance) - Specified by:
setTargetPositionTolerance
in interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
getTargetPositionTolerance
public int getTargetPositionTolerance()- Specified by:
getTargetPositionTolerance
in interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
isOverCurrent
public boolean isOverCurrent()Unsupported Operation- Specified by:
isOverCurrent
in interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
getMotorType
public com.qualcomm.robotcore.hardware.configuration.typecontainers.MotorConfigurationType getMotorType()- Specified by:
getMotorType
in interfacecom.qualcomm.robotcore.hardware.DcMotor
-
setMotorType
public void setMotorType(com.qualcomm.robotcore.hardware.configuration.typecontainers.MotorConfigurationType motorType) - Specified by:
setMotorType
in interfacecom.qualcomm.robotcore.hardware.DcMotor
-
getController
public com.qualcomm.robotcore.hardware.DcMotorController getController()Unsupported Operation- Specified by:
getController
in interfacecom.qualcomm.robotcore.hardware.DcMotor
-
getPortNumber
public int getPortNumber()Should return -1, which is the SDK's default before it gets set- Specified by:
getPortNumber
in interfacecom.qualcomm.robotcore.hardware.DcMotor
-
setZeroPowerBehavior
public void setZeroPowerBehavior(com.qualcomm.robotcore.hardware.DcMotor.ZeroPowerBehavior zeroPowerBehavior) - Specified by:
setZeroPowerBehavior
in interfacecom.qualcomm.robotcore.hardware.DcMotor
-
getZeroPowerBehavior
public com.qualcomm.robotcore.hardware.DcMotor.ZeroPowerBehavior getZeroPowerBehavior()- Specified by:
getZeroPowerBehavior
in interfacecom.qualcomm.robotcore.hardware.DcMotor
-
setPowerFloat
public void setPowerFloat()The name of this method is confusing. It simply sets the power to 0 and sets theDcMotor.ZeroPowerBehavior
to FLOAT. This completely removes power from the motor.- Specified by:
setPowerFloat
in interfacecom.qualcomm.robotcore.hardware.DcMotor
-
getPowerFloat
public boolean getPowerFloat()Returns if the motor is simply floating, completely unpowered. Specifically, returns if the power is set to 0 and theDcMotor.ZeroPowerBehavior
is set to FLOAT.- Specified by:
getPowerFloat
in interfacecom.qualcomm.robotcore.hardware.DcMotor
-
setTargetPosition
public void setTargetPosition(int position) - Specified by:
setTargetPosition
in interfacecom.qualcomm.robotcore.hardware.DcMotor
-
getTargetPosition
public int getTargetPosition()- Specified by:
getTargetPosition
in interfacecom.qualcomm.robotcore.hardware.DcMotor
-
isBusy
public boolean isBusy()This implementation, and seemingly the SDK's, returns whether or not the current position is the target position (the target has been reached, we're not still moving towards it).- Specified by:
isBusy
in interfacecom.qualcomm.robotcore.hardware.DcMotor
-
getCurrentPosition
public int getCurrentPosition()- Specified by:
getCurrentPosition
in interfacecom.qualcomm.robotcore.hardware.DcMotor
-
setMode
public void setMode(com.qualcomm.robotcore.hardware.DcMotor.RunMode mode) - Specified by:
setMode
in interfacecom.qualcomm.robotcore.hardware.DcMotor
-
getMode
public com.qualcomm.robotcore.hardware.DcMotor.RunMode getMode()- Specified by:
getMode
in interfacecom.qualcomm.robotcore.hardware.DcMotor
-
setDirection
public void setDirection(com.qualcomm.robotcore.hardware.DcMotorSimple.Direction direction) - Specified by:
setDirection
in interfacecom.qualcomm.robotcore.hardware.DcMotorSimple
-
getDirection
public com.qualcomm.robotcore.hardware.DcMotorSimple.Direction getDirection()- Specified by:
getDirection
in interfacecom.qualcomm.robotcore.hardware.DcMotorSimple
-
setPower
public void setPower(double power) - Specified by:
setPower
in interfacecom.qualcomm.robotcore.hardware.DcMotorSimple
-
getPower
public double getPower()- Specified by:
getPower
in interfacecom.qualcomm.robotcore.hardware.DcMotorSimple
-
getManufacturer
public com.qualcomm.robotcore.hardware.HardwareDevice.Manufacturer getManufacturer()ReturnsHardwareDevice.Manufacturer
.UNKNOWN- Specified by:
getManufacturer
in interfacecom.qualcomm.robotcore.hardware.HardwareDevice
-
getDeviceName
Returns "Mockery 0 RPM motor"- Specified by:
getDeviceName
in interfacecom.qualcomm.robotcore.hardware.HardwareDevice
-
getConnectionInfo
Returns "This motor shares a connection with its friends."- Specified by:
getConnectionInfo
in interfacecom.qualcomm.robotcore.hardware.HardwareDevice
-
getVersion
public int getVersion()Returns 51825- Specified by:
getVersion
in interfacecom.qualcomm.robotcore.hardware.HardwareDevice
-
resetDeviceConfigurationForOpMode
public void resetDeviceConfigurationForOpMode()Sets theDcMotorSimple.Direction
to FORWARD. (matches the original implementation)- Specified by:
resetDeviceConfigurationForOpMode
in interfacecom.qualcomm.robotcore.hardware.HardwareDevice
-
close
public void close()Calls setPowerFloat() (matches the original implementation)- Specified by:
close
in interfacecom.qualcomm.robotcore.hardware.HardwareDevice
-
setMaxVelocityTicks
public void setMaxVelocityTicks(double maxVelocityTicks) For use by your test - sets the maximum velocity of the motor in ticks per second -
setTicksPerRotation
public void setTicksPerRotation(double ticksPerRotation) For use by your test - sets the ticks counted by the encoder on each rotation of the motor -
setPosition
public void setPosition(int position)
-