Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.06 KB | None | 0 0
  1. package org.firstinspires.ftc.teamcode.BuildZone;
  2.  
  3. import android.app.Activity;
  4. import android.graphics.Color;
  5. import android.view.View;
  6.  
  7. import com.qualcomm.robotcore.eventloop.opmode.Disabled;
  8. import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
  9. import com.qualcomm.robotcore.hardware.ColorSensor;
  10. import com.qualcomm.robotcore.hardware.DistanceSensor;
  11.  
  12. import org.firstinspires.ftc.robotcore.external.navigation.DistanceUnit;
  13.  
  14. import java.util.Locale;
  15.  
  16. import com.qualcomm.hardware.bosch.BNO055IMU;
  17. import com.qualcomm.robotcore.eventloop.opmode.Disabled;
  18. import com.qualcomm.robotcore.hardware.Servo;
  19. import java.util.Iterator;
  20. import com.qualcomm.hardware.bosch.JustLoggingAccelerationIntegrator;
  21. import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
  22. import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
  23. import com.qualcomm.robotcore.hardware.DcMotor;
  24. import com.qualcomm.robotcore.hardware.DcMotorSimple;
  25.  
  26. import org.firstinspires.ftc.robotcore.external.navigation.Acceleration;
  27. import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
  28. import org.firstinspires.ftc.robotcore.external.navigation.AxesOrder;
  29. import org.firstinspires.ftc.robotcore.external.navigation.AxesReference;
  30. import org.firstinspires.ftc.robotcore.external.navigation.Orientation;
  31.  
  32. import org.firstinspires.ftc.teamcode.DriveClass;
  33.  
  34. @Autonomous(name="special sauce (blue)!", group="chad")
  35.  
  36. public class SpecialSauce_BLUE extends LinearOpMode {
  37. DriveClass dt;
  38. Servo found1, found2;
  39.  
  40. DcMotor intake1, intake2;
  41.  
  42. ColorSensor sensorColor;
  43. DistanceSensor sensorDistance;
  44.  
  45. public void runOpMode(){
  46. // get a reference to the color sensor.
  47. sensorColor = hardwareMap.get(ColorSensor.class, "colorSense");
  48. // get a reference to the distance sensor that shares the same name.
  49. sensorDistance = hardwareMap.get(DistanceSensor.class, "colorSense");
  50.  
  51. // hsvValues is an array that will hold the hue, saturation, and value information.
  52. float hsvValues[] = {0F, 0F, 0F};
  53.  
  54. // values is a reference to the hsvValues array.
  55. final float values[] = hsvValues;
  56.  
  57. // sometimes it helps to multiply the raw RGB values with a scale factor
  58. // to amplify/attentuate the measured values.
  59. final double SCALE_FACTOR = 255;
  60.  
  61. // get a reference to the RelativeLayout so we can change the background
  62. // color of the Robot Controller app to match the hue detected by the RGB sensor.
  63. int relativeLayoutId = hardwareMap.appContext.getResources().getIdentifier("RelativeLayout", "id", hardwareMap.appContext.getPackageName());
  64. final View relativeLayout = ((Activity) hardwareMap.appContext).findViewById(relativeLayoutId);
  65.  
  66. dt = new DriveClass(hardwareMap, this);
  67.  
  68. found1 = hardwareMap.get(Servo.class, "foundLeft");
  69. found2 = hardwareMap.get(Servo.class, "foundRight");
  70.  
  71. intake1 = hardwareMap.get(DcMotor.class, "intakeLeft");
  72. intake2 = hardwareMap.get(DcMotor.class, "intakeRight");
  73. /* SOME GOOD THINGS TO KNOW:
  74. 1. USE 0.2 POWER FOR TURNING
  75. 2. USE 0.5 POWER FOR FORWARDS / BACKWARDS
  76. 2. DON'T DELETE SHIT IF IT DOESN'T WORK, COMMENT IT
  77. */
  78.  
  79. double factorU;
  80.  
  81. dt.initMotors();
  82. dt.initGyro();
  83. //
  84. found1.setPosition(0.0);
  85. found2.setPosition(0.0);
  86.  
  87. waitForStart();
  88. Color.RGBToHSV((int) (sensorColor.red() * SCALE_FACTOR),
  89. (int) (sensorColor.green() * SCALE_FACTOR),
  90. (int) (sensorColor.blue() * SCALE_FACTOR),
  91. hsvValues);
  92.  
  93. /*while(opModeIsActive()) {
  94. telemetry.addData("ENC", dt.robot.leftBack.getCurrentPosition());
  95. telemetry.update();
  96. }*/
  97. dt.moveBackward(10, 0.3);
  98. sleep(200);
  99. dt.strafeRight(12, 0.5);
  100. sleep(200);
  101. dt.moveBackward(10, 0.2);
  102. dt.moveBackward(5, 0.17);
  103. sleep(300);
  104. found1.setPosition(0.5);
  105. found2.setPosition(0.5);
  106. sleep(1000);
  107. dt.moveForward(60, 0.5);
  108. sleep(200);
  109. found1.setPosition(0.0);
  110. found2.setPosition(0.0);
  111. sleep(200);
  112. dt.strafeLeft(30, 0.5);
  113. dt.moveBackward(7, 0.5);
  114. dt.strafeRight(16, 0.4);
  115. dt.moveBackward(7, 0.5);
  116. sleep(200);
  117. dt.strafeLeft(47, 0.5);
  118. dt.moveBackward(4, 0.2);
  119.  
  120. factorU = (sensorColor.red()*sensorColor.green())/
  121. (sensorColor.blue()*sensorColor.blue());
  122.  
  123. if(factorU > 2) {
  124. telemetry.addLine("Tis a stone");
  125. telemetry.update();
  126. dt.moveForward(4, 0.4);
  127. dt.strafeLeft(7, 0.5);
  128. dt.moveBackward(2, 0.5);
  129.  
  130. factorU = (sensorColor.red()*sensorColor.green())/
  131. (sensorColor.blue()*sensorColor.blue());
  132.  
  133. if(factorU > 2) {
  134. telemetry.addLine("Tis a stone");
  135. telemetry.update();
  136.  
  137. dt.moveForward(4, 0.4);
  138. dt.strafeLeft(7, 0.5);
  139.  
  140. telemetry.addLine("Tis a skystone (3)");
  141. telemetry.update();
  142. stoneSequence3();
  143. } else {
  144. telemetry.addLine("Tis a skystone (2)");
  145. telemetry.update();
  146. stoneSequence2();
  147. }
  148.  
  149. } else {
  150. telemetry.addLine("Tis a skystone (1)");
  151. telemetry.update();
  152. stoneSequence1();
  153. }
  154. }
  155.  
  156. public void stoneSequence1() {
  157. dt.moveForward(4, 0.5);
  158. dt.rotate(-85, 0.3);
  159. dt.moveBackward(6.5, 0.5);
  160. dt.strafeRight(16, 0.3);
  161.  
  162. intake1.setPower(-0.4);
  163. intake2.setPower(0.4);
  164.  
  165. dt.moveForward(18, 0.3);
  166.  
  167. intake1.setPower(0.0);
  168. intake2.setPower(0.0);
  169.  
  170. dt.strafeLeft(12.5, 0.3);
  171. dt.moveForward(34, 0.7);
  172.  
  173. sleep(200);
  174.  
  175. intake1.setPower(0.4);
  176. intake2.setPower(-0.4);
  177. sleep(1000);
  178. intake1.setPower(0.0);
  179. intake2.setPower(0.0);
  180.  
  181. sleep(200);
  182.  
  183. dt.moveBackward(3, 0.7);
  184.  
  185. }
  186.  
  187. public void stoneSequence2() {
  188. dt.moveForward(4, 0.5);
  189. dt.rotate(-85, 0.3);
  190. dt.moveBackward(5, 0.5);
  191. dt.strafeRight(19, 0.3);
  192.  
  193. intake1.setPower(-0.4);
  194. intake2.setPower(0.4);
  195.  
  196. dt.moveForward(18, 0.3);
  197.  
  198. intake1.setPower(0.0);
  199. intake2.setPower(0.0);
  200.  
  201. dt.strafeLeft(12.5, 0.3);
  202. dt.moveForward(38, 0.7);
  203.  
  204. sleep(200);
  205.  
  206. intake1.setPower(0.4);
  207. intake2.setPower(-0.4);
  208. sleep(1000);
  209. intake1.setPower(0.0);
  210. intake2.setPower(0.0);
  211.  
  212. sleep(200);
  213.  
  214. dt.moveBackward(6, 0.7);
  215. }
  216.  
  217. public void stoneSequence3() {
  218. dt.moveForward(4, 0.5);
  219. dt.rotate(-85, 0.3);
  220. dt.moveBackward(4, 0.5);
  221. dt.strafeRight(17, 0.3);
  222.  
  223. intake1.setPower(-0.4);
  224. intake2.setPower(0.4);
  225.  
  226. dt.moveForward(16, 0.3);
  227.  
  228. intake1.setPower(0.0);
  229. intake2.setPower(0.0);
  230.  
  231. dt.strafeLeft(12.5, 0.3);
  232. dt.moveForward(50, 0.7);
  233.  
  234. sleep(200);
  235.  
  236. intake1.setPower(0.4);
  237. intake2.setPower(-0.4);
  238. sleep(1000);
  239. intake1.setPower(0.0);
  240. intake2.setPower(0.0);
  241.  
  242. sleep(200);
  243.  
  244. dt.moveBackward(6, 0.7);
  245.  
  246. }
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement