Motors
NextMotor is a lightweight wrapper around the standard FTC motor (DcMotor or DcMotorEx) that provides standard easy-to-use interface for throttling, voltage control, PIDS, and more
Creating a NextMotor
Section titled “Creating a NextMotor”There are two main ways to construct a NextMotor, depending on what you desire.
// By Lynx Module and port, recommendedval intakeMotor = NextMotor(RobotController.controlHub, 0)
// Using a configuration nameval intakeMotor = NextMotor("intakeMotor")// By Lynx Module and port, recommendedNextMotor intakeMotor = new NextMotor(RobotController.controlHub(), 0);
// Using a configuration nameNextMotor intakeMotor = new NextMotor("intakeMotor");All constructors accept two optional parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
anglePerCount |
Angle |
1.0 rad | The angle that a motor’s shaft rotates by for every ‘tick’ or ‘count’, used to convert ‘ticks’ into the number of rotations the motor has spun. |
cacheTolerance |
Double |
0.01 |
Minimum change in throttle required before a new value is written to the motor. |
Throttle Control
Section titled “Throttle Control”Throttle Control allows the motor to be throttled from -1.0 (reverse) to 1.0 (full power). The value represents a fraction of the robot’s total voltage.
// Adjust 1.0 to be what value you would like it to bemyMotor.throttle = 1.0// Adjust 1.0 to be what value you would like it to bemyMotor.setThrottle(1.0)Voltage Control
Section titled “Voltage Control”Voltage Control allows the motor’s power to be controlled more accurately and set to a specific voltage.
// This function takes in a 'Voltage'myMotor.voltage = 12.0.volts// This function takes in a 'Voltage'myMotor.setVoltage(Volts.of(12))Positional Control
Section titled “Positional Control”Positional control allows the motor’s position to be controlled using a PID Controller
You can change the default positional PID constants by doing:
myMotor.positionConstants.apply { kP = 0.1}// Like kP, other positional PID constants include:// kP, kI, kD, kS, kV, kA, kG, kCos, kCosRatiomyMotor.getPositionConstants() .withP(0.1)// Like kP, other positional PID constants include:// kP, kI, kD, kS, kV, kA, kG, kCos, kCosRatioRelative Positional Control
Section titled “Relative Positional Control”This moves the motor to the designated position relative to the position of the motor during the robot’s startup.
// Increase the target to be your desired angle from the initial positionmyMotor.setPositionSetpoint(90.degrees)// Increase the target to be your desired angle from the initial positionmyMotor.setPositionSetpoint(Degrees.of(90))Absolute Positional Control
Section titled “Absolute Positional Control”This makes the motor take the shortest path, regardless of rotations to an angle in the range [-180, 180] degrees.
// Increase the target to be your desired anglemyMotor.setAbsolutePositionSetpoint(90.degrees)// Increase the target to be your desired anglemyMotor.setAbsolutePositionSetpoint(Degrees.of(90))Velocity Control
Section titled “Velocity Control”Similar to Positional Control velocity control allows the motor’s velocity to be controlled using a PID Controller
// Increase the target to be your desired angular velocitymyMotor.setVelocitySetpoint(30.degreesPerSecond)// Increase the target to be your desired angular velocitymyMotor.setVelocitySetpoint(DegreesPerSecond.of(30))You can change the default velocity PID constants by doing:
myMotor.velocityConstants.apply { kP = 0.1}// Like kP, other velocity PID constants include:// kP, kI, kD, kS, kV, kAmyMotor.getVelocityConstants() .withP(0.1)// Like kP, other velocity PID constants include:// kP, kI, kD, kS, kV, kAFollowing other motors
Section titled “Following other motors”NextMotor’s have a helpful feature that allows one motor to ‘follow’ or mimic another motor.
You can use this feature by doing:
myFollowerMotor.follow(myLeaderMotor)
// Optional direction to specify whether it should follow in the same// or opposite direction.myFollowerMotor.follow(myLeaderMotor, Direction.REVERSE)myFollowerMotor.follow(myLeaderMotor)
// Optional direction to specify whether it should follow in the same// or opposite direction.myFollowerMotor.follow(myLeaderMotor, Direction.REVERSE)Direction
Section titled “Direction”You can set the Direction property of NextMotor’s to control the direction that the motor rotates in.
| Direction Type | Description |
|---|---|
| Direction.FORWARD | The motor moves forward (Clockwise) |
| Direction.REVERSE | The motor spins in the opposite direction (Counter-Clockwise) |
ZeroPowerBehaviour
Section titled “ZeroPowerBehaviour”The ZeroPowerBehaviour property allows you to control how the motor reacts when it is given a throttle of 0
| ZeroPowerBehaviour Type | Description |
|---|---|
| ZeroPowerBehaviour.BRAKE | Actively stops the motor when given a power of 0 |
| ZeroPowerBehaviour.FLOAT | Allows the motor to naturally spin and eventually stop by itself |

