Repository navigation
Linear Actuator #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Linear Actuator #41
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8a97cde
feat: linear actuator wrapper for lift
RoushilS 05a685a
update
RoushilS 4e43eac
fix: setters and getters
RoushilS 5f7ca86
Merge branch 'main' into linear-actuator
zachwaffle4 e15ad90
Merge remote-tracking branch 'upstream/main' into linear-actuator
RoushilS 3f0ad85
fix: feedback
RoushilS 94b2d71
make positionTicks Double instead of Int and add more kdoc
zachwaffle4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
hardware/src/main/kotlin/dev/nextftc/hardware/actuators/LinearActuator.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package dev.nextftc.hardware.actuators | ||
|
|
||
| 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 | ||
| 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 | ||
| * | ||
| * @param motor wrapped NextMotor | ||
| * @param distPerRotation linear distance traveled per one motor rotation | ||
| */ | ||
| class LinearActuator(val motor: NextMotor, val distPerRotation: Per<DistanceUnit, AngleUnit>) { | ||
| private val distancePerRotation: Distance | ||
| get() = distPerRotation.unit.numerator.of(distPerRotation.magnitude) | ||
|
|
||
| /** | ||
| * The position of this linear actuator in linear [Distance] units. | ||
| */ | ||
| var position: Distance | ||
| get() { | ||
| val rotations = motor.encoderPosition.into(distPerRotation.unit.denominator) | ||
| return distancePerRotation * rotations | ||
| } | ||
| set(value) { | ||
| val rotations = value.into(distancePerRotation.unit) / distancePerRotation.magnitude | ||
| val angle = distPerRotation.unit.denominator.of(rotations) | ||
| motor.setPositionSetpoint(angle) | ||
| } | ||
|
|
||
| /** | ||
| * The position of this linear actuator in inches. | ||
| */ | ||
| var positionInches: Double | ||
| get() = position.into(Inches) | ||
| set(value) { | ||
| position = Inches.of(value) | ||
| } | ||
|
|
||
| /** | ||
| * The position of this linear actuator in motor tick units. | ||
| */ | ||
| var positionTicks: Double | ||
| get() = (motor.encoderPosition / motor.anglePerCount).magnitude | ||
| set(value) { | ||
| val angle = motor.anglePerCount * value | ||
| motor.setPositionSetpoint(angle) | ||
| } | ||
|
|
||
| var throttle: Double | ||
| get() = motor.throttle | ||
| set(value) { | ||
| motor.throttle = value | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.