Closed andrewda closed 6 years ago
This is how we are currently writing our PidCommands:
PidCommand
class TurnToAngle(private val angle: Double) : PidCommand(P, I, D) { init { requires(Drivetrain) } override fun execute() = (Drivetrain.ahrs.yaw - angle).absoluteValue < ALLOWABLE_ERROR override fun returnPidInput() = Drivetrain.ahrs.yaw.toDouble() override fun usePidOutput(output: Double) { Drivetrain.drive(BASE_SPEED + output, BASE_SPEED - output) } companion object { private const val P = 1.0 private const val I = 1.0 private const val D = 1.0 private const val BASE_SPEED = 0.25 private const val ALLOWABLE_ERROR = 10 // in degrees } }
We should consider doing something more like this:
class TurnToAngle(private val angle: Double) : PidCommand(P, I, D) { init { requires(Drivetrain) } override fun execute(output: Double) { Drivetrain.drive(BASE_SPEED + output, BASE_SPEED - output) return (Drivetrain.ahrs.yaw - angle).absoluteValue < ALLOWABLE_ERROR } override fun returnPidInput() = Drivetrain.ahrs.yaw.toDouble() companion object { private const val P = 1.0 private const val I = 1.0 private const val D = 1.0 private const val BASE_SPEED = 0.25 private const val ALLOWABLE_ERROR = 10 // in degrees } }
Fixed in e01d8fb83ad7a80a16bf472e59b287f7906f80e5.
This is how we are currently writing our
PidCommand
s:We should consider doing something more like this: