NextMotor
Comprehensive wrapper around a DcMotorImplEx supporting multiple control modes.
NextMotor provides a high-level interface for DC motor control including:
Throttle control: Direct power/PWM percentage.
Voltage control: Set power as a voltage relative to the input rail voltage.
Position control: PID-based regulation to reach and hold a target encoder position.
Velocity control: PID + feedforward to reach and hold a target velocity.
The motor wraps a DcMotorImplEx obtained lazily through an initializer, supporting construction from a Lynx module/port, hardware map name, or a raw initializer function.
Encoder readings are automatically converted to Angle and AngularVelocity using the configured anglePerCount conversion factor.
Example:
val motor = NextMotor("driveMotor", anglePerCount = 0.05.radians)
motor.setVelocitySetpoint(12.0.radiansPerSecond)Parameters
A function that returns the backing DcMotorImplEx. Invoked lazily.
Conversion factor from encoder counts to angle. Defaults to 1.0 radian.
Power caching tolerance to reduce redundant hardware writes. Defaults to 0.01.
Constructors
Constructs a motor from a Lynx hub module and port number.
Constructs a motor by name from the current hardware map.
Types
Properties
Optional external absolute encoder via analog feedback.
Current absolute encoder position.
Current active control mode (THROTTLE, VOLTAGE, POSITION, or VELOCITY).
Motor rotation direction (FORWARD or REVERSE).
Current encoder position in physical angle units.
Current encoder velocity in physical angle per time units.
Position control constants (PID and feedforward gains).
PID controller used for position setpoint tracking.
Velocity control constants (PID and feedforward gains).
Feedforward calculator used in conjunction with velocity PID.
PID controller used for velocity setpoint tracking.
Motor zero power behavior (FLOAT or BRAKE).
Functions
Configures this motor to follow another motor's behavior and align its rotation direction.
Set absolute position control mode and position setpoint.
Set position control mode and position setpoint.
Set velocity control mode and velocity setpoint.