Advertisement
Faerie-

FTCcode3

Jan 20th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.45 KB | None | 0 0
  1. package org.usfirst.ftc.exampleteam.yourcodehere;
  2.  
  3. import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
  4. import com.qualcomm.robotcore.hardware.DcMotor;
  5. import com.qualcomm.robotcore.hardware.Servo;
  6.  
  7. import org.swerverobotics.library.SynchronousOpMode;
  8.  
  9. /**
  10. * A skeletal example of a do-nothing first OpMode. Go ahead and change this code
  11. * to suit your needs, or create sibling OpModes adjacent to this one in the same
  12. * Java package.
  13. */
  14. @TeleOp(name = "My First OpMode")
  15. public class MyFirstOpMode extends SynchronousOpMode {
  16. /* Declare here any fields you might find useful. */
  17. public DcMotor motorLeft = null;
  18. public DcMotor motorRight = null;
  19. public DcMotor slide2 = null;
  20.  
  21.  
  22. public Servo pusher = null;
  23. public Servo P1 = null;
  24. public Servo P2 = null;
  25. public DcMotor carry = null;
  26. public Servo buttonPusher = null;
  27. @Override
  28. public void main() throws InterruptedException {
  29. /* Initialize our hardware variables. Note that the strings used here as parameters
  30. * to 'get' must correspond to the names you assigned during the robot configuration
  31. * step you did in the FTC Robot Controller app on the phone.
  32. */
  33. motorLeft = this.hardwareMap.dcMotor.get("motorLeft");
  34. motorRight = this.hardwareMap.dcMotor.get("motorRight");
  35. pusher = hardwareMap.servo.get("pusher");
  36. slide2 = hardwareMap.dcMotor.get("slide2");
  37. P1 = hardwareMap.servo.get("P1");
  38. P2 = hardwareMap.servo.get("P2");
  39. carry = hardwareMap.dcMotor.get("carry");
  40. buttonPusher = hardwareMap.servo.get("buttonPusher");
  41. motorRight.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
  42. motorLeft.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
  43. slide2.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
  44. carry.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
  45. boolean direction = true;
  46. double powerM = 5.5;
  47. double powerRight = 0;
  48. double powerLeft = 0;
  49. boolean pusherIn = true;
  50. waitForStart();
  51.  
  52. // Go go gadget robot!
  53. while (opModeIsActive()) {
  54.  
  55. if (updateGamepads()) {
  56.  
  57. if (gamepad1.a){
  58. direction = !direction;
  59. }
  60.  
  61. if (gamepad1.y){
  62. powerM = .55;
  63. }
  64. if (gamepad1.x){
  65. powerM = .2;
  66. }
  67.  
  68.  
  69. powerLeft = gamepad1.left_stick_y;
  70. powerRight = gamepad1.right_stick_y;
  71.  
  72. //reverse direction
  73. if (direction){
  74. this.motorLeft.setPower(powerLeft * powerM);
  75. this.motorRight.setPower(-powerRight * powerM);
  76. }
  77. else {
  78. this.motorLeft.setPower(-powerRight * powerM);
  79. this.motorRight.setPower(powerLeft * powerM);
  80. }
  81.  
  82.  
  83. // pusher
  84. if (gamepad1.dpad_up) {
  85. pusher.setPosition(100);
  86. }
  87. else if (gamepad1.dpad_down) {
  88. pusher.setPosition(0.5);
  89. }
  90.  
  91. //buttonPusher
  92. if (gamepad1.b){
  93. if (pusherIn){
  94. buttonPusher.setPosition(0.5);
  95. pusherIn = !pusherIn;
  96. }
  97. else{
  98. buttonPusher.setPosition(100);
  99. pusherIn = !pusherIn;
  100. }
  101. }
  102.  
  103. //higher slide bar
  104. if (gamepad2.left_bumper) {
  105. slide2.setPower(-15);
  106. } else if (gamepad2.left_trigger > 0) {
  107. slide2.setPower(15);
  108. } else {
  109. slide2.setPower(0);
  110. }
  111.  
  112. //pincers
  113. if(gamepad2.a){
  114. P1.setPosition(0);
  115. P2.setPosition(1);
  116. }
  117. if(gamepad2.b){
  118. P1.setPosition(1);
  119. P2.setPosition(0);
  120. }
  121. //lower pinser code
  122. if (gamepad2.dpad_down){
  123. carry.setPower(25);
  124. }
  125. else if (gamepad2.dpad_up){
  126. carry.setPower(-25);
  127. }
  128. else {
  129. carry.setPower(0);
  130. }
  131.  
  132. }
  133.  
  134. telemetry.update();
  135. idle();
  136. }
  137. }
  138. }
  139.  
  140.  
  141.  
  142. //auto
  143.  
  144.  
  145.  
  146. package org.usfirst.ftc.exampleteam.yourcodehere;
  147.  
  148. import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
  149. import com.qualcomm.robotcore.eventloop.opmode.Disabled;
  150. import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
  151. import com.qualcomm.robotcore.hardware.DcMotor;
  152. import com.qualcomm.robotcore.hardware.Servo;
  153.  
  154. import org.swerverobotics.library.SynchronousOpMode;
  155.  
  156. /**
  157. * A skeletal example of a do-nothing first OpMode. Go ahead and change this code
  158. * to suit your needs, or create sibling OpModes adjacent to this one in the same
  159. * Java package.
  160. */
  161. @Autonomous(name = "Auto")
  162.  
  163. public class Auto extends SynchronousOpMode {
  164. /* Declare here any fields you might find useful. */
  165. public DcMotor motorLeft = null;
  166. public DcMotor motorRight = null;
  167. public DcMotor slide1 = null;
  168. public DcMotor slide2 = null;
  169.  
  170.  
  171. public Servo pusher = null;
  172.  
  173. @Override
  174. public void main() throws InterruptedException {
  175. /* Initialize our hardware variables. Note that the strings used here as parameters
  176. * to 'get' must correspond to the names you assigned during the robot configuration
  177. * step you did in the FTC Robot Controller app on the phone.
  178. */
  179. motorLeft = this.hardwareMap.dcMotor.get("motorLeft");
  180. motorRight = this.hardwareMap.dcMotor.get("motorRight");
  181. pusher = hardwareMap.servo.get("pusher");
  182. slide2 = hardwareMap.dcMotor.get("slide2");
  183.  
  184.  
  185. motorRight.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
  186. motorLeft.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
  187. slide2.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
  188.  
  189. waitForStart();
  190.  
  191. // Go go gadget robot!
  192. motorLeft.setPower(-35);
  193. motorRight.setPower(35);
  194. Thread.sleep(2000);
  195. motorLeft.setPower(0);
  196. motorRight.setPower(0);
  197.  
  198. }
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement