88
99package dev.nextftc.hardware.actuators
1010
11- import com.qualcomm.robotcore.hardware.AnalogInput
1211import com.qualcomm.robotcore.hardware.CRServoImplEx
1312import com.qualcomm.robotcore.hardware.configuration.typecontainers.ServoConfigurationType
1413import dev.nextftc.hardware.RobotController
@@ -29,45 +28,48 @@ import dev.nextftc.units.radians
2928 *
3029 * @param initializer A function returning the backing [CRServoImplEx]. It will
3130 * be invoked lazily the first time the servo is accessed.
32- * @param feedbackName Hardware map name of the analog input.
31+ * @param feedbackInitializer A function returning the backing [AnalogFeedback]
32+ * used to read the feedback angle. Accepts any [AnalogFeedback] implementation.
3333 * @param cacheTolerance Tolerance for the [NextCRServo] power caching delegate.
3434 */
3535class NextFeedbackCRServo @JvmOverloads constructor(
3636 initializer : () -> CRServoImplEx ,
37- feedbackName : String ,
37+ feedbackInitializer : () -> AnalogFeedback ,
3838 cacheTolerance : Double = 0.01 ,
3939) : NextCRServo(initializer, cacheTolerance) {
4040
4141 /* *
42- * Constructor to create a NextFeedbackCRServo using a servo name.
42+ * Constructor to create a NextFeedbackCRServo using a servo name and an
43+ * already-constructed [AnalogFeedback] instance for the feedback input.
4344 *
4445 * @param servoName Hardware map name of the servo.
45- * @param feedbackName Hardware map name of the analog input .
46+ * @param feedback An already-constructed [AnalogFeedback] instance to read the angle from .
4647 * @param cacheTolerance Tolerance for the [NextCRServo] power caching delegate.
4748 */
4849 @JvmOverloads constructor (
4950 servoName: String ,
50- feedbackName : String ,
51+ feedback : AnalogFeedback ,
5152 cacheTolerance: Double = 0.01 ,
5253 ) : this (
5354 { RobotController .hardwareMap[servoName] as CRServoImplEx },
54- feedbackName ,
55+ { feedback } ,
5556 cacheTolerance,
5657 )
5758
5859 /* *
59- * Constructor to create a NextFeedbackCRServo using a LynxModule and port number.
60+ * Constructor to create a NextFeedbackCRServo using a LynxModule and port number for
61+ * the servo, and an already-constructed [AnalogFeedback] instance for the feedback input.
6062 *
6163 * @param module The Lynx module, see [RobotController.controlHub], [RobotController.expansionHub],
6264 * and [RobotController.servoHubs].
6365 * @param port The servo port (in the range [0, 5]).
64- * @param feedbackName Hardware map name of the analog input .
66+ * @param feedback An already-constructed [AnalogFeedback] instance to read the angle from .
6567 * @param cacheTolerance Tolerance for the [NextCRServo] power caching delegate.
6668 */
6769 @JvmOverloads constructor (
6870 module: NextLynxModule ,
6971 port: Int ,
70- feedbackName : String ,
72+ feedback : AnalogFeedback ,
7173 cacheTolerance: Double = 0.01 ,
7274 ) : this (
7375 {
@@ -77,14 +79,12 @@ class NextFeedbackCRServo @JvmOverloads constructor(
7779 ServoConfigurationType .getStandardServoType(),
7880 )
7981 },
80- feedbackName ,
82+ { feedback } ,
8183 cacheTolerance,
8284 )
8385
84- private val analogInput by LazyHardware {
85- RobotController .hardwareMap[feedbackName] as AnalogInput
86- }
87- private val rawAngleRadians: Double by AnalogFeedback { analogInput.voltage }
86+ private val analogInput by LazyHardware (feedbackInitializer)
87+ private val rawAngleRadians: Double by analogInput
8888
8989 /* *
9090 * Actual angle of the servo, reported from the analog feedback input.
0 commit comments