SHARE
TWEET

TELEOP Code

a guest Jan 7th, 2017 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Copyright (c) 2016 Robert Atkinson
  3.  
  4. All rights reserved.
  5.  
  6. Redistribution and use in source and binary forms, with or without modification,
  7. are permitted (subject to the limitations in the disclaimer below) provided that
  8. the following conditions are met:
  9.  
  10. Redistributions of source code must retain the above copyright notice, this list
  11. of conditions and the following disclaimer.
  12.  
  13. Redistributions in binary form must reproduce the above copyright notice, this
  14. list of conditions and the following disclaimer in the documentation and/or
  15. other materials provided with the distribution.
  16.  
  17. Neither the name of Robert Atkinson nor the names of his contributors may be used to
  18. endorse or promote products derived from this software without specific prior
  19. written permission.
  20.  
  21. NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS
  22. LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  24. THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESSFOR A PARTICULAR PURPOSE
  25. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  26. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  30. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  31. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. package org.firstinspires.ftc.teamcode;
  34.  
  35. import com.qualcomm.robotcore.eventloop.opmode.Disabled;
  36. import com.qualcomm.robotcore.eventloop.opmode.OpMode;
  37. import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
  38. import com.qualcomm.robotcore.util.ElapsedTime;
  39. import org.firstinspires.ftc.teamcode.direction;
  40. @TeleOp(name="Telebop", group="Iterative Opmode")  // @Autonomous(...) is the other common choice
  41. //@Disabled
  42. public class TELEBOP extends OpMode
  43. {
  44.     /* Declare OpMode members. */
  45.     private ElapsedTime runtime = new ElapsedTime();
  46.     Bot robot;
  47.  
  48.     public TELEBOP()
  49.     {
  50.         robot = new Bot();
  51.     }
  52.  
  53.     /*
  54.      * Code to run ONCE when the driver hits INIT
  55.      */
  56.     @Override
  57.     public void init()
  58.     {
  59.         telemetry.addData("Status", "Initialized");
  60.         robot.init(hardwareMap);
  61.         telemetry.addData("Status", "Initialized");
  62.     }
  63.  
  64.     /*
  65.      * Code to run REPEATEDLY after the driver hits INIT, but before they hit PLAY
  66.      */
  67.     @Override
  68.     public void init_loop() {}
  69.  
  70.     /*
  71.      * Code to run ONCE when the driver hits PLAY
  72.      */
  73.     @Override
  74.     public void start()
  75.     {
  76.         runtime.reset();
  77.         robot.resetCurrentTime();
  78.     }
  79.  
  80.     /*
  81.      * Code to run REPEATEDLY after the driver hits PLAY but before they hit STOP
  82.      */
  83.     @Override
  84.     public void loop()
  85.     {
  86.         telemetry.addData("Status", "Running: " + runtime.toString());
  87.  
  88.        
  89.         if (gamepad1.y) {
  90.             robot.drive(direction.FOR, 1);
  91.             telemetry.addData("Drive Mode", 0);
  92.         } else if (gamepad1.x) {
  93.             robot.drive(direction.BACK, 1);
  94.             telemetry.addData("Drive Mode", 1);
  95.         } else if (gamepad1.a) {
  96.             robot.drive(direction.LEFT, 1);
  97.             telemetry.addData("Drive Mode", 2);
  98.         } else if (gamepad1.b) {
  99.             robot.drive(direction.RIGHT, 1);
  100.             telemetry.addData("Drive Mode", 3);
  101.         } else if (gamepad1.right_trigger > 0) {
  102.             robot.drive(direction.TURNL, 1);
  103.             telemetry.addData("Drive Mode", 4);
  104.         } else if (gamepad1.left_trigger > 0) {
  105.             robot.drive(direction.TURNR, 1);
  106.             telemetry.addData("Drive Mode", 5);
  107.         } else {
  108.             robot.drive(direction.FOR, 0);
  109.            
  110.             telemetry.addData("Drive Mode", 6);
  111.         }
  112.        
  113.         telemetry.update();
  114.     }
  115.  
  116.     /*
  117.      * Code to run ONCE after the driver hits STOP
  118.      */
  119.     @Override
  120.     public void stop() {}
  121.  
  122. }
RAW Paste Data
Top