Guest User

Untitled

a guest
Feb 16th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. package org.firstinspires.ftc.teamcode;
  2.  
  3. import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
  4. import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
  5. import com.qualcomm.robotcore.hardware.DcMotor;
  6. import com.qualcomm.robotcore.hardware.Servo;
  7.  
  8. /**
  9. *Autonomous program for Swerve Robotics tutorial
  10. */
  11.  
  12. @Autonomous(name = "AutoBlueFront", group = "Autonomous")
  13.  
  14.  
  15. public class AutoBlueFront extends LinearOpMode
  16. {
  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 public void runOpMode () throws InterruptedException
  32. {
  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.  
  50.  
  51.  
  52. //wait for the game to start
  53. waitForStart ();
  54.  
  55. DriveBackwards(DRIVE_POWER,2000);
  56.  
  57. TurnLeftTime(DRIVE_POWER,900);
  58.  
  59. DriveFowardTime(DRIVE_POWER,12000);
  60.  
  61.  
  62. //finish the objective and stop
  63. StopDriving();
  64.  
  65.  
  66.  
  67. }
  68.  
  69. //make "method" for functions
  70.  
  71. double DRIVE_POWER = 1.0;
  72.  
  73. public void DriveForward (double power)
  74. {
  75. motorLeft.setPower(0.6);
  76. motorRight.setPower(0.6);
  77. }
  78.  
  79. public void DriveFowardTime (double power, long time) throws InterruptedException
  80. {
  81. DriveForward(0.75);
  82. Thread.sleep(2000);
  83. }
  84.  
  85. public void DriveBackwards (double power) {
  86. motorLeft.setPower(-0.6);
  87. motorRight.setPower(-0.6);
  88. }
  89. public void DriveBackwards (double power, long time) throws InterruptedException
  90. {
  91. DriveBackwards(0.6);
  92. Thread.sleep(1000);
  93. }
  94.  
  95. public void StopDriving ()
  96. {
  97. DriveForward(0);
  98. }
  99.  
  100. public void TurnLeft (double power)
  101. {
  102. motorLeft.setPower(-0.6);
  103. motorRight.setPower(0.6);
  104. }
  105.  
  106. public void TurnLeftTime (double power, long time) throws InterruptedException
  107. {
  108. TurnLeft(0.4);
  109. Thread.sleep(2000);
  110. }
  111.  
  112. public void TurnRight (double power)
  113. {
  114. TurnLeft(-0.6);
  115. }
  116.  
  117. public void TurnRightTime (double power, long time) throws InterruptedException
  118. {
  119. TurnRight(0.6);
  120. Thread.sleep(2000);
  121. }
  122.  
  123.  
  124.  
  125.  
  126.  
  127. }
Add Comment
Please, Sign In to add comment