Made mock package
This commit is contained in:
@@ -1,13 +1,16 @@
|
|||||||
package org.firstinspires.ftc.teamcode.subsystems.chute;
|
package org.firstinspires.ftc.teamcode.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mock continuous rotation servo for testing.
|
* Mock continuous rotation servo for testing.
|
||||||
* Mirrors the override pattern of {@link FtcCRServo} without requiring the FTC SDK.
|
* Mirrors the override pattern of {@link FtcCRServo} without requiring the FTC SDK.
|
||||||
*
|
*
|
||||||
* <p>Extends MockDCMotor and overrides {@code setPower()} to track commanded values,
|
* <p>Extends MockMotor and overrides {@code setPower()} to track commanded values,
|
||||||
* letting tests verify that ChuteController correctly routes through a subclassed motor.
|
* letting tests verify that ChuteController correctly routes through a subclassed motor.
|
||||||
|
*
|
||||||
|
* @see FtcCRServo
|
||||||
|
* @see MockDCMotor
|
||||||
*/
|
*/
|
||||||
public class MockCRServo extends MockDCMotor {
|
public class MockCRServo extends MockMotor {
|
||||||
private double lastCommandedPower = 0.0;
|
private double lastCommandedPower = 0.0;
|
||||||
private int setPowerCallCount = 0;
|
private int setPowerCallCount = 0;
|
||||||
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package org.firstinspires.ftc.teamcode.mock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock DC motor for testing.
|
||||||
|
* Provides type identity for DC motor-specific code paths while
|
||||||
|
* inheriting all simulation behavior from {@link MockMotor}.
|
||||||
|
*
|
||||||
|
* @see FtcDCMotor
|
||||||
|
* @see MockCRServo
|
||||||
|
*/
|
||||||
|
public class MockDCMotor extends MockMotor {
|
||||||
|
}
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
package org.firstinspires.ftc.teamcode.subsystems.chute;
|
package org.firstinspires.ftc.teamcode.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple mock motor.
|
* Simple mock motor.
|
||||||
*/
|
*/
|
||||||
public class MockDCMotor {
|
public class MockMotor {
|
||||||
private double power;
|
private double power;
|
||||||
private double position;
|
private double position;
|
||||||
private double speed = 1.0; // rad/s at full power
|
private double speed = 1.0; // rad/s at full power
|
||||||
|
|
||||||
public MockDCMotor() {
|
public MockMotor() {
|
||||||
this.power = 0.0;
|
this.power = 0.0;
|
||||||
this.position = 0.0;
|
this.position = 0.0;
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.firstinspires.ftc.teamcode.subsystems.chute;
|
package org.firstinspires.ftc.teamcode.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple mock potentiometer with configurable wraparound.
|
* Simple mock potentiometer with configurable wraparound.
|
||||||
@@ -11,7 +11,7 @@ import org.firstinspires.ftc.teamcode.subsystems.chute.FtcCRServo;
|
|||||||
import org.firstinspires.ftc.teamcode.subsystems.chute.FtcDCMotor;
|
import org.firstinspires.ftc.teamcode.subsystems.chute.FtcDCMotor;
|
||||||
import org.firstinspires.ftc.teamcode.subsystems.chute.FtcPotentiometer;
|
import org.firstinspires.ftc.teamcode.subsystems.chute.FtcPotentiometer;
|
||||||
import org.firstinspires.ftc.teamcode.subsystems.chute.ChuteController;
|
import org.firstinspires.ftc.teamcode.subsystems.chute.ChuteController;
|
||||||
import org.firstinspires.ftc.teamcode.subsystems.chute.MockDCMotor;
|
import org.firstinspires.ftc.teamcode.subsystems.chute.MockMotor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example OpMode demonstrating chute control with real hardware.
|
* Example OpMode demonstrating chute control with real hardware.
|
||||||
@@ -46,7 +46,7 @@ public class ChuteOpMode extends LinearOpMode {
|
|||||||
FtcPotentiometer pot = new FtcPotentiometer(chutePot, POT_WRAP_AMOUNT);
|
FtcPotentiometer pot = new FtcPotentiometer(chutePot, POT_WRAP_AMOUNT);
|
||||||
|
|
||||||
// Create motor adapter — either DcMotor or CRServo
|
// Create motor adapter — either DcMotor or CRServo
|
||||||
MockDCMotor motor;
|
MockMotor motor;
|
||||||
if (USE_SERVO) {
|
if (USE_SERVO) {
|
||||||
CRServo chuteServo = hardwareMap.get(CRServo.class, "chute_servo");
|
CRServo chuteServo = hardwareMap.get(CRServo.class, "chute_servo");
|
||||||
motor = new FtcCRServo(chuteServo);
|
motor = new FtcCRServo(chuteServo);
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
package org.firstinspires.ftc.teamcode.subsystems.chute;
|
package org.firstinspires.ftc.teamcode.subsystems.chute;
|
||||||
|
|
||||||
|
import org.firstinspires.ftc.teamcode.mock.MockMotor;
|
||||||
|
import org.firstinspires.ftc.teamcode.mock.MockDCMotor;
|
||||||
|
import org.firstinspires.ftc.teamcode.mock.MockPotentiometer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main entry point for chute control system.
|
* Main entry point for chute control system.
|
||||||
*
|
*
|
||||||
@@ -28,7 +32,7 @@ package org.firstinspires.ftc.teamcode.subsystems.chute;
|
|||||||
* ChuteController controller = new ChuteController(motor, pot, 4 * Math.PI);
|
* ChuteController controller = new ChuteController(motor, pot, 4 * Math.PI);
|
||||||
* Chute chute = new Chute(controller, motor, pot);
|
* Chute chute = new Chute(controller, motor, pot);
|
||||||
*
|
*
|
||||||
* // With a CRServo:
|
* // With a CRServo (drop-in replacement):
|
||||||
* FtcCRServo motor = new FtcCRServo(hardwareMap.get(CRServo.class, "chute_servo"));
|
* FtcCRServo motor = new FtcCRServo(hardwareMap.get(CRServo.class, "chute_servo"));
|
||||||
* FtcPotentiometer pot = new FtcPotentiometer(hardwareMap.get(AnalogInput.class, "chute_pot"));
|
* FtcPotentiometer pot = new FtcPotentiometer(hardwareMap.get(AnalogInput.class, "chute_pot"));
|
||||||
* ChuteController controller = new ChuteController(motor, pot, 4 * Math.PI);
|
* ChuteController controller = new ChuteController(motor, pot, 4 * Math.PI);
|
||||||
@@ -45,13 +49,14 @@ package org.firstinspires.ftc.teamcode.subsystems.chute;
|
|||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @see ChuteController
|
* @see ChuteController
|
||||||
|
* @see FtcDCMotor
|
||||||
* @see FtcCRServo
|
* @see FtcCRServo
|
||||||
* @see MockPotentiometer
|
* @see MockPotentiometer
|
||||||
* @see FtcPotentiometer
|
* @see FtcPotentiometer
|
||||||
*/
|
*/
|
||||||
public class Chute {
|
public class Chute {
|
||||||
private final ChuteController controller;
|
private final ChuteController controller;
|
||||||
private final MockDCMotor motor;
|
private final MockMotor motor;
|
||||||
private final MockPotentiometer pot;
|
private final MockPotentiometer pot;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,12 +87,13 @@ public class Chute {
|
|||||||
* Use this constructor in actual FTC OpModes with hardware from hardwareMap.
|
* Use this constructor in actual FTC OpModes with hardware from hardwareMap.
|
||||||
*
|
*
|
||||||
* @param controller Pre-configured controller with real hardware
|
* @param controller Pre-configured controller with real hardware
|
||||||
* @param motor FtcDCMotor adapter wrapping DcMotor
|
* @param motor Motor adapter (FtcDCMotor or FtcCRServo)
|
||||||
* @param pot FtcPotentiometer adapter wrapping AnalogInput
|
* @param pot FtcPotentiometer adapter wrapping AnalogInput
|
||||||
* @see FtcDCMotor
|
* @see FtcDCMotor
|
||||||
|
* @see FtcCRServo
|
||||||
* @see FtcPotentiometer
|
* @see FtcPotentiometer
|
||||||
*/
|
*/
|
||||||
public Chute(ChuteController controller, MockDCMotor motor, MockPotentiometer pot) {
|
public Chute(ChuteController controller, MockMotor motor, MockPotentiometer pot) {
|
||||||
this.controller = controller;
|
this.controller = controller;
|
||||||
this.motor = motor;
|
this.motor = motor;
|
||||||
this.pot = pot;
|
this.pot = pot;
|
||||||
@@ -168,9 +174,9 @@ public class Chute {
|
|||||||
/**
|
/**
|
||||||
* Gets motor instance for testing.
|
* Gets motor instance for testing.
|
||||||
*
|
*
|
||||||
* @return MockDCMotor instance used by this chute
|
* @return MockMotor instance used by this chute
|
||||||
*/
|
*/
|
||||||
public MockDCMotor getMotor() { return motor; }
|
public MockMotor getMotor() { return motor; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets potentiometer instance for testing.
|
* Gets potentiometer instance for testing.
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package org.firstinspires.ftc.teamcode.subsystems.chute;
|
package org.firstinspires.ftc.teamcode.subsystems.chute;
|
||||||
|
|
||||||
|
import org.firstinspires.ftc.teamcode.mock.MockMotor;
|
||||||
|
import org.firstinspires.ftc.teamcode.mock.MockPotentiometer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple chute controller with homing and position control.
|
* Simple chute controller with homing and position control.
|
||||||
*/
|
*/
|
||||||
public class ChuteController {
|
public class ChuteController {
|
||||||
private final MockDCMotor motor;
|
private final MockMotor motor;
|
||||||
private final MockPotentiometer pot;
|
private final MockPotentiometer pot;
|
||||||
private final double maxExtension;
|
private final double maxExtension;
|
||||||
private final double wrapAmount;
|
private final double wrapAmount;
|
||||||
@@ -29,7 +32,7 @@ public class ChuteController {
|
|||||||
* @param pot Potentiometer that measures position
|
* @param pot Potentiometer that measures position
|
||||||
* @param maxExtension Maximum extension from home in radians
|
* @param maxExtension Maximum extension from home in radians
|
||||||
*/
|
*/
|
||||||
public ChuteController(MockDCMotor motor, MockPotentiometer pot, double maxExtension) {
|
public ChuteController(MockMotor motor, MockPotentiometer pot, double maxExtension) {
|
||||||
this.motor = motor;
|
this.motor = motor;
|
||||||
this.pot = pot;
|
this.pot = pot;
|
||||||
this.maxExtension = maxExtension;
|
this.maxExtension = maxExtension;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package org.firstinspires.ftc.teamcode.subsystems.chute;
|
|||||||
import com.qualcomm.robotcore.hardware.CRServo;
|
import com.qualcomm.robotcore.hardware.CRServo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapter that wraps a real FTC CRServo and makes it look like a MockDCMotor.
|
* Adapter that wraps a real FTC CRServo and makes it look like a MockCRServo.
|
||||||
* Drop-in replacement for FtcDCMotor when the chute is driven by a continuous
|
* Drop-in replacement for FtcDCMotor when the chute is driven by a continuous
|
||||||
* rotation servo instead of a DC motor.
|
* rotation servo instead of a DC motor.
|
||||||
*
|
*
|
||||||
@@ -19,7 +19,7 @@ import com.qualcomm.robotcore.hardware.CRServo;
|
|||||||
*
|
*
|
||||||
* @see FtcDCMotor
|
* @see FtcDCMotor
|
||||||
*/
|
*/
|
||||||
public class FtcCRServo extends MockDCMotor {
|
public class FtcCRServo extends MockCRServo {
|
||||||
private final CRServo servo;
|
private final CRServo servo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import com.qualcomm.robotcore.hardware.DcMotor;
|
|||||||
/**
|
/**
|
||||||
* Adapter that wraps a real FTC DcMotor and makes it look like a MockDCMotor.
|
* Adapter that wraps a real FTC DcMotor and makes it look like a MockDCMotor.
|
||||||
* Use this to connect the chute controller to actual hardware.
|
* Use this to connect the chute controller to actual hardware.
|
||||||
|
*
|
||||||
|
* @see FtcCRServo
|
||||||
*/
|
*/
|
||||||
public class FtcDCMotor extends MockDCMotor {
|
public class FtcDCMotor extends MockDCMotor {
|
||||||
private final DcMotor motor;
|
private final DcMotor motor;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package org.firstinspires.ftc.teamcode.subsystems.chute;
|
package org.firstinspires.ftc.teamcode.subsystems.chute;
|
||||||
|
|
||||||
|
import org.firstinspires.ftc.teamcode.mock.MockCRServo;
|
||||||
|
import org.firstinspires.ftc.teamcode.mock.MockPotentiometer;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user