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 Distance and LinearVelocity using the configured distancePerCount conversion factor.
Example:
val motor = NextMotor("driveMotor", distancePerCount = 0.05.inches)
motor.setVelocitySetpoint(12.0.inchesPerSecond)Parameters
A function that returns the backing DcMotorImplEx. Invoked lazily.
Conversion factor from encoder counts to distance. Defaults to 1.0 inch.
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
Current active control mode (THROTTLE, VOLTAGE, POSITION, or VELOCITY).
Motor rotation direction (FORWARD or REVERSE).
Current encoder position in physical distance units.
Current encoder velocity in physical distance 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.