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.
Creating a feedback servo
Section titled “Creating a feedback servo”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 nameval armServo = NextFeedbackServo("armServo", NextAnalogInput("armEncoder"))
// By Lynx Module and portval armServo = NextFeedbackServo(RobotController.expansionHub, 0, NextAnalogInput(RobotController.expansionHub, 0))// By configuration nameNextFeedbackServo armServo = new NextFeedbackServo("armServo", new NextAnalogInput("armEncoder"));
// By Lynx Module and portNextFeedbackServo armServo = new NextFeedbackServo(RobotController.getExpansionHub(), 0, new NextAnalogInput(RobotController.getExpansionHub(), 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)AnalogInput myAnalogInput = hardwareMap.get(AnalogInput.class, "armEncoder");
AnalogFeedback customFeedback = new AnalogFeedback(3.3.volts, () -> myAnalogInput.getVoltage());
NextFeedbackServo armServo = new NextFeedbackServo("armServo", customFeedback);The servo’s actual physical angle, read from the analog feedback input and returned as a typed Angle.
val currentAngle = armServo.angleAngle currentAngle = armServo.getAngle();
