Skip to content

Linear Actuator - #41

Open
RoushilS wants to merge 6 commits into
NextFTC:mainfrom
RoushilS:linear-actuator
Open

RoushilS wants to merge 6 commits into
NextFTC:mainfrom
RoushilS:linear-actuator

Conversation

@RoushilS

Copy link
Copy Markdown

Added a LinearActuator wrapper that holds a NextMotor and a distance-per-rotation Per.

It converts linear distances to rotations and calls NextMotor.setPositionSetpoint(Angle).

@zachwaffle4 zachwaffle4 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to do the math directly on the Angle, Distance, and Per values without needing to convert to Doubles (ie, without needing .into/.magnitude).

@RoushilS

RoushilS commented Sep 19, 2026 •

Copy link
Copy Markdown
Author

You should be able to do the math directly on the Angle, Distance, and Per values without needing to convert to Doubles (ie, without needing .into/.magnitude).

Does that work? It looks like the units library doesn't declare those operator overloads, so I'm pretty confused if I'm interpreting this right.

@28shettr

Copy link
Copy Markdown
Member

You should be able to do the math directly on the Angle, Distance, and Per values without needing to convert to Doubles (ie, without needing .into/.magnitude).

Does that work? It looks like the units library doesn't declare those operator overloads, so I'm pretty confused if I'm interpreting this right.

Yeah I dont think it's possible

* @param distPerRotation linear distance traveled per one motor rotation
*/
class LinearActuator(val motor: NextMotor, val distPerRotation: Per<DistanceUnit, AngleUnit>) {
var position: Distance

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either type it as Per<Inches, Rotations> or convert distPerRotation to Inches first

var positionTicks: Int
get() = ((motor.encoderPosition / motor.anglePerCount).magnitude).roundToInt()
set(value) {
val angle = (motor.anglePerCount * value) as Angle

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not js do Rotations.of(.....)

}

var positionTicks: Int
get() = ((motor.encoderPosition / motor.anglePerCount).magnitude).roundToInt()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this cause decimals to be lost? If you round every time?

position = Inches.of(value)
}

var positionTicks: Int

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should 100% be a Double; the SDK exposes it as an integer but the unit conversion would likely cause it to end up as a double value and we don't want any information lost

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants