Guest User

Untitled

a guest
Feb 16th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. package org.firstinspires.ftc.teamcode;
  2.  
  3.  
  4. import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
  5. import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
  6. import com.qualcomm.robotcore.hardware.DcMotor;
  7. import com.qualcomm.robotcore.hardware.Servo;
  8.  
  9. /**
  10. *Autonomous program for Swerve Robotics tutorial
  11. */
  12.  
  13. @Autonomous(name = "AutoBlueBack", group = "Autonomous")
  14.  
  15.  
  16. public class AutoBlueBack extends LinearOpMode {
  17. //declare motors
  18. DcMotor motorLeft = null;
  19. DcMotor motorRight = null;
  20.  
  21. DcMotor armLeft = null;
  22. DcMotor armRight = null;
  23.  
  24. DcMotor pullLeft = null;
  25. DcMotor pullRight = null;
  26.  
  27. //declare servo
  28. Servo collector = null;
  29.  
  30.  
  31. @Override
  32. public void runOpMode() throws InterruptedException {
  33. /* initialize our hardware variables. Note that the strings used here as parameters
  34. * to 'get' must correspond to the name you assigned during the robot configuration
  35. * step you did in the FTC Robot Controller app on the phone
  36. */
  37.  
  38. //initialize motors
  39. motorLeft = hardwareMap.dcMotor.get("motorLeft");
  40. motorRight = hardwareMap.dcMotor.get("motorRight");
  41.  
  42. motorLeft.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
  43. motorRight.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
  44.  
  45. motorLeft.setDirection(DcMotor.Direction.REVERSE);
  46. motorRight.setDirection(DcMotor.Direction.FORWARD);
  47.  
  48.  
  49. //wait for the game to start
  50. waitForStart();
  51.  
  52. DriveBackwards(DRIVE_POWER, 500);
  53.  
  54. TurnLeftTime(DRIVE_POWER, 2000);
  55.  
  56. DriveFowardTime(DRIVE_POWER, 2000);
  57.  
  58. TurnLeftTime(DRIVE_POWER, 1000);
  59.  
  60.  
  61. DriveFowardTime(DRIVE_POWER, 3000);
  62.  
  63.  
  64. //finish the objective and stop
  65. StopDriving();
  66.  
  67.  
  68. }
  69.  
  70. //make "method" for functions
  71.  
  72. double DRIVE_POWER = 1.0;
  73.  
  74. public void DriveForward(double power) {
  75. motorLeft.setPower(0.4);
  76. motorRight.setPower(0.4);
  77. }
  78.  
  79. public void DriveFowardTime(double power, long time) throws InterruptedException {
  80. DriveForward(0.4);
  81. Thread.sleep(2000);
  82. }
  83.  
  84. public void DriveBackwards(double power) {
  85. motorLeft.setPower(-0.4);
  86. motorRight.setPower(-0.4);
  87. }
  88.  
  89. public void DriveBackwards(double power, long time) throws InterruptedException {
  90. DriveBackwards(0.4);
  91. Thread.sleep(3000);
  92. }
  93.  
  94. public void StopDriving() {
  95. DriveForward(0);
  96. }
  97.  
  98. public void TurnLeft(double power) {
  99. motorLeft.setPower(-0.4);
  100. motorRight.setPower(0.4);
  101. }
  102.  
  103. public void TurnLeftTime(double power, long time) throws InterruptedException {
  104. TurnLeft(0.4);
  105. Thread.sleep(2000);
  106. }
  107.  
  108. public void TurnRight(double power) {
  109. TurnLeft(-0.4);
  110. }
  111.  
  112. public void TurnRightTime(double power, long time) throws InterruptedException {
  113. TurnRight(0.4);
  114. Thread.sleep(2000);
  115. }
  116.  
  117.  
  118. }
Add Comment
Please, Sign In to add comment