88
99package dev.nextftc.hardware.actuators
1010
11- import com.qualcomm.robotcore.hardware.AnalogInput
1211import com.qualcomm.robotcore.hardware.ServoImplEx
1312import com.qualcomm.robotcore.hardware.configuration.typecontainers.ServoConfigurationType
1413import dev.nextftc.hardware.RobotController
@@ -29,64 +28,65 @@ import dev.nextftc.units.radians
2928 * Example:
3029 *
3130 * ```
32- * val arm = NextFeedbackServo("armServo", "armEncoder" )
31+ * val arm = NextFeedbackServo("armServo", myAnalogFeedback )
3332 * arm.position = 0.5
3433 * val angle = arm.angle
3534 * ```
3635 *
3736 * @param initializer A function returning the backing [ServoImplEx]. It will be
3837 * invoked lazily the first time the servo is accessed.
39- * @param feedbackName Hardware map name of the analog input.
38+ * @param feedbackInitializer A function returning the backing [AnalogFeedback]
39+ * used to read the feedback angle. Accepts any [AnalogFeedback] implementation.
4040 * @param cacheTolerance Tolerance for the [NextServo] position caching delegate.
4141 */
4242class NextFeedbackServo @JvmOverloads constructor(
4343 initializer : () -> ServoImplEx ,
44- feedbackName : String ,
44+ feedbackInitializer : () -> AnalogFeedback ,
4545 cacheTolerance : Double = 0.01 ,
4646) : NextServo(initializer, cacheTolerance) {
4747
4848 /* *
49- * Constructor to create a NextFeedbackServo using a servo name.
49+ * Constructor to create a NextFeedbackServo using a servo name and an
50+ * already-constructed [AnalogFeedback] instance for the feedback input.
5051 *
5152 * @param servoName Hardware map name of the servo.
52- * @param feedbackName Hardware map name of the analog input .
53+ * @param feedback An already-constructed [AnalogFeedback] instance to read the angle from .
5354 * @param cacheTolerance Tolerance for the [NextServo] position caching delegate.
5455 */
5556 @JvmOverloads constructor (
5657 servoName: String ,
57- feedbackName : String ,
58+ feedback : AnalogFeedback ,
5859 cacheTolerance: Double = 0.01 ,
5960 ) : this (
6061 { RobotController .hardwareMap[servoName] as ServoImplEx },
61- feedbackName ,
62+ { feedback } ,
6263 cacheTolerance,
6364 )
6465
6566 /* *
66- * Constructor to create a NextFeedbackServo using a LynxModule and port number.
67+ * Constructor to create a NextFeedbackServo using a LynxModule and port number for
68+ * the servo, and an already-constructed [AnalogFeedback] instance for the feedback input.
6769 *
6870 * @param module The Lynx module, see [RobotController.controlHub], [RobotController.expansionHub],
6971 * and [RobotController.servoHubs].
7072 * @param port The servo port (in the range [0, 5]).
71- * @param feedbackName Hardware map name of the analog input .
73+ * @param feedback An already-constructed [AnalogFeedback] instance to read the angle from .
7274 * @param cacheTolerance Tolerance for the [NextServo] position caching delegate.
7375 */
7476 @JvmOverloads constructor (
7577 module: NextLynxModule ,
7678 port: Int ,
77- feedbackName : String ,
79+ feedback : AnalogFeedback ,
7880 cacheTolerance: Double = 0.01 ,
7981 ) : this (
8082 { ServoImplEx (module.servoController, port, ServoConfigurationType .getStandardServoType()) },
81- feedbackName ,
83+ { feedback } ,
8284 cacheTolerance,
8385 )
8486
85- private val analogInput by LazyHardware {
86- RobotController .hardwareMap[feedbackName] as AnalogInput
87- }
87+ private val analogInput by LazyHardware (feedbackInitializer)
8888
89- private val rawAngleRadians: Double by AnalogFeedback { analogInput.voltage }
89+ private val rawAngleRadians: Double by analogInput
9090
9191 /* *
9292 * Actual angle of the servo, reported from the analog feedback input.
0 commit comments