Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Commit

Permalink
refactor!: prune AutoMain
Browse files Browse the repository at this point in the history
  • Loading branch information
BD103 committed Feb 24, 2024
1 parent c39be6b commit 0e218e4
Showing 1 changed file with 10 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
package org.firstinspires.ftc.teamcode.opmode.autonomous

import com.qualcomm.robotcore.eventloop.opmode.Autonomous
import com.qualcomm.robotcore.eventloop.opmode.Disabled
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode
import org.firstinspires.ftc.teamcode.api.Drone
import org.firstinspires.ftc.teamcode.api.Telemetry
import org.firstinspires.ftc.teamcode.api.TriWheels
import org.firstinspires.ftc.teamcode.api.linear.Encoders
import org.firstinspires.ftc.teamcode.utils.RobotConfig
import org.firstinspires.ftc.teamcode.utils.Team

abstract class AutoMain : LinearOpMode() {
abstract val config: Config
abstract val team: Team

/** The axis the robot should move along. */
private val forward =
when (RobotConfig.model) {
RobotConfig.Model.MiniRobot -> Encoders.Direction.Red
RobotConfig.Model.RobotA -> Encoders.Direction.Blue
RobotConfig.Model.RobotB -> Encoders.Direction.Red
}

/** How many inches the robot is from the starting tile */
private val startingOffset = 2.0

/** The length and width of a tile in inches. */
private val tileSize = 24.0

override fun runOpMode() {
Telemetry.init(this)
TriWheels.init(this)
Encoders.init(this)
Drone.init(this)

Telemetry.sayInitialized()

Expand All @@ -53,94 +48,25 @@ abstract class AutoMain : LinearOpMode() {
* A utility that returns the value correlating to the configured team.
*
* It is a lot easier to understand by reading the code than explaining it here.
*
* @see pickParkPos
*/
private fun <T> pickTeam(
red: T,
blue: T,
): T =
when (config.team) {
when (team) {
Team.Red -> red
Team.Blue -> blue
}

/**
* A utility that returns the value correlating to the configured parking position.
*
* It is a lot easier to understand by reading the code than explaining it here.
*
* @see pickTeam
*/
private fun <T> pickParkPos(
left: T,
right: T,
): T =
when (config.parkPos) {
ParkPos.LeftOfBackdrop -> left
ParkPos.RightOfBackdrop -> right
}

data class Config(val team: Team, val startPos: StartPos, val parkPos: ParkPos)

enum class StartPos {
BackStage,
FrontStage,
}

enum class ParkPos {
LeftOfBackdrop,
RightOfBackdrop,
}
}

// Matrix of run configurations
// {Red,Blue}{Front,Back}{Left,Right}

@Autonomous(name = "AutoMain - RedFrontLeft")
@Disabled
class AutoMainRedFrontLeft : AutoMain() {
override val config = Config(Team.Red, StartPos.FrontStage, ParkPos.LeftOfBackdrop)
}

@Autonomous(name = "AutoMain - BlueFrontLeft")
@Disabled
class AutoMainBlueFrontLeft : AutoMain() {
override val config = Config(Team.Blue, StartPos.FrontStage, ParkPos.LeftOfBackdrop)
}

@Autonomous(name = "AutoMain - RedBackLeft")
@Disabled
class AutoMainRedBackLeft : AutoMain() {
override val config = Config(Team.Red, StartPos.BackStage, ParkPos.LeftOfBackdrop)
}

@Autonomous(name = "AutoMain - BlueBackLeft")
@Disabled
class AutoMainBlueBackLeft : AutoMain() {
override val config = Config(Team.Blue, StartPos.BackStage, ParkPos.LeftOfBackdrop)
}

@Autonomous(name = "AutoMain - RedFrontRight")
@Disabled
class AutoMainRedFrontRight : AutoMain() {
override val config = Config(Team.Red, StartPos.FrontStage, ParkPos.RightOfBackdrop)
}

@Autonomous(name = "AutoMain - BlueFrontRight")
@Disabled
class AutoMainBlueFrontRight : AutoMain() {
override val config = Config(Team.Blue, StartPos.FrontStage, ParkPos.RightOfBackdrop)
data class Config(val team: Team)
}

@Autonomous(name = "AutoMain - RedBackRight")
@Disabled
class AutoMainRedBackRight : AutoMain() {
override val config = Config(Team.Red, StartPos.BackStage, ParkPos.RightOfBackdrop)
@Autonomous(name = "AutoMain - Red")
class AutoMainRed : AutoMain() {
override val team = Team.Red
}

@Autonomous(name = "AutoMain - BlueBackRight")
@Disabled
class AutoMainBlueBackRight : AutoMain() {
override val config = Config(Team.Blue, StartPos.BackStage, ParkPos.RightOfBackdrop)
@Autonomous(name = "AutoMain - Blue")
class AutoMainBlue : AutoMain() {
override val team = Team.Blue
}

0 comments on commit 0e218e4

Please sign in to comment.