forked from FIRST-Tech-Challenge/FtcRobotController
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
303 additions
and
0 deletions.
There are no files selected for viewing
303 changes: 303 additions & 0 deletions
303
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/auton_red
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,303 @@ | ||
package org.firstinspires.ftc.teamcode; | ||
|
||
import com.qualcomm.robotcore.eventloop.opmode.Autonomous; | ||
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; | ||
import com.qualcomm.robotcore.hardware.DcMotor; | ||
import com.qualcomm.robotcore.hardware.DcMotorController; | ||
import com.qualcomm.robotcore.hardware.DcMotorSimple; | ||
import com.qualcomm.robotcore.hardware.Servo; | ||
import com.qualcomm.robotcore.util.ElapsedTime; | ||
import com.qualcomm.robotcore.util.Range; | ||
|
||
|
||
//version 1 of team taro's autonomous code. | ||
|
||
@Autonomous(name="auton_red", group="Linear OpMode") | ||
|
||
public class auton_red extends LinearOpMode{ | ||
|
||
private ElapsedTime runtime = new ElapsedTime(); | ||
|
||
private DcMotor fldrive, frdrive, bldrive, brdrive, carousel; | ||
|
||
|
||
public void runOpMode() throws InterruptedException { | ||
telemetry.addData("Status", "Intialized"); | ||
telemetry.update(); | ||
|
||
fldrive = hardwareMap.get(DcMotor.class, "fldrive"); | ||
frdrive = hardwareMap.get(DcMotor.class, "frdrive"); | ||
brdrive = hardwareMap.get(DcMotor.class, "brdrive"); | ||
bldrive = hardwareMap.get(DcMotor.class, "bldrive"); | ||
carousel = hardwareMap.get(DcMotor.class, "carousel"); | ||
|
||
fldrive.setDirection(DcMotor.Direction.FORWARD); | ||
frdrive.setDirection(DcMotor.Direction.REVERSE); | ||
brdrive.setDirection(DcMotor.Direction.REVERSE); | ||
bldrive.setDirection(DcMotor.Direction.FORWARD); | ||
carousel.setDirection(DcMotor.Direction.REVERSE); | ||
|
||
waitForStart(); | ||
runtime.reset(); | ||
|
||
//write code here using functions | ||
//forward(0.1, 2000); | ||
//straferight(1, 3000); | ||
|
||
strafelefttime(0.5, 300); | ||
lefttime(0.1, 200); | ||
carousel(0.5, 2000); | ||
forwardtime(0.3, 4000); | ||
|
||
} | ||
|
||
public void carousel(double power, long time) throws InterruptedException | ||
{ | ||
carousel.setPower(power); | ||
Thread.sleep(time); | ||
} | ||
|
||
public void forwardtime(double power, long time) throws InterruptedException | ||
{ | ||
fldrive.setPower(power); | ||
frdrive.setPower(power); | ||
brdrive.setPower(power); | ||
bldrive.setPower(power); | ||
Thread.sleep(time); | ||
} | ||
|
||
public void backwardtime(double power, long time) throws InterruptedException | ||
{ | ||
fldrive.setPower(-power); | ||
frdrive.setPower(-power); | ||
brdrive.setPower(-power); | ||
bldrive.setPower(-power); | ||
Thread.sleep(time); | ||
} | ||
|
||
public void lefttime(double power, long time) throws InterruptedException | ||
{ | ||
fldrive.setPower(-power); | ||
frdrive.setPower(power); | ||
brdrive.setPower(power); | ||
bldrive.setPower(-power); | ||
Thread.sleep(time); | ||
} | ||
|
||
public void righttime(double power, long time) throws InterruptedException | ||
{ | ||
fldrive.setPower(power); | ||
frdrive.setPower(-power); | ||
brdrive.setPower(-power); | ||
bldrive.setPower(power); | ||
Thread.sleep(time); | ||
} | ||
|
||
public void strafelefttime(double power, long time) throws InterruptedException | ||
{ | ||
fldrive.setPower(-power); | ||
frdrive.setPower(power); | ||
brdrive.setPower(-power); | ||
bldrive.setPower(power); | ||
Thread.sleep(time); | ||
} | ||
|
||
public void straferighttime(double power, long time) throws InterruptedException | ||
{ | ||
fldrive.setPower(power); | ||
frdrive.setPower(-power); | ||
brdrive.setPower(power); | ||
bldrive.setPower(-power); | ||
Thread.sleep(time); | ||
} | ||
|
||
public void forward(double power, int distance) { | ||
fldrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
frdrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
bldrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
brdrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
|
||
fldrive.setTargetPosition(distance); | ||
frdrive.setTargetPosition(distance); | ||
bldrive.setTargetPosition(distance); | ||
brdrive.setTargetPosition(distance); | ||
|
||
fldrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
frdrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
bldrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
brdrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
|
||
fldrive.setPower(power); | ||
frdrive.setPower(power); | ||
brdrive.setPower(power); | ||
bldrive.setPower(power); | ||
|
||
while (fldrive.isBusy() && frdrive.isBusy() && bldrive.isBusy() && brdrive.isBusy()) { | ||
//until point reached | ||
} | ||
|
||
power = 0.0; | ||
fldrive.setPower(power); | ||
frdrive.setPower(power); | ||
brdrive.setPower(power); | ||
bldrive.setPower(power); | ||
} | ||
|
||
public void backward(double power, int distance) { | ||
fldrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
frdrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
bldrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
brdrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
|
||
fldrive.setTargetPosition(-distance); | ||
frdrive.setTargetPosition(-distance); | ||
bldrive.setTargetPosition(-distance); | ||
brdrive.setTargetPosition(-distance); | ||
|
||
fldrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
frdrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
bldrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
brdrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
|
||
fldrive.setPower(-power); | ||
frdrive.setPower(-power); | ||
brdrive.setPower(-power); | ||
bldrive.setPower(-power); | ||
|
||
while (fldrive.isBusy() && frdrive.isBusy() && bldrive.isBusy() && brdrive.isBusy()) { | ||
//until point reached | ||
} | ||
|
||
power = 0.0; | ||
fldrive.setPower(-power); | ||
frdrive.setPower(-power); | ||
brdrive.setPower(-power); | ||
bldrive.setPower(-power); | ||
} | ||
|
||
public void left(double power, int distance) { | ||
fldrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
frdrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
bldrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
brdrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
|
||
fldrive.setTargetPosition(-distance); | ||
frdrive.setTargetPosition(distance); | ||
bldrive.setTargetPosition(distance); | ||
brdrive.setTargetPosition(-distance); | ||
|
||
fldrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
frdrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
bldrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
brdrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
|
||
fldrive.setPower(-power); | ||
frdrive.setPower(power); | ||
brdrive.setPower(power); | ||
bldrive.setPower(-power); | ||
|
||
while (fldrive.isBusy() && frdrive.isBusy() && bldrive.isBusy() && brdrive.isBusy()) { | ||
//until point reached | ||
} | ||
|
||
power = 0.0; | ||
fldrive.setPower(power); | ||
frdrive.setPower(power); | ||
brdrive.setPower(power); | ||
bldrive.setPower(power); | ||
} | ||
|
||
public void right(double power, int distance) { | ||
fldrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
frdrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
bldrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
brdrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
|
||
fldrive.setTargetPosition(distance); | ||
frdrive.setTargetPosition(-distance); | ||
bldrive.setTargetPosition(-distance); | ||
brdrive.setTargetPosition(distance); | ||
|
||
fldrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
frdrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
bldrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
brdrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
|
||
fldrive.setPower(power); | ||
frdrive.setPower(-power); | ||
brdrive.setPower(-power); | ||
bldrive.setPower(power); | ||
|
||
while (fldrive.isBusy() && frdrive.isBusy() && bldrive.isBusy() && brdrive.isBusy()) { | ||
//until point reached | ||
} | ||
|
||
power = 0.0; | ||
fldrive.setPower(-power); | ||
frdrive.setPower(-power); | ||
brdrive.setPower(-power); | ||
bldrive.setPower(-power); | ||
} | ||
public void strafeleft(double power, int distance) { | ||
fldrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
frdrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
bldrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
brdrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
|
||
fldrive.setTargetPosition(-distance); | ||
frdrive.setTargetPosition(distance); | ||
bldrive.setTargetPosition(-distance); | ||
brdrive.setTargetPosition(distance); | ||
|
||
fldrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
frdrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
bldrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
brdrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
|
||
fldrive.setPower(-power); | ||
frdrive.setPower(power); | ||
brdrive.setPower(-power); | ||
bldrive.setPower(power); | ||
|
||
while (fldrive.isBusy() && frdrive.isBusy() && bldrive.isBusy() && brdrive.isBusy()) { | ||
//until point reached | ||
} | ||
|
||
power = 0.0; | ||
fldrive.setPower(power); | ||
frdrive.setPower(power); | ||
brdrive.setPower(power); | ||
bldrive.setPower(power); | ||
} | ||
public void straferight(double power, int distance) { | ||
fldrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
frdrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
bldrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
brdrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
|
||
fldrive.setTargetPosition(distance); | ||
frdrive.setTargetPosition(-distance); | ||
bldrive.setTargetPosition(distance); | ||
brdrive.setTargetPosition(-distance); | ||
|
||
fldrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
frdrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
bldrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
brdrive.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
|
||
fldrive.setPower(power); | ||
frdrive.setPower(-power); | ||
brdrive.setPower(power); | ||
bldrive.setPower(-power); | ||
|
||
while (fldrive.isBusy() && frdrive.isBusy() && bldrive.isBusy() && brdrive.isBusy()) { | ||
//until point reached | ||
} | ||
|
||
power = 0.0; | ||
fldrive.setPower(power); | ||
frdrive.setPower(power); | ||
brdrive.setPower(power); | ||
bldrive.setPower(power); | ||
} | ||
} |