sertain / sertain-legacy

:robot: Write more for your robot with less
https://sertain.github.io/javadocs
MIT License
9 stars 3 forks source link

Execute method should contain PID output values #44

Closed andrewda closed 6 years ago

andrewda commented 6 years ago

This is how we are currently writing our PidCommands:

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
    }
}
SUPERCILEX commented 6 years ago

Fixed in e01d8fb83ad7a80a16bf472e59b287f7906f80e5.