Class MotorSetup

java.lang.Object
com.crossbotics.ftchelper.hardware.MotorSetup

public final class MotorSetup extends Object
Sets up a motor in one readable chain.

 DcMotorEx lift = MotorSetup.get(hardwareMap, "lift")
         .reversed()
         .brake()
         .resetEncoder()
         .runUsingEncoder()
         .done();
 

done() always sets the power to 0, so the motor never moves during INIT. Settings are sent to the motor at once, in the order you write them.

How the chain works: every step (except done()) does its setting and then hands back the same MotorSetup (return this), so you can put the next .step() right after it. Tutorial 02 (docs/tutorials/02-motors-and-servos.md) walks through motor setup. Docs: docs/modules/hardware.md

  • Method Details

    • get

      public static MotorSetup get(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, String name)
      Starts the setup for a motor in the configuration.
      Parameters:
      hardwareMap - the OpMode's hardwareMap
      name - the motor's configuration name
      Returns:
      the start of the chain
      Throws:
      IllegalArgumentException - with the list of real motor names if the name is wrong
    • of

      public static MotorSetup of(com.qualcomm.robotcore.hardware.DcMotorEx motor)
      Starts the setup for a motor you already have.
      Parameters:
      motor - the motor to set up
      Returns:
      the start of the chain
    • forward

      public MotorSetup forward()
      Positive power turns the motor the normal way (this is the default).
    • reversed

      public MotorSetup reversed()
      Positive power turns the motor the other way. Use when a motor is mounted mirrored.
    • reversed

      public MotorSetup reversed(boolean reversed)
      Sets the direction from a true/false setting. true = reversed. Handy when the direction is a number in your settings file, not written in the code.
      Parameters:
      reversed - true to reverse the motor, false for the normal direction
    • brake

      public MotorSetup brake()
      At power 0 the motor resists turning (holds still). Good for drive wheels and lifts.
    • coast

      public MotorSetup coast()
      At power 0 the motor spins freely. Good for flywheels: a heavy spinning wheel that is braked hard can strain the motor and gears, so it is better to let it slow down by itself.
    • resetEncoder

      public MotorSetup resetEncoder()
      Sets the encoder count to 0 here. Call this BEFORE a run mode (runUsingEncoder() or runWithoutEncoder()), because a reset stops the motor until a new mode is set.

      An encoder counts how far the motor has turned, in "ticks" (small steps). After the reset, the position the motor is in right now counts as 0 ticks.

    • runUsingEncoder

      public MotorSetup runUsingEncoder()
      Power sets the speed, and the hub uses the encoder to hold that speed. Needs an encoder cable.
    • runWithoutEncoder

      public MotorSetup runWithoutEncoder()
      Power goes straight to the motor. The encoder can still be read.
    • done

      public com.qualcomm.robotcore.hardware.DcMotorEx done()
      Sets power to 0 and gives you the motor. Always end the chain with this.
      Returns:
      the motor, set up and stopped