Drive util - #18
Conversation
| data class DriveInput(val x: Double, val y: Double, val rx: Double) | ||
|
|
||
| /** Computed power for each wheel of a 4-wheel drivetrain. */ | ||
| data class WheelPowers( |
There was a problem hiding this comment.
Mecanum and Tank should define their own wheel power classes, because tank should only have two.
| ) | ||
|
|
||
| /** Converts raw drive input into wheel powers for a specific drivetrain type. */ | ||
| interface DriveKinematics { |
There was a problem hiding this comment.
This should then be generic over the wheel power class, so Mecanum would be MecanumKinematics : DriveKinematics<MecanumWheelPowers>
| * used to rotate stick input for field-centric driving. Pass `null` or nothing at all for | ||
| * robot-centric driving. | ||
| */ | ||
| class DrivetrainGroup( |
There was a problem hiding this comment.
This shouldn't exist. Just add mecanumDrive and tankDrive as functions that return commands given their kinematics objects + motors, and then field centric variants.
| /** Multiplier applied to all stick trigger values. */ | ||
| var scalar: Double = 1.0 | ||
| set(value) { | ||
| field = value.coerceIn(0.0, 1.0) |
|
|
||
| package dev.nextftc.control.drive | ||
|
|
||
| data class DriveInput(val x: Double, val y: Double, val rx: Double) |
|
|
||
| data class DriveInput(val x: Double, val y: Double, val rx: Double) | ||
|
|
||
| interface DriveKinematics<Output> { |
| ) | ||
|
|
||
| return MecanumWheelPowers( | ||
| frontLeft = (input.y + compensatedX + input.rx) / denominator, |
There was a problem hiding this comment.
It looks like you fundamentally misunderstood the coordinate system; +x is forward and +y is left, not the other way around. Thus this should be
| frontLeft = (input.y + compensatedX + input.rx) / denominator, | |
| frontLeft = (input.x + compensatedY + input.rx) / denominator, |
| override fun calculate(input: DriveInput): TankWheelPowers { | ||
| val denominator = max(input.y.absoluteValue + input.rx.absoluteValue, 1.0) | ||
| return TankWheelPowers( | ||
| left = (input.y + input.rx) / denominator, |
There was a problem hiding this comment.
See other comment about coordinate systems.
| * Lightweight wrapper for a distance sensor that caches the last reading. | ||
| * Call [update] in periodic to read the hardware. | ||
| * | ||
| * wait are you able to make new folders and class or nah? |
| gamepad: Gamepad, | ||
| ): Command = Commands.infinite { | ||
| val powers = kinematics.calculate( | ||
| DriveInput( |
There was a problem hiding this comment.
See other comment about coordinate systems (goes for all of these methods).
zachwaffle4
left a comment
There was a problem hiding this comment.
can you also merge upstream back into this branch pls
| /** | ||
| * Lightweight wrapper for a distance sensor that caches the last reading. | ||
| * Call [update] in periodic to read the hardware. | ||
| * |
There was a problem hiding this comment.
There's a random deletion here that shouldn't be.
| * Converts raw drive inputs into tank/differential wheel powers. | ||
| */ | ||
|
|
||
| class TankKinematics : DriveKinematics<TankWheelPowers> { |
There was a problem hiding this comment.
Clarify in the documentation that because tank drivetrains aren't holonomic, any y in the DriveInput will be ignored.
Mecanum and Tank and technically x drive