From 8a97cdea3eadf7ed4da00b0bc2d472aaf8987891 Mon Sep 17 00:00:00 2001 From: Roushil Satta Date: Wed, 16 Sep 2026 20:27:52 -0700 Subject: [PATCH 1/5] feat: linear actuator wrapper for lift --- .../hardware/actuators/LinearActuator.kt | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 hardware/src/main/kotlin/dev/nextftc/hardware/actuators/LinearActuator.kt diff --git a/hardware/src/main/kotlin/dev/nextftc/hardware/actuators/LinearActuator.kt b/hardware/src/main/kotlin/dev/nextftc/hardware/actuators/LinearActuator.kt new file mode 100644 index 00000000..0f46b87c --- /dev/null +++ b/hardware/src/main/kotlin/dev/nextftc/hardware/actuators/LinearActuator.kt @@ -0,0 +1,36 @@ +package dev.nextftc.hardware.actuators + +import dev.nextftc.units.Units +import dev.nextftc.units.measuretypes.Angle +import dev.nextftc.units.measuretypes.Distance +import dev.nextftc.units.measuretypes.Per +import dev.nextftc.units.unittypes.AngleUnit +import dev.nextftc.units.unittypes.DistanceUnit + +/** + * Wraps a `NextMotor` and a distance-per-rotation, to work on linear units + * + * @param motor wrapped NextMotor + * @param distPerRotation linear distance traveled per one motor rotation + */ +class LinearActuator( + val motor: NextMotor, + val distPerRotation: Per, +) { + fun setPosition(distance: Distance) { + // convert distance to rotations + val rotations = distance.into(Units.Inches) / distPerRotation.magnitude + val angle: Angle = Units.Rotations.of(rotations) + motor.setPositionSetpoint(angle) + } + + fun setPositionInches(inches: Double) = setPosition(Units.Inches.of(inches)) + + fun setPositionTicks(ticks: Int) { + val angle = motor.anglePerCount * ticks + motor.setPositionSetpoint(angle) + } + + fun setThrottle(throttle: Double) { motor.throttle = throttle } + fun setThrottleContinuous(throttle: Double) { motor.throttle = throttle } +} From 05a685a04357f22336adaf00137e1120427e5eae Mon Sep 17 00:00:00 2001 From: Roushil Satta Date: Wed, 16 Sep 2026 21:39:14 -0700 Subject: [PATCH 2/5] update --- .../hardware/actuators/LinearActuator.kt | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/hardware/src/main/kotlin/dev/nextftc/hardware/actuators/LinearActuator.kt b/hardware/src/main/kotlin/dev/nextftc/hardware/actuators/LinearActuator.kt index 0f46b87c..e64434e6 100644 --- a/hardware/src/main/kotlin/dev/nextftc/hardware/actuators/LinearActuator.kt +++ b/hardware/src/main/kotlin/dev/nextftc/hardware/actuators/LinearActuator.kt @@ -1,6 +1,7 @@ package dev.nextftc.hardware.actuators -import dev.nextftc.units.Units +import dev.nextftc.units.Inches +import dev.nextftc.units.Rotations import dev.nextftc.units.measuretypes.Angle import dev.nextftc.units.measuretypes.Distance import dev.nextftc.units.measuretypes.Per @@ -13,24 +14,26 @@ import dev.nextftc.units.unittypes.DistanceUnit * @param motor wrapped NextMotor * @param distPerRotation linear distance traveled per one motor rotation */ -class LinearActuator( - val motor: NextMotor, - val distPerRotation: Per, -) { +class LinearActuator(val motor: NextMotor, val distPerRotation: Per) { fun setPosition(distance: Distance) { // convert distance to rotations - val rotations = distance.into(Units.Inches) / distPerRotation.magnitude - val angle: Angle = Units.Rotations.of(rotations) + val rotations = distance.into(Inches) / distPerRotation.magnitude + val angle: Angle = Rotations.of(rotations) motor.setPositionSetpoint(angle) } - fun setPositionInches(inches: Double) = setPosition(Units.Inches.of(inches)) + fun setPositionInches(inches: Double) = setPosition(Inches.of(inches)) fun setPositionTicks(ticks: Int) { - val angle = motor.anglePerCount * ticks + val angle = (motor.anglePerCount * ticks) as Angle motor.setPositionSetpoint(angle) } - fun setThrottle(throttle: Double) { motor.throttle = throttle } - fun setThrottleContinuous(throttle: Double) { motor.throttle = throttle } + fun setThrottle(throttle: Double) { + motor.throttle = throttle + } + + fun setThrottleContinuous(throttle: Double) { + motor.throttle = throttle + } } From 4e43eac4033ee92c5e2dfc7fecc896e8c1f6e4d1 Mon Sep 17 00:00:00 2001 From: Roushil Satta Date: Wed, 16 Sep 2026 22:05:40 -0700 Subject: [PATCH 3/5] fix: setters and getters --- .../hardware/actuators/LinearActuator.kt | 47 ++++++++++++------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/hardware/src/main/kotlin/dev/nextftc/hardware/actuators/LinearActuator.kt b/hardware/src/main/kotlin/dev/nextftc/hardware/actuators/LinearActuator.kt index e64434e6..403769f6 100644 --- a/hardware/src/main/kotlin/dev/nextftc/hardware/actuators/LinearActuator.kt +++ b/hardware/src/main/kotlin/dev/nextftc/hardware/actuators/LinearActuator.kt @@ -7,6 +7,7 @@ import dev.nextftc.units.measuretypes.Distance import dev.nextftc.units.measuretypes.Per import dev.nextftc.units.unittypes.AngleUnit import dev.nextftc.units.unittypes.DistanceUnit +import kotlin.math.roundToInt /** * Wraps a `NextMotor` and a distance-per-rotation, to work on linear units @@ -15,25 +16,37 @@ import dev.nextftc.units.unittypes.DistanceUnit * @param distPerRotation linear distance traveled per one motor rotation */ class LinearActuator(val motor: NextMotor, val distPerRotation: Per) { - fun setPosition(distance: Distance) { - // convert distance to rotations - val rotations = distance.into(Inches) / distPerRotation.magnitude - val angle: Angle = Rotations.of(rotations) - motor.setPositionSetpoint(angle) - } + var position: Distance + get() = Inches.of(motor.encoderPosition.into(Rotations) * distPerRotation.magnitude) + set(value) { + // convert distance to rotations + val rotations = value.into(Inches) / distPerRotation.magnitude + val angle: Angle = Rotations.of(rotations) + motor.setPositionSetpoint(angle) + } - fun setPositionInches(inches: Double) = setPosition(Inches.of(inches)) + var positionInches: Double + get() = position.into(Inches) + set(value) { + position = Inches.of(value) + } - fun setPositionTicks(ticks: Int) { - val angle = (motor.anglePerCount * ticks) as Angle - motor.setPositionSetpoint(angle) - } + var positionTicks: Int + get() = ((motor.encoderPosition / motor.anglePerCount).magnitude).roundToInt() + set(value) { + val angle = (motor.anglePerCount * value) as Angle + motor.setPositionSetpoint(angle) + } - fun setThrottle(throttle: Double) { - motor.throttle = throttle - } + var throttle: Double + get() = motor.throttle + set(value) { + motor.throttle = value + } - fun setThrottleContinuous(throttle: Double) { - motor.throttle = throttle - } + var throttleContinuous: Double + get() = throttle + set(value) { + throttle = value + } } From 3f0ad8553fc9a99c314e4094c6a583b562112664 Mon Sep 17 00:00:00 2001 From: Roushil Satta Date: Sun, 27 Sep 2026 17:38:12 -0700 Subject: [PATCH 4/5] fix: feedback --- .../nextftc/hardware/actuators/LinearActuator.kt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/hardware/src/main/kotlin/dev/nextftc/hardware/actuators/LinearActuator.kt b/hardware/src/main/kotlin/dev/nextftc/hardware/actuators/LinearActuator.kt index 403769f6..ca859de9 100644 --- a/hardware/src/main/kotlin/dev/nextftc/hardware/actuators/LinearActuator.kt +++ b/hardware/src/main/kotlin/dev/nextftc/hardware/actuators/LinearActuator.kt @@ -16,12 +16,17 @@ import kotlin.math.roundToInt * @param distPerRotation linear distance traveled per one motor rotation */ class LinearActuator(val motor: NextMotor, val distPerRotation: Per) { + private val distancePerRotation: Distance + get() = distPerRotation.unit.numerator.of(distPerRotation.magnitude) + var position: Distance - get() = Inches.of(motor.encoderPosition.into(Rotations) * distPerRotation.magnitude) + get() { + val rotations = motor.encoderPosition.into(distPerRotation.unit.denominator) + return distancePerRotation * rotations + } set(value) { - // convert distance to rotations - val rotations = value.into(Inches) / distPerRotation.magnitude - val angle: Angle = Rotations.of(rotations) + val rotations = value.into(distancePerRotation.unit) / distancePerRotation.magnitude + val angle = distPerRotation.unit.denominator.of(rotations) motor.setPositionSetpoint(angle) } @@ -34,7 +39,7 @@ class LinearActuator(val motor: NextMotor, val distPerRotation: Per Date: Mon, 5 Oct 2026 11:59:57 -0400 Subject: [PATCH 5/5] make positionTicks Double instead of Int and add more kdoc Signed-off-by: Zach Harel --- .../hardware/actuators/LinearActuator.kt | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/hardware/src/main/kotlin/dev/nextftc/hardware/actuators/LinearActuator.kt b/hardware/src/main/kotlin/dev/nextftc/hardware/actuators/LinearActuator.kt index ca859de9..910574d5 100644 --- a/hardware/src/main/kotlin/dev/nextftc/hardware/actuators/LinearActuator.kt +++ b/hardware/src/main/kotlin/dev/nextftc/hardware/actuators/LinearActuator.kt @@ -19,6 +19,9 @@ class LinearActuator(val motor: NextMotor, val distPerRotation: Per