This file contains an minimal example of a Linear "OpMode". An OpMode is a 'program' that runs in either
the autonomous or the teleop period of an FTC match. The names of OpModes appear on the menu
of the FTC Driver Station. When an selection is made from the menu, the corresponding OpMode
class is instantiated on the Robot Controller and executed.
This particular OpMode just executes a basic Tank Drive Teleop for a two wheeled robot
It includes all the skeletal structure that all linear OpModes contain.
Use Android Studios to Copy this Class, and Paste it into your team's code folder with a new name.
0 Remove or comment out the @Disabled line to add this opmode to the Driver Station OpMode list
/
@TeleOp(name="ftc_teleop", group="Linear Opmode")
//@Disabled
public class ftc_teleop extends LinearOpMode {
@Override
public void runOpMode() {
telemetry.addData("Status", "Initialized");
telemetry.update();
// Initialize the hardware variables. Note that the strings used here as parameters
// to 'get' must correspond to the names assigned during the robot configuration
// step (using the FTC Robot Controller app on the phone).
servo = hardwareMap.servo.get("servo");
servo.setPosition(servoPosition);
// Initialize the hardware variables. Note that the strings used here as parameters
leftfront = hardwareMap.get(DcMotor.class, "leftfront");
rightfront = hardwareMap.get(DcMotor.class, "rightfront");
rightback = hardwareMap.get(DcMotor.class, "rightback");
leftback = hardwareMap.get(DcMotor.class, "leftback");
// Arm = hardwareMap.get(DcMotor.class, "Arm");
// boxmotor = hardwareMap.get(Servo.class, "boxmotor");
// Most robots need the motor on one side to be reversed to drive forward
// Reverse the motor that runs backwards when connected directly to the battery
leftfront.setDirection(DcMotor.Direction.FORWARD);
rightfront.setDirection(DcMotor.Direction.REVERSE);
leftback.setDirection(DcMotor.Direction.FORWARD);
//Arm.setDirection(DcMotor.Direction.FORWARD);
rightback.setDirection(DcMotor.Direction.REVERSE);
// Wait for the game to start (driver presses PLAY)
waitForStart();
runtime.reset();
// run until the end of the match (driver presses STOP)
while (opModeIsActive()) {
// Setup a variable for each drive wheel to save power level for telemetry
double leftPower;
double rightPower;
// Choose to drive using either Tank Mode, or POV Mode
// Comment out the method that's not used. The default below is POV.
// POV Mode uses left stick to go forward, and right stick to turn.
// - This uses basic math to combine motions and is easier to drive straight.
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) ;
double leftteleop = -gamepad1.left_trigger;
double rightteleop = -gamepad1.right_trigger;
// Tank Mode uses one stick to control each wheel.
// - This requires no math, but it is hard to drive forward slowly and keep straight.
// leftPower = -gamepad1.left_stick_y ;
// rightPower = -gamepad1.right_stick_y ;
// Send calculated power to wheels
leftfront.setPower(leftPower);
rightfront.setPower(rightPower);
leftback.setPower(leftPower);
rightfront.setPower(rightPower);
// Show the elapsed game time and wheel power.
telemetry.addData("Status", "Run Time: " + runtime.toString());
telemetry.addData("Motors", "left (%.2f), right (%.2f)", leftPower, rightPower);
telemetry.update();
}
/ Copyright (c) 2017 FIRST. All rights reserved.
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous; import com.qualcomm.robotcore.eventloop.opmode.Disabled; import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; import com.qualcomm.robotcore.eventloop.opmode.TeleOp; import com.qualcomm.robotcore.hardware.DcMotor; import com.qualcomm.robotcore.hardware.Servo; import com.qualcomm.robotcore.util.ElapsedTime; import com.qualcomm.robotcore.util.Range;
/**
@TeleOp(name="ftc_teleop", group="Linear Opmode") //@Disabled public class ftc_teleop extends LinearOpMode {
private ElapsedTime runtime = new ElapsedTime(); private DcMotor leftfront = null; private DcMotor rightfront = null; private DcMotor leftback = null; //private DcMotor Arm = null; private DcMotor rightback = null;
private double drivepower = 0.0; private double right = 0.0; private double left = 0.0;
Servo servo; double servoPosition = 0.4; // Start at halfway position boolean rampUp = true;
double rightteleop; double leftteleop;
private void lateralmovement() { leftfront.setPower(drivepower); rightfront.setPower(drivepower); rightback.setPower(drivepower); leftback.setPower(drivepower); }
private void lateralright() { leftfront.setPower(rightteleop); rightfront.setPower(-rightteleop); rightback.setPower(rightteleop); leftback.setPower(-rightteleop); }
private void lateralleft() { leftfront.setPower(-leftteleop); rightfront.setPower(leftteleop); rightback.setPower(-leftteleop); leftback.setPower(leftteleop); }
@Override public void runOpMode() { telemetry.addData("Status", "Initialized"); telemetry.update();
} }