Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.Servo;
- @Autonomous(name="Basic: Linear OpMode", group="Linear Opmode")
- //@Disabled
- public class MecanumAutonomous extends LinearOpMode {
- //Declare motors
- DcMotor fl; //Front left wheel
- DcMotor fr; //Front right wheel
- DcMotor bl; //Back left wheel
- DcMotor br; //Back right wheel
- //Declare servos
- Servo FoundationServo1;
- Servo FoundationServo2;
- //Methods for moving
- public void MoveForward(double power)
- {
- fl.setPower(power);
- fr.setPower(power);
- bl.setPower(power);
- br.setPower(power);
- }
- public void DriveForward(double power, int distance)
- {
- //Reset encoders
- fl.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- fr.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- bl.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- br.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- //Set target position
- fl.setTargetPosition(distance);
- fr.setTargetPosition(distance);
- bl.setTargetPosition(distance);
- br.setTargetPosition(distance);
- //Set mode to RUN_TO_POSITION
- fl.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- fr.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- bl.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- br.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- }
- public void DriveLeft(double power, int distance)
- {
- //Reset encoders
- fl.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- fr.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- bl.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- br.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- //Set target position
- fl.setTargetPosition(-distance);
- fr.setTargetPosition(distance);
- bl.setTargetPosition(distance);
- br.setTargetPosition(-distance);
- //Set mode to RUN_TO_POSITION
- fl.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- fr.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- bl.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- br.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- }
- public void DriveRight(double power, int distance)
- {
- //Reset encoders
- fl.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- fr.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- bl.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- br.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- //Set target position
- fl.setTargetPosition(distance);
- fr.setTargetPosition(-distance);
- bl.setTargetPosition(-distance);
- br.setTargetPosition(distance);
- //Set mode to RUN_TO_POSITION
- fl.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- fr.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- bl.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- br.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- }
- public void TurnLeft(double power, int distance)
- {
- //Reset encoders
- fl.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- fr.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- bl.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- br.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- //Set target position
- fl.setTargetPosition(-distance);
- fr.setTargetPosition(distance);
- bl.setTargetPosition(-distance);
- br.setTargetPosition(distance);
- //Set mode to RUN_TO_POSITION
- fl.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- fr.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- bl.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- br.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- }
- public void TurnRight(double power, int distance)
- {
- //Reset encoders
- fl.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- fr.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- bl.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- br.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
- //Set target position
- fl.setTargetPosition(distance);
- fr.setTargetPosition(-distance);
- bl.setTargetPosition(distance);
- br.setTargetPosition(-distance);
- //Set mode to RUN_TO_POSITION
- fl.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- fr.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- bl.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- br.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- }
- public void runOpMode() {
- //Initializing motors
- fl = hardwareMap.dcMotor.get("fl");
- fr = hardwareMap.dcMotor.get("fr");
- bl = hardwareMap.dcMotor.get("bl");
- br = hardwareMap.dcMotor.get("br");
- fl.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- fr.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- bl.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- br.setMode(DcMotor.RunMode.RUN_TO_POSITION);
- //Initializing servos
- FoundationServo1 = hardwareMap.servo.get("servo1");
- FoundationServo2 = hardwareMap.servo.get("servo2");
- FoundationServo1.setPosition(0);
- FoundationServo2.setPosition(0);
- //Miscellaneous
- //Wait for driver to press start
- waitForStart();
- //Steps go here
- DriveForward(50, 5);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement