Class MotorSetup
java.lang.Object
com.crossbotics.ftchelper.hardware.MotorSetup
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 Summary
Modifier and TypeMethodDescriptionbrake()At power 0 the motor resists turning (holds still).coast()At power 0 the motor spins freely.com.qualcomm.robotcore.hardware.DcMotorExdone()Sets power to 0 and gives you the motor.forward()Positive power turns the motor the normal way (this is the default).static MotorSetupStarts the setup for a motor in the configuration.static MotorSetupof(com.qualcomm.robotcore.hardware.DcMotorEx motor) Starts the setup for a motor you already have.Sets the encoder count to 0 here.reversed()Positive power turns the motor the other way.reversed(boolean reversed) Sets the direction from a true/false setting.Power sets the speed, and the hub uses the encoder to hold that speed.Power goes straight to the motor.
-
Method Details
-
get
Starts the setup for a motor in the configuration.- Parameters:
hardwareMap- the OpMode'shardwareMapname- 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
Starts the setup for a motor you already have.- Parameters:
motor- the motor to set up- Returns:
- the start of the chain
-
forward
Positive power turns the motor the normal way (this is the default). -
reversed
Positive power turns the motor the other way. Use when a motor is mounted mirrored. -
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
At power 0 the motor resists turning (holds still). Good for drive wheels and lifts. -
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
Sets the encoder count to 0 here. Call this BEFORE a run mode (runUsingEncoder()orrunWithoutEncoder()), 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
Power sets the speed, and the hub uses the encoder to hold that speed. Needs an encoder cable. -
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
-