/* Copyright (c) 2017 FIRST. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted (subject to the limitations in the disclaimer below) provided that
* the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* Neither the name of FIRST nor the names of its contributors may be used to endorse or
* promote products derived from this software without specific prior written permission.
*
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS
* LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
import com.qualcomm.robotcore.hardware.Servo;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.util.ElapsedTime;
import com.qualcomm.robotcore.util.Range;
@TeleOp(name="Starter Bot 2024", group="Iterative Opmode")
public class StarterBot2024Teleop extends OpMode
{
// Declare OpMode members.
private ElapsedTime runtime = new ElapsedTime();
private DcMotor leftDrive = null;
private DcMotor rightDrive = null;
private DcMotor armLeft = null;
private DcMotor armRight = null;
private Servo gripper = null;
private Servo wrist = null;
private boolean manualMode = false;
private double armSetpoint = 0.0;
private final double armManualDeadband = 0.03;
private final double gripperClosedPosition = 1.0;
private final double gripperOpenPosition = 0.5;
private final double wristUpPosition = 1.0;
private final double wristDownPosition = 0.0;
private final int armHomePosition = 0;
private final int armIntakePosition = 10;
private final int armScorePosition = 600;
private final int armShutdownThreshold = 5;
/*
* Code to run ONCE when the driver hits INIT
*/
@Override
public void init() {
telemetry.addData("Status", "Initialized");
leftDrive = hardwareMap.get(DcMotor.class, "leftDrive");
rightDrive = hardwareMap.get(DcMotor.class, "rightDrive");
armLeft = hardwareMap.get(DcMotor.class, "armLeft");
armRight = hardwareMap.get(DcMotor.class, "armRight");
gripper = hardwareMap.get(Servo.class, "gripper");
wrist = hardwareMap.get(Servo.class, "wrist");
leftDrive.setDirection(DcMotor.Direction.FORWARD);
rightDrive.setDirection(DcMotor.Direction.REVERSE);
leftDrive.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.FLOAT);
rightDrive.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.FLOAT);
armLeft.setDirection(DcMotor.Direction.FORWARD);
armRight.setDirection(DcMotor.Direction.REVERSE);
armLeft.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
armRight.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
armLeft.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
armRight.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
armLeft.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
armRight.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
armLeft.setPower(0.0);
armRight.setPower(0.0);
telemetry.addData("Status", "Initialized");
}
/*
* Code to run REPEATEDLY after the driver hits INIT, but before they hit PLAY
*/
@Override
public void init_loop() {
}
/*
* Code to run ONCE when the driver hits PLAY
*/
@Override
public void start() {
runtime.reset();
armLeft.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
armRight.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
armLeft.setTargetPosition(armHomePosition);
armRight.setTargetPosition(armHomePosition);
armLeft.setPower(1.0);
armRight.setPower(1.0);
armLeft.setMode(DcMotor.RunMode.RUN_TO_POSITION);
armRight.setMode(DcMotor.RunMode.RUN_TO_POSITION);
}
/*
* Code to run REPEATEDLY after the driver hits PLAY but before they hit STOP
*/
@Override
public void loop() {
double leftPower;
double rightPower;
double manualArmPower;
//DRIVE
double drive = -gamepad1.left_stick_y;
double turn = gamepad1.right_stick_x;
leftPower = Range.clip(drive + turn, -1.0, 1.0) ;
rightPower = Range.clip(drive - turn, -1.0, 1.0) ;
leftDrive.setPower(leftPower);
rightDrive.setPower(rightPower);
//ARM & WRIST
manualArmPower = gamepad1.right_trigger - gamepad1.left_trigger;
if (Math.abs(manualArmPower) > armManualDeadband) {
if (!manualMode) {
armLeft.setPower(0.0);
armRight.setPower(0.0);
armLeft.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
armRight.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
manualMode = true;
}
armLeft.setPower(manualArmPower);
armRight.setPower(manualArmPower);
}
else {
if (manualMode) {
armLeft.setTargetPosition(armLeft.getCurrentPosition());
armRight.setTargetPosition(armRight.getCurrentPosition());
armLeft.setPower(1.0);
armRight.setPower(1.0);
armLeft.setMode(DcMotor.RunMode.RUN_TO_POSITION);
armRight.setMode(DcMotor.RunMode.RUN_TO_POSITION);
manualMode = false;
}
//preset buttons
if (gamepad1.a) {
armLeft.setTargetPosition(armHomePosition);
armRight.setTargetPosition(armHomePosition);
armLeft.setPower(1.0);
armRight.setPower(1.0);
armLeft.setMode(DcMotor.RunMode.RUN_TO_POSITION);
armRight.setMode(DcMotor.RunMode.RUN_TO_POSITION);
wrist.setPosition(wristUpPosition);
}
else if (gamepad1.b) {
armLeft.setTargetPosition(armIntakePosition);
armRight.setTargetPosition(armIntakePosition);
armLeft.setPower(1.0);
armRight.setPower(1.0);
armLeft.setMode(DcMotor.RunMode.RUN_TO_POSITION);
armRight.setMode(DcMotor.RunMode.RUN_TO_POSITION);
wrist.setPosition(wristDownPosition);
}
else if (gamepad1.y) {
armLeft.setTargetPosition(armScorePosition);
armRight.setTargetPosition(armScorePosition);
armLeft.setPower(1.0);
armRight.setPower(1.0);
armLeft.setMode(DcMotor.RunMode.RUN_TO_POSITION);
armRight.setMode(DcMotor.RunMode.RUN_TO_POSITION);
wrist.setPosition(wristUpPosition);
}
}
//Re-zero encoder button
if (gamepad1.start) {
armLeft.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
armRight.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
armLeft.setPower(0.0);
armRight.setPower(0.0);
manualMode = false;
}
//Watchdog to shut down motor once the arm reaches the home position
if (!manualMode &&
armLeft.getMode() == DcMotor.RunMode.RUN_TO_POSITION &&
armLeft.getTargetPosition() <= armShutdownThreshold &&
armLeft.getCurrentPosition() <= armShutdownThreshold
) {
armLeft.setPower(0.0);
armRight.setPower(0.0);
armLeft.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
armRight.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
}
//GRIPPER
if (gamepad1.left_bumper || gamepad1.right_bumper) {
gripper.setPosition(gripperOpenPosition);
}
else {
gripper.setPosition(gripperClosedPosition);
}
telemetry.addData("Status", "Run Time: " + runtime.toString());
telemetry.addData("Gamepad", "drive (%.2f), turn (%.2f)", drive, turn);
telemetry.addData("Motors", "left (%.2f), right (%.2f)", leftPower, rightPower);
telemetry.addData("Manual Power", manualArmPower);
telemetry.addData("Arm Pos:",
"left = " +
((Integer)armLeft.getCurrentPosition()).toString() +
", right = " +
((Integer)armRight.getCurrentPosition()).toString());
telemetry.addData("Arm Pos:",
"left = " +
((Integer)armLeft.getTargetPosition()).toString() +
", right = " +
((Integer)armRight.getTargetPosition()).toString());
}
/*
* Code to run ONCE after the driver hits STOP
*/
@Override
public void stop() {
}
} 











