Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 169 additions & 0 deletions .idea/caches/deviceStreaming.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,21 @@ open class NextCRServo @JvmOverloads constructor(
* @param port The servo port (in the range [0, 5]).
* @param cacheTolerance Tolerance used by the [Caching] delegate for power updates; defaults to 0.01.
*/
@JvmOverloads constructor(module: NextLynxModule, port: Int, cacheTolerance: Double = 0.01) : this(
@JvmOverloads constructor(
module: NextLynxModule,
port: Int,
cacheTolerance: Double = 0.01,
) : this(
{ CRServoImplEx(module.servoController, port, ServoConfigurationType.getStandardServoType()) },
cacheTolerance,
)
) {
require(port in 0..3) { "Expected port in range [0, 3], got $port" }
}

@JvmOverloads constructor(name: String, cacheTolerance: Double = 0.01) : this(
@JvmOverloads constructor(
name: String,
cacheTolerance: Double = 0.01,
) : this(
{ RobotController.hardwareMap[name] as CRServoImplEx },
cacheTolerance,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

package dev.nextftc.hardware.actuators

import com.qualcomm.robotcore.hardware.AnalogInput
import com.qualcomm.robotcore.hardware.CRServoImplEx
import com.qualcomm.robotcore.hardware.configuration.typecontainers.ServoConfigurationType
import dev.nextftc.hardware.RobotController
Expand All @@ -29,45 +28,48 @@ import dev.nextftc.units.radians
*
* @param initializer A function returning the backing [CRServoImplEx]. It will
* be invoked lazily the first time the servo is accessed.
* @param feedbackName Hardware map name of the analog input.
* @param feedbackInitializer A function returning the backing [AnalogFeedback]
* used to read the feedback angle. Accepts any [AnalogFeedback] implementation.
* @param cacheTolerance Tolerance for the [NextCRServo] power caching delegate.
*/
class NextFeedbackCRServo @JvmOverloads constructor(
initializer: () -> CRServoImplEx,
feedbackName: String,
feedbackInitializer: () -> AnalogFeedback,
cacheTolerance: Double = 0.01,
) : NextCRServo(initializer, cacheTolerance) {

/**
* Constructor to create a NextFeedbackCRServo using a servo name.
* Constructor to create a NextFeedbackCRServo using a servo name and an
* already-constructed [AnalogFeedback] instance for the feedback input.
*
* @param servoName Hardware map name of the servo.
* @param feedbackName Hardware map name of the analog input.
* @param feedback An already-constructed [AnalogFeedback] instance to read the angle from.
* @param cacheTolerance Tolerance for the [NextCRServo] power caching delegate.
*/
@JvmOverloads constructor(
servoName: String,
feedbackName: String,
feedback: AnalogFeedback,
cacheTolerance: Double = 0.01,
) : this(
{ RobotController.hardwareMap[servoName] as CRServoImplEx },
feedbackName,
{ feedback },
cacheTolerance,
)

/**
* Constructor to create a NextFeedbackCRServo using a LynxModule and port number.
* Constructor to create a NextFeedbackCRServo using a LynxModule and port number for
* the servo, and an already-constructed [AnalogFeedback] instance for the feedback input.
*
* @param module The Lynx module, see [RobotController.controlHub], [RobotController.expansionHub],
* and [RobotController.servoHubs].
* @param port The servo port (in the range [0, 5]).
* @param feedbackName Hardware map name of the analog input.
* @param feedback An already-constructed [AnalogFeedback] instance to read the angle from.
* @param cacheTolerance Tolerance for the [NextCRServo] power caching delegate.
*/
@JvmOverloads constructor(
module: NextLynxModule,
port: Int,
feedbackName: String,
feedback: AnalogFeedback,
cacheTolerance: Double = 0.01,
) : this(
{
Expand All @@ -77,14 +79,12 @@ class NextFeedbackCRServo @JvmOverloads constructor(
ServoConfigurationType.getStandardServoType(),
)
},
feedbackName,
{ feedback },
cacheTolerance,
)

private val analogInput by LazyHardware {
RobotController.hardwareMap[feedbackName] as AnalogInput
}
private val rawAngleRadians: Double by AnalogFeedback { analogInput.voltage }
private val analogInput by LazyHardware(feedbackInitializer)
private val rawAngleRadians: Double by analogInput

/**
* Actual angle of the servo, reported from the analog feedback input.
Expand Down
Loading
Loading