Conversation
zachwaffle4
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
why not js do Rotations.of(.....)
| } | ||
|
|
||
| var positionTicks: Int | ||
| get() = ((motor.encoderPosition / motor.anglePerCount).magnitude).roundToInt() |
There was a problem hiding this comment.
Wouldn't this cause decimals to be lost? If you round every time?
| position = Inches.of(value) | ||
| } | ||
|
|
||
| var positionTicks: Int |
There was a problem hiding this comment.
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
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).