Skip to content

Feedback Servos

NextFeedbackServo and NextFeedbackCRServo pair a NextServo or NextCRServo with an analog feedback input, for servos with a feedback wire (e.g. Axon). They inherit everything from their base class and add angle for reading the servo’s actual physical angle.

Both classes pair the constructors you already know from NextServo and NextCRServo with an already-constructed AnalogFeedback instance for reading the angle. NextAnalogInput is the built-in implementation of AnalogFeedback, and is what you’ll use in most cases. All of these below are interchangeable with NextFeedbackCRServo.

// By configuration name
val armServo = NextFeedbackServo("armServo", NextAnalogInput("armEncoder"))
// By Lynx Module and port
val armServo = NextFeedbackServo(RobotController.expansionHub, 0, NextAnalogInput(RobotController.expansionHub, 0))

feedback accepts any AnalogFeedback implementation, so you can also write your own if NextAnalogInput doesn’t fit what you want. AnalogFeedback just needs a maxVoltage and a Supplier<Double> that returns the raw voltage from wherever you’re reading it

val myAnalogInput = hardwareMap.get(AnalogInput::class.java, "armEncoder")
val customFeedback = AnalogFeedback(maxVoltage = 3.3.volts) { myAnalogInput.voltage }
val armServo = NextFeedbackServo("armServo", customFeedback)

The servo’s actual physical angle, read from the analog feedback input and returned as a typed Angle.

val currentAngle = armServo.angle