Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

Cleanup Code #51

Merged
merged 16 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: CI

on:
# Update on pushes to main
push:
branches: [ "main" ]

pull_request:

# Allow running workflow manually
workflow_dispatch:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
cache: 'gradle'

- name: Lint project
run: |
chmod +x ./gradlew
./gradlew lintKotlin
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
cache: 'gradle'

- name: Build project
run: |
chmod +x ./gradlew
./gradlew build
6 changes: 3 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Setup JDK 11
uses: actions/setup-java@v3
- name: Setup JDK 17
uses: actions/setup-java@v4
with:
java-version: 11
java-version: 17
distribution: 'temurin'
cache: 'gradle'

Expand Down
30 changes: 0 additions & 30 deletions .github/workflows/lint.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract class API {
@Deprecated(
message = "Accessing the hardwareMap indirectly is not supported.",
replaceWith = ReplaceWith("this.opMode.hardwareMap"),
level = DeprecationLevel.WARNING,
level = DeprecationLevel.ERROR,
)
protected val hardwareMap: HardwareMap
get() = this.opMode.hardwareMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ import org.firstinspires.ftc.teamcode.utils.opModeSleep
/**
* An API for controlling the Box on the robot.
*/
@Deprecated(
message = "The Box hardware component has been removed.",
level = DeprecationLevel.WARNING,
)
object Box : API() {
private lateinit var box: Servo
private lateinit var grip: Servo

override fun init(opMode: OpMode) {
super.init(opMode)

this.box = this.hardwareMap.get(Servo::class.java, "box")
this.grip = this.hardwareMap.get(Servo::class.java, "grip")
this.box = this.opMode.hardwareMap.get(Servo::class.java, "box")
this.grip = this.opMode.hardwareMap.get(Servo::class.java, "grip")

// Close grip at the beginning.
this.gripOut()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ object DemoQuadWheels : API() {
// You must call super.init(opMode), or the API will not initialize correctly.
super.init(opMode)

this.fl = this.hardwareMap.get(DcMotor::class.java, "fl")
this.fr = this.hardwareMap.get(DcMotor::class.java, "fr")
this.bl = this.hardwareMap.get(DcMotor::class.java, "bl")
this.br = this.hardwareMap.get(DcMotor::class.java, "br")
this.fl = this.opMode.hardwareMap.get(DcMotor::class.java, "fl")
this.fr = this.opMode.hardwareMap.get(DcMotor::class.java, "fr")
this.bl = this.opMode.hardwareMap.get(DcMotor::class.java, "bl")
this.br = this.opMode.hardwareMap.get(DcMotor::class.java, "br")
}

// A public function that sets the power of all four wheels.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ object TriWheels : API() {
override fun init(opMode: OpMode) {
super.init(opMode)

this.red = hardwareMap.get(DcMotor::class.java, "redWheel")
this.green = hardwareMap.get(DcMotor::class.java, "greenWheel")
this.blue = hardwareMap.get(DcMotor::class.java, "blueWheel")
this.red = this.opMode.hardwareMap.get(DcMotor::class.java, "redWheel")
this.green = this.opMode.hardwareMap.get(DcMotor::class.java, "greenWheel")
this.blue = this.opMode.hardwareMap.get(DcMotor::class.java, "blueWheel")

this.stopAndResetMotors()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ 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.Box
import org.firstinspires.ftc.teamcode.api.Telemetry
import org.firstinspires.ftc.teamcode.api.TriWheels
import org.firstinspires.ftc.teamcode.api.linear.Encoders
Expand All @@ -30,84 +29,16 @@ abstract class AutoMain : LinearOpMode() {
Telemetry.init(this)
TriWheels.init(this)
Encoders.init(this)
Box.init(this)

// Vision APIs
// AprilVision.init(this)
// Vision.init(this, AprilVision)

// AprilMovement.init(this)

// Modify camera exposure for april tags
// This may interfere with other vision processes like Tensorflow
// Vision.optimizeForAprilTags()

// Stream camera to FTC Dashboard
// val camera = getVisionPortalCamera(Vision.portal)!!
// FtcDashboard.getInstance().startCameraStream(camera, 0.0)

Telemetry.sayInitialized()

waitForStart()

/*
// TODO: Scan team game element
val teamElementPos = 2
*/
Telemetry.sayStarted()

sleep(RobotConfig.AutoMain.WAIT_TIME)

telemetry.log().add("No team game element scanned, defaulting to 2!")
telemetry.update()

when (config.startPos) {
StartPos.BackStage -> {
Encoders.driveTo(forward, startingOffset)
Encoders.spinTo(pickTeam(90.0, -90.0))
Encoders.driveTo(forward, tiles(1))
Encoders.spinTo(pickTeam(-90.0, 90.0))
Encoders.driveTo(forward, tiles(1))
Encoders.spinTo(pickTeam(90.0, -90.0))
Encoders.driveTo(forward, tiles(2))
}

StartPos.FrontStage -> {
// Drive forward two tiles
Encoders.driveTo(forward, tiles(2) + startingOffset)

// Spin to face backdrop
Encoders.spinTo(pickTeam(90.0, -90.0))

Encoders.driveTo(forward, tiles(1))
}
}

/*

// Deposit pixel using april tag
// Red: 1, 2, 3. Blue: 4, 5, 6
AprilMovement.driveTo(teamElementPos + pickTeam(0, 3))

// TODO: Deposit pixel

// Back up to view all april tags
Encoders.driveTo(forward, tiles(-1))

// Center 1 tile away from middle april tag
when (config.team) {
Team.Red -> AprilMovement.driveTo(5, tiles(1))
Team.Blue -> AprilMovement.driveTo(2, tiles(1))
}

*/

// Navigate to parking spot
Encoders.spinTo(pickParkPos(-90.0, 90.0))
Encoders.driveTo(forward, tiles(1))
Encoders.spinTo(pickParkPos(90.0, -90.0))

// Park in spot
Encoders.driveTo(forward, tiles(1))
// TODO: Rest of the autonomous.
}

/** Converts an amount of tiles to inches. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ 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 com.qualcomm.robotcore.util.ElapsedTime
import org.firstinspires.ftc.teamcode.api.DemoQuadWheels
import org.firstinspires.ftc.teamcode.api.Telemetry
import org.firstinspires.ftc.teamcode.components.linear.DemoSpinLinear

@Autonomous(name = "Demo Autonomous")
@Disabled
Expand All @@ -26,7 +26,14 @@ class DemoAutonomous : LinearOpMode() {
// Log that we are started
Telemetry.sayStarted()

// Linear components are run in order
DemoSpinLinear.run(this)
val runtime = ElapsedTime()

while (runtime.seconds() < 2.0) {
// Drive at 50% speed, slowing down the closer we get to 2 seconds.
DemoQuadWheels.drive(0.5 * (2.0 - runtime.seconds()))
}

// Stop the robot.
DemoQuadWheels.drive(0.0)
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("DEPRECATION")

package org.firstinspires.ftc.teamcode.opmode.autonomous

import com.qualcomm.robotcore.eventloop.opmode.Autonomous
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.firstinspires.ftc.teamcode.api.DemoQuadWheels
import org.firstinspires.ftc.teamcode.api.Telemetry
import org.firstinspires.ftc.teamcode.api.vision.AprilVision
import org.firstinspires.ftc.teamcode.api.vision.Vision
import org.firstinspires.ftc.teamcode.components.DemoForward

@TeleOp(name = "Demo TeleOp")
@Disabled
Expand All @@ -32,8 +31,17 @@ class DemoTeleOp : OpMode() {

// Run repeatedly while the robot is running.
override fun loop() {
// Runs the component.
DemoForward.loop(this)
val x = this.gamepad1.left_stick_x.toDouble()
val y = this.gamepad1.left_stick_y.toDouble()
val rotation = this.gamepad1.right_stick_x.toDouble()

// Strafe + rotate robot using left and right joysticks.
DemoQuadWheels.drive(
x - y + rotation,
-x - y - rotation,
-x - y + rotation,
x - y - rotation,
)

// Log that we are running
Telemetry.sayRunning()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("DEPRECATION")

package org.firstinspires.ftc.teamcode.opmode.teleop

import com.qualcomm.robotcore.eventloop.opmode.OpMode
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

buildscript {
ext {
kotlin_version = '1.9.0'
kotlin_version = '1.9.22'
}
repositories {
mavenCentral()
google()
}
dependencies {
// Note for FTC Teams: Do not modify this yourself.
classpath 'com.android.tools.build:gradle:7.4.2'
classpath 'com.android.tools.build:gradle:8.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
6 changes: 6 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ android.enableJetifier=true
org.gradle.jvmargs=-Xmx1024M
# Force Kotlin official code style
kotlin.code.style=official
# Disable auto-downloading of Java toolchains
org.gradle.java.installations.auto-download=false
# Gradle 8.0 config
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Dec 14 13:01:55 EST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists