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

Commit

Permalink
feat: drone api (#49)
Browse files Browse the repository at this point in the history
Co-authored-by: Vifi5 <117041326+Vif15@users.noreply.github.com>
  • Loading branch information
BD103 and Vif15 committed Jan 25, 2024
2 parents aea6208 + 831b0b9 commit 8771d84
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
30 changes: 30 additions & 0 deletions TeamCode/src/main/java/org/firstinspires/ftc/teamcode/api/Drone.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.firstinspires.ftc.teamcode.api

import com.qualcomm.robotcore.eventloop.opmode.OpMode
import com.qualcomm.robotcore.hardware.Servo
import org.firstinspires.ftc.teamcode.utils.RobotConfig

/**
* An API to control the drone launcher.
*/
object Drone : API() {
private lateinit var pin: Servo

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

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

this.resetPin()
}

/** Moves the pin to the open position, releasing the drone. */
fun releasePin() {
this.pin.position = RobotConfig.Drone.OPEN_PIN
}

/** Resets the pin to its default, closed, position. */
private fun resetPin() {
this.pin.position = RobotConfig.Drone.CLOSE_PIN
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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.Drone
import org.firstinspires.ftc.teamcode.api.Telemetry
import org.firstinspires.ftc.teamcode.api.TriWheels
import org.firstinspires.ftc.teamcode.api.linear.Encoders
Expand Down Expand Up @@ -31,6 +32,7 @@ abstract class AutoMain : LinearOpMode() {
TriWheels.init(this)
Encoders.init(this)
Box.init(this)
Drone.init(this)

// Vision APIs
// AprilVision.init(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.qualcomm.robotcore.eventloop.opmode.OpMode
import com.qualcomm.robotcore.eventloop.opmode.TeleOp
import com.qualcomm.robotcore.hardware.DcMotor
import org.firstinspires.ftc.teamcode.api.Box
import org.firstinspires.ftc.teamcode.api.Drone
import org.firstinspires.ftc.teamcode.api.GamepadEx
import org.firstinspires.ftc.teamcode.api.LinearSlide
import org.firstinspires.ftc.teamcode.api.Telemetry
Expand All @@ -18,9 +19,6 @@ class TeleOpMain : OpMode() {
// Whether the linear slide should remain locked in place or not.
private var slideLocked = false

// Whether the robot should drive along the main axis or the pushbot axis.
private var pushBotAxis = false

// init will run once
override fun init() {
// Setup special telemetry
Expand All @@ -37,6 +35,9 @@ class TeleOpMain : OpMode() {
// Box controls
Box.init(this)

// Drone controls
Drone.init(this)

// Log that we are initialized
Telemetry.sayInitialized()
}
Expand All @@ -54,13 +55,7 @@ class TeleOpMain : OpMode() {

// angle and strength
// PI / 3 because 0 radians is right, not forward
val joyRadians =
atan2(joyY, joyX) - (PI / 3.0) +
if (this.pushBotAxis) {
2.0 * PI / 3.0
} else {
0.0
}
val joyRadians = atan2(joyY, joyX) - (PI / 3.0)

val joyMagnitude = sqrt(joyY * joyY + joyX * joyX)

Expand Down Expand Up @@ -107,10 +102,9 @@ class TeleOpMain : OpMode() {
Box.pickUpBox()
}

if (gamepad.y) {
this.pushBotAxis = true
} else if (gamepad.x) {
this.pushBotAxis = false
// Input to launch drone.
if (gamepad.x && gamepad.y) {
Drone.releasePin()
}

// movement of all wheels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ object RobotConfig {
var SLIDE_DOWN_POWER: Double = -0.4
}

/** Configurations related to the Drone API. */
@Config
object Drone {
@JvmField
var OPEN_PIN: Double = 0.5

@JvmField
var CLOSE_PIN: Double = 0.0
}

/**
* Represents what model of robot is running the code.
*
Expand Down

0 comments on commit 8771d84

Please sign in to comment.