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

Box Movement #36

Merged
merged 19 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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
51 changes: 51 additions & 0 deletions TeamCode/src/main/java/org/firstinspires/ftc/teamcode/api/Box.kt
BD103 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.firstinspires.ftc.teamcode.api

import com.qualcomm.robotcore.eventloop.opmode.OpMode
import com.qualcomm.robotcore.hardware.Servo

/**
* An API for controlling the Box on the robot.
*/
object Box : API() {
BD103 marked this conversation as resolved.
Show resolved Hide resolved
private lateinit var boxL: Servo
private lateinit var boxR: Servo
private lateinit var grip: Servo

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

this.boxL = this.hardwareMap.get(Servo::class.java, "boxL")
this.boxR = this.hardwareMap.get(Servo::class.java, "boxR")
BD103 marked this conversation as resolved.
Show resolved Hide resolved
this.grip = this.hardwareMap.get(Servo::class.java, "grip")
}

/**
* Moves the box to the ground
*/
fun dropBox() {
this.boxL.position = 0.4
this.boxR.position = 0.35
}

/**
* Moves box to upright position
*/
fun pickUpBox() {
this.boxL.position = 0.76
this.boxR.position = 0.0
}

/**
* Moves the grip to keep pixels in place when [pickUpBox] the box
*/
fun gripIn() {
this.grip.position = 0.23
}

/**
* Resets the grip to starting position
*/
fun gripOut() {
this.grip.position = 0.11
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.firstinspires.ftc.teamcode.components

import com.qualcomm.robotcore.eventloop.opmode.OpMode
import org.firstinspires.ftc.teamcode.api.Box
import org.firstinspires.ftc.teamcode.api.TriWheels
import org.firstinspires.ftc.teamcode.utils.RobotConfig
import kotlin.math.PI
Expand Down Expand Up @@ -30,11 +31,25 @@ object TeleOpMovement : Component {
val joyRadians = atan2(joyY, joyX) - (PI / 3.0)
var joyMagnitude = sqrt(joyY * joyY + joyX * joyX)

// if the right bumper is pressed move slower
if (gamepad.right_bumper) {
// if the y button is pressed move slower
if (gamepad.y) {
joyMagnitude *= SLOW_MULTIPLIER
}

// Inputs for the gripper on the box
if (gamepad.left_bumper) {
Box.gripIn()
} else if (gamepad.right_bumper) {
Box.gripOut()
}

// Inputs for the movement of the box
if (gamepad.a) {
Box.dropBox()
} else if (gamepad.b) {
Box.pickUpBox()
}

// movement of all wheels
TriWheels.driveWithRotation(
joyRadians,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.firstinspires.ftc.teamcode.opmode.teleop

import com.qualcomm.robotcore.eventloop.opmode.OpMode
import com.qualcomm.robotcore.eventloop.opmode.TeleOp
import org.firstinspires.ftc.teamcode.api.Box
import org.firstinspires.ftc.teamcode.api.GamepadEx
import org.firstinspires.ftc.teamcode.api.Telemetry
import org.firstinspires.ftc.teamcode.api.TriWheels
Expand All @@ -24,6 +25,9 @@ class TeleOpMain : OpMode() {
// Advanced gamepad inputs
GamepadEx.init(this)

// Box controls
Box.init(this)

// Log that we are initialized
Telemetry.sayInitialized()
}
Expand Down