SHARE
TWEET

Untitled

a guest Jun 19th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Copyright (c) 2017 FIRST. All rights reserved.
  2.  *
  3.  * Redistribution and use in source and binary forms, with or without modification,
  4.  * are permitted (subject to the limitations in the disclaimer below) provided that
  5.  * the following conditions are met:
  6.  *
  7.  * Redistributions of source code must retain the above copyright notice, this list
  8.  * of conditions and the following disclaimer.
  9.  *
  10.  * Redistributions in binary form must reproduce the above copyright notice, this
  11.  * list of conditions and the following disclaimer in the documentation and/or
  12.  * other materials provided with the distribution.
  13.  *
  14.  * Neither the name of FIRST nor the names of its contributors may be used to endorse or
  15.  * promote products derived from this software without specific prior written permission.
  16.  *
  17.  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS
  18.  * LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  20.  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  22.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  24.  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  25.  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28.  */
  29.  
  30. package org.firstinspires.ftc.teamcode;
  31.  
  32. import com.qualcomm.robotcore.eventloop.opmode.Disabled;
  33. import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
  34. import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
  35. import com.qualcomm.robotcore.hardware.DcMotor;
  36. import com.qualcomm.robotcore.hardware.DcMotorSimple;
  37. import com.qualcomm.robotcore.util.ElapsedTime;
  38. import com.qualcomm.robotcore.util.Range;
  39.  
  40.  
  41. /**
  42.  * This file contains an minimal example of a Linear "OpMode". An OpMode is a 'program' that runs in either
  43.  * the autonomous or the teleop period of an FTC match. The names of OpModes appear on the menu
  44.  * of the FTC Driver Station. When an selection is made from the menu, the corresponding OpMode
  45.  * class is instantiated on the Robot Controller and executed.
  46.  *
  47.  * This particular OpMode just executes a basic Tank Drive Teleop for a two wheeled robot
  48.  * It includes all the skeletal structure that all linear OpModes contain.
  49.  *
  50.  * Use Android Studios to Copy this Class, and Paste it into your team's code folder with a new name.
  51.  * Remove or comment out the @Disabled line to add this opmode to the Driver Station OpMode list
  52.  */
  53.  
  54. @TeleOp(name="Basic: Linear OpMode", group="Linear Opmode")
  55. public class BasicOpMode_Linear extends LinearOpMode {
  56.  
  57.     // Declare OpMode members.
  58.     private ElapsedTime runtime = new ElapsedTime();
  59.     private DcMotor FrontLeft = null;
  60.     private DcMotor FrontRight = null;
  61.     private DcMotor BackLeft = null;
  62.     private DcMotor BackRight = null;
  63.  
  64.     @Override
  65.     public void runOpMode() {
  66.         telemetry.addData("Status", "Initialized");
  67.         telemetry.update();
  68.  
  69.         // Initialize the hardware variables. Note that the strings used here as parameters
  70.         // to 'get' must correspond to the names assigned during the robot configuration
  71.         // step (using the FTC Robot Controller app on the phone).
  72.         FrontLeft = hardwareMap.get(DcMotor.class, "fl");
  73.         FrontRight = hardwareMap.get(DcMotor.class, "fr");
  74.         BackRight = hardwareMap.get(DcMotor.class, "br");
  75.         BackLeft = hardwareMap.get(DcMotor.class, "bl");
  76.         // Most robots need the motor on one side to be reversed to drive forward
  77.         // Reverse the motor that runs backwards when connected directly to the battery
  78.         FrontRight.setDirection(DcMotor.Direction.FORWARD);
  79.         FrontLeft.setDirection(DcMotor.Direction.REVERSE);
  80.         BackLeft.setDirection(DcMotor.Direction.REVERSE);
  81.         BackRight.setDirection(DcMotor.Direction.FORWARD);
  82.  
  83.         // Wait for the game to start (driver presses PLAY)
  84.         waitForStart();
  85.         runtime.reset();
  86.  
  87.         // run until the end of the match (driver presses STOP)
  88.         while (opModeIsActive()) {
  89.  
  90.             if (gamepad1.y) {
  91.                 FrontLeft.setPower(1.0);
  92.                 FrontRight.setPower(1.0);
  93.                 BackRight.setPower(1.0);
  94.                 BackLeft.setPower(1.0);
  95.  
  96.  
  97.             } else {
  98.  
  99.                 FrontLeft.setPower(0);
  100.                 FrontRight.setPower(0);
  101.                 BackRight.setPower(0);
  102.                 BackLeft.setPower(0);
  103.             }
  104.  
  105.  
  106.             if (gamepad1.a) {
  107.  
  108.                 FrontLeft.setPower(-1.0);
  109.                 FrontRight.setPower(-1.0);
  110.                 BackRight.setPower(-1.0);
  111.                 BackLeft.setPower(-1.0);
  112.             } else {
  113.                 FrontLeft.setPower(0);
  114.                 FrontRight.setPower(0);
  115.                 BackRight.setPower(0);
  116.                 BackLeft.setPower(0);
  117.             }
  118.             if (gamepad1.x) {
  119.                 FrontLeft.setPower(-1.0);
  120.                 FrontRight.setPower(1.0);
  121.                 BackRight.setPower(-1.0);
  122.                 BackLeft.setPower(1.0);
  123.             } else {
  124.                 FrontLeft.setPower(0);
  125.                 FrontRight.setPower(0);
  126.                 BackRight.setPower(0);
  127.                 BackLeft.setPower(0);
  128.             }
  129.             if (gamepad1.b) {
  130.                 FrontLeft.setPower(1.0);
  131.                 FrontRight.setPower(-1.0);
  132.                 BackRight.setPower(1.0);
  133.                 BackLeft.setPower(-1.0);
  134.             } else {
  135.                 FrontLeft.setPower(0);
  136.                 FrontRight.setPower(0);
  137.                 BackRight.setPower(0);
  138.                 BackLeft.setPower(0);
  139.             }
  140.  
  141.  
  142.             // Show the elapsed game time and wheel power.
  143.             telemetry.addData("Status", "Run Time: " + runtime.toString());
  144.             telemetry.addData("Motors", "left (%.2f), right (%.2f)", FrontLeft, FrontRight);
  145.             telemetry.update();
  146.         }
  147.     }
  148. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top