Class PretendMotor

java.lang.Object
com.crossbotics.ftchelper.testkit.PretendMotor

public class PretendMotor extends Object
A pretend motor for JUnit tests on a laptop (no robot): it remembers the power it was sent, and its encoder is a number your test sets. Get one from PretendDevices.motor(String).

 PretendMotor lift = devices.motor("lift");
 lift.position = 900;                 // the encoder now reads 900
 robot.all().update();
 assertEquals(0, lift.power, 0.01);   // at its target: no power
 

The fields are public on purpose: a test reads and sets them directly. Docs: docs/modules/testkit.md, docs/tests/03-checks-before-practice-and-matches.md

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    double
    What getCurrent(...) gives, amps.
    com.qualcomm.robotcore.hardware.DcMotorSimple.Direction
    FORWARD or REVERSE, as set (.reversed() sets REVERSE).
    boolean
    True: setPower throws, like an unplugged motor.
    double
    The largest power (either way) ever sent.
    com.qualcomm.robotcore.hardware.DcMotor.RunMode
    The run mode set (STOP_AND_RESET_ENCODER also sets position to 0).
    final com.qualcomm.robotcore.hardware.DcMotorEx
    The SDK motor to hand to code that wants one.
    double[]
    The last setVelocityPIDFCoefficients gains {p, i, d, f}, or null.
    double
    The encoder count your test sets; getCurrentPosition() gives it rounded.
    int
    How many times the encoder was read.
    double
    The last power sent (-1 to 1).
    int
    How many times a power was sent (each is a trip to the hub on a robot).
    double
    Ticks per second, what getVelocity() gives.
    double
    The last setVelocity(...) (ticks per second).
    com.qualcomm.robotcore.hardware.DcMotor.ZeroPowerBehavior
    BRAKE or FLOAT, as set.
  • Constructor Summary

    Constructors
    Constructor
    Description
    A new pretend motor at power 0 and position 0.
  • Method Summary

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • power

      public double power
      The last power sent (-1 to 1).
    • position

      public double position
      The encoder count your test sets; getCurrentPosition() gives it rounded.
    • velocity

      public double velocity
      Ticks per second, what getVelocity() gives.
    • velocityCommand

      public double velocityCommand
      The last setVelocity(...) (ticks per second).
    • currentAmps

      public double currentAmps
      What getCurrent(...) gives, amps.
    • powerWrites

      public int powerWrites
      How many times a power was sent (each is a trip to the hub on a robot).
    • positionReads

      public int positionReads
      How many times the encoder was read.
    • maxAbsPower

      public double maxAbsPower
      The largest power (either way) ever sent.
    • pidf

      public double[] pidf
      The last setVelocityPIDFCoefficients gains {p, i, d, f}, or null.
    • failSetPower

      public boolean failSetPower
      True: setPower throws, like an unplugged motor.
    • mode

      public com.qualcomm.robotcore.hardware.DcMotor.RunMode mode
      The run mode set (STOP_AND_RESET_ENCODER also sets position to 0).
    • zeroPower

      public com.qualcomm.robotcore.hardware.DcMotor.ZeroPowerBehavior zeroPower
      BRAKE or FLOAT, as set.
    • direction

      public com.qualcomm.robotcore.hardware.DcMotorSimple.Direction direction
      FORWARD or REVERSE, as set (.reversed() sets REVERSE).
    • motor

      public final com.qualcomm.robotcore.hardware.DcMotorEx motor
      The SDK motor to hand to code that wants one.
  • Constructor Details

    • PretendMotor

      public PretendMotor()
      A new pretend motor at power 0 and position 0.