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.ZeroPowerBehaviorNested classes/interfaces inherited from interface com.qualcomm.robotcore.hardware.DcMotorSimple
com.qualcomm.robotcore.hardware.DcMotorSimple.DirectionNested 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 TypeMethodDescriptionvoidclose()Calls setPowerFloat() (matches the original implementation)Returns "This motor shares a connection with its friends."com.qualcomm.robotcore.hardware.DcMotorControllerUnsupported OperationdoublegetCurrent(org.firstinspires.ftc.robotcore.external.navigation.CurrentUnit unit) Unsupported OperationdoublegetCurrentAlert(org.firstinspires.ftc.robotcore.external.navigation.CurrentUnit unit) Unsupported OperationintReturns "Mockery 0 RPM motor"com.qualcomm.robotcore.hardware.DcMotorSimple.Directioncom.qualcomm.robotcore.hardware.HardwareDevice.ManufacturerReturnsHardwareDevice.Manufacturer.UNKNOWNcom.qualcomm.robotcore.hardware.DcMotor.RunModegetMode()com.qualcomm.robotcore.hardware.configuration.typecontainers.MotorConfigurationTypecom.qualcomm.robotcore.hardware.PIDCoefficientsgetPIDCoefficients(com.qualcomm.robotcore.hardware.DcMotor.RunMode mode) com.qualcomm.robotcore.hardware.PIDFCoefficientsgetPIDFCoefficients(com.qualcomm.robotcore.hardware.DcMotor.RunMode mode) intShould return -1, which is the SDK's default before it gets setdoublegetPower()booleanReturns if the motor is simply floating, completely unpowered.intintdoubledoublegetVelocity(org.firstinspires.ftc.robotcore.external.navigation.AngleUnit unit) intReturns 51825com.qualcomm.robotcore.hardware.DcMotor.ZeroPowerBehaviorbooleanisBusy()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).booleanbooleanUnsupported OperationvoidSets theDcMotorSimple.Directionto FORWARD.voidsetCurrentAlert(double current, org.firstinspires.ftc.robotcore.external.navigation.CurrentUnit unit) Unsupported OperationvoidsetDirection(com.qualcomm.robotcore.hardware.DcMotorSimple.Direction direction) voidsetMaxVelocityTicks(double maxVelocityTicks) For use by your test - sets the maximum velocity of the motor in ticks per secondvoidsetMode(com.qualcomm.robotcore.hardware.DcMotor.RunMode mode) voidvoidvoidsetMotorType(com.qualcomm.robotcore.hardware.configuration.typecontainers.MotorConfigurationType motorType) voidsetPIDCoefficients(com.qualcomm.robotcore.hardware.DcMotor.RunMode mode, com.qualcomm.robotcore.hardware.PIDCoefficients pidCoefficients) voidsetPIDFCoefficients(com.qualcomm.robotcore.hardware.DcMotor.RunMode mode, com.qualcomm.robotcore.hardware.PIDFCoefficients pidfCoefficients) voidsetPosition(int position) voidsetPositionPIDFCoefficients(double p) voidsetPower(double power) voidThe name of this method is confusing.voidsetTargetPosition(int position) voidsetTargetPositionTolerance(int tolerance) voidsetTicksPerRotation(double ticksPerRotation) For use by your test - sets the ticks counted by the encoder on each rotation of the motorvoidsetVelocity(double angularRate) voidsetVelocity(double angularRate, org.firstinspires.ftc.robotcore.external.navigation.AngleUnit unit) voidsetVelocityPIDFCoefficients(double p, double i, double d, double f) voidsetZeroPowerBehavior(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:
setMotorEnablein interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
setMotorDisable
public void setMotorDisable()- Specified by:
setMotorDisablein interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
isMotorEnabled
public boolean isMotorEnabled()- Specified by:
isMotorEnabledin interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
setVelocity
public void setVelocity(double angularRate) - Specified by:
setVelocityin interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
getVelocity
public double getVelocity()- Specified by:
getVelocityin interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
setPIDCoefficients
public void setPIDCoefficients(com.qualcomm.robotcore.hardware.DcMotor.RunMode mode, com.qualcomm.robotcore.hardware.PIDCoefficients pidCoefficients) - Specified by:
setPIDCoefficientsin 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:
setPIDFCoefficientsin interfacecom.qualcomm.robotcore.hardware.DcMotorEx- Throws:
UnsupportedOperationException
-
setVelocityPIDFCoefficients
public void setVelocityPIDFCoefficients(double p, double i, double d, double f) - Specified by:
setVelocityPIDFCoefficientsin interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
setPositionPIDFCoefficients
public void setPositionPIDFCoefficients(double p) - Specified by:
setPositionPIDFCoefficientsin interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
getPIDCoefficients
public com.qualcomm.robotcore.hardware.PIDCoefficients getPIDCoefficients(com.qualcomm.robotcore.hardware.DcMotor.RunMode mode) - Specified by:
getPIDCoefficientsin interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
getPIDFCoefficients
public com.qualcomm.robotcore.hardware.PIDFCoefficients getPIDFCoefficients(com.qualcomm.robotcore.hardware.DcMotor.RunMode mode) - Specified by:
getPIDFCoefficientsin interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
setTargetPositionTolerance
public void setTargetPositionTolerance(int tolerance) - Specified by:
setTargetPositionTolerancein interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
getTargetPositionTolerance
public int getTargetPositionTolerance()- Specified by:
getTargetPositionTolerancein interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
isOverCurrent
public boolean isOverCurrent()Unsupported Operation- Specified by:
isOverCurrentin interfacecom.qualcomm.robotcore.hardware.DcMotorEx
-
getMotorType
public com.qualcomm.robotcore.hardware.configuration.typecontainers.MotorConfigurationType getMotorType()- Specified by:
getMotorTypein interfacecom.qualcomm.robotcore.hardware.DcMotor
-
setMotorType
public void setMotorType(com.qualcomm.robotcore.hardware.configuration.typecontainers.MotorConfigurationType motorType) - Specified by:
setMotorTypein interfacecom.qualcomm.robotcore.hardware.DcMotor
-
getController
public com.qualcomm.robotcore.hardware.DcMotorController getController()Unsupported Operation- Specified by:
getControllerin interfacecom.qualcomm.robotcore.hardware.DcMotor
-
getPortNumber
public int getPortNumber()Should return -1, which is the SDK's default before it gets set- Specified by:
getPortNumberin interfacecom.qualcomm.robotcore.hardware.DcMotor
-
setZeroPowerBehavior
public void setZeroPowerBehavior(com.qualcomm.robotcore.hardware.DcMotor.ZeroPowerBehavior zeroPowerBehavior) - Specified by:
setZeroPowerBehaviorin interfacecom.qualcomm.robotcore.hardware.DcMotor
-
getZeroPowerBehavior
public com.qualcomm.robotcore.hardware.DcMotor.ZeroPowerBehavior getZeroPowerBehavior()- Specified by:
getZeroPowerBehaviorin 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.ZeroPowerBehaviorto FLOAT. This completely removes power from the motor.- Specified by:
setPowerFloatin 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.ZeroPowerBehavioris set to FLOAT.- Specified by:
getPowerFloatin interfacecom.qualcomm.robotcore.hardware.DcMotor
-
setTargetPosition
public void setTargetPosition(int position) - Specified by:
setTargetPositionin interfacecom.qualcomm.robotcore.hardware.DcMotor
-
getTargetPosition
public int getTargetPosition()- Specified by:
getTargetPositionin 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:
isBusyin interfacecom.qualcomm.robotcore.hardware.DcMotor
-
getCurrentPosition
public int getCurrentPosition()- Specified by:
getCurrentPositionin interfacecom.qualcomm.robotcore.hardware.DcMotor
-
setMode
public void setMode(com.qualcomm.robotcore.hardware.DcMotor.RunMode mode) - Specified by:
setModein interfacecom.qualcomm.robotcore.hardware.DcMotor
-
getMode
public com.qualcomm.robotcore.hardware.DcMotor.RunMode getMode()- Specified by:
getModein interfacecom.qualcomm.robotcore.hardware.DcMotor
-
setDirection
public void setDirection(com.qualcomm.robotcore.hardware.DcMotorSimple.Direction direction) - Specified by:
setDirectionin interfacecom.qualcomm.robotcore.hardware.DcMotorSimple
-
getDirection
public com.qualcomm.robotcore.hardware.DcMotorSimple.Direction getDirection()- Specified by:
getDirectionin interfacecom.qualcomm.robotcore.hardware.DcMotorSimple
-
setPower
public void setPower(double power) - Specified by:
setPowerin interfacecom.qualcomm.robotcore.hardware.DcMotorSimple
-
getPower
public double getPower()- Specified by:
getPowerin interfacecom.qualcomm.robotcore.hardware.DcMotorSimple
-
getManufacturer
public com.qualcomm.robotcore.hardware.HardwareDevice.Manufacturer getManufacturer()ReturnsHardwareDevice.Manufacturer.UNKNOWN- Specified by:
getManufacturerin interfacecom.qualcomm.robotcore.hardware.HardwareDevice
-
getDeviceName
Returns "Mockery 0 RPM motor"- Specified by:
getDeviceNamein interfacecom.qualcomm.robotcore.hardware.HardwareDevice
-
getConnectionInfo
Returns "This motor shares a connection with its friends."- Specified by:
getConnectionInfoin interfacecom.qualcomm.robotcore.hardware.HardwareDevice
-
getVersion
public int getVersion()Returns 51825- Specified by:
getVersionin interfacecom.qualcomm.robotcore.hardware.HardwareDevice
-
resetDeviceConfigurationForOpMode
public void resetDeviceConfigurationForOpMode()Sets theDcMotorSimple.Directionto FORWARD. (matches the original implementation)- Specified by:
resetDeviceConfigurationForOpModein interfacecom.qualcomm.robotcore.hardware.HardwareDevice
-
close
public void close()Calls setPowerFloat() (matches the original implementation)- Specified by:
closein 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)
-