Skip to content
This repository has been archived by the owner on Dec 24, 2018. It is now read-only.

Commit

Permalink
Fix DriveToCube command
Browse files Browse the repository at this point in the history
This allows the DriveToCube command to have no cube in sight for a set
amount of time without terminating. This allows for the robot to
occasionally lose sight without killing auto.
  • Loading branch information
andrewda committed Aug 26, 2018
1 parent f9bdecb commit 5ad9e33
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,35 @@ import org.sert2521.powerup.elevator.Elevator
import org.sert2521.powerup.intake.Intake
import org.sert2521.powerup.util.DEGREES_PER_PIXEL
import org.sert2521.powerup.util.Vision
import java.util.Date

class DriveToCube : AngleDriver(0.008, 0.0, 0.022) {
private lateinit var visionLastSeen: Date

class DriveToCube : AngleDriver(0.01, 0.0, 0.022) {
init {
requires(Drivetrain)
}

override fun onCreate() = updateSetpoint(0.0)
override fun onCreate() {
updateSetpoint(0.0)
visionLastSeen = Date()
}

override fun execute(output: Double): Boolean {
println("Found Cube: ${Vision.found}, " +
"X Offset: ${Vision.xOffset}, " +
"Y Offset: ${Vision.yOffset}")
"Y Offset: ${Vision.yOffset}, " +
"Values: (${BASE_SPEED + output}, ${BASE_SPEED - output})")

if (Vision.found == true) {
visionLastSeen = Date()

Drivetrain.drive(BASE_SPEED + output, BASE_SPEED - output)
updateSetpoint(Vision.xOffset?.toDouble() ?: 0.0 * DEGREES_PER_PIXEL)
return Intake.hasCube && Elevator.atBottom
}

return true
return visionLastSeen.time - Date().time > MAX_TIME_WITHOUT_CUBE
}

private fun updateSetpoint(offset: Double) {
Expand All @@ -33,5 +42,6 @@ class DriveToCube : AngleDriver(0.01, 0.0, 0.022) {

private companion object {
const val BASE_SPEED = 0.3
const val MAX_TIME_WITHOUT_CUBE = 5000
}
}

0 comments on commit 5ad9e33

Please sign in to comment.