Advertisement
Technologyman00

Untitled

Aug 30th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1.  
  2. import java.util.Random;
  3. public class TestMain {
  4. public static void main(String[] args) {
  5.  
  6. //Instances
  7. Random gen=new Random();
  8. Decoder decoder=new Decoder();
  9. TargetFilter filter=new TargetFilter();
  10. AligntoTarget align=new AligntoTarget();
  11.  
  12. //Variables
  13. int syncbyte = -1;
  14. String blocksync = "0xaa55";
  15. //Pixy Data
  16. //How Much Data
  17. int setsofdata = 25;
  18. int amountofbytes = 14;
  19. int amountofvariables = 7;
  20. //Data From Pixy
  21. String[] data = new String[(amountofbytes * setsofdata)];
  22. //Sorted Data From Pixy
  23. String[][] objects = new String[setsofdata][amountofbytes];
  24. //Converted Data From Pixy
  25. double[][] targets = new double[setsofdata][amountofvariables];
  26. //Find Best Target
  27. double numdist = -1; //Distance between numbers and closest
  28. int[] bestcount = new int[setsofdata];
  29. int besttarget = 0;
  30. double[] target = new double[amountofvariables];
  31. //Targeting System Variables
  32. boolean fixed = false,xgood = false,ygood = false,hgood = false,wgood = false;
  33. boolean strafe = false;
  34. //Robot Variables
  35. double LeftMotor = 0,RightMotor = 0;
  36. boolean auto = false;
  37. double oldwidth = 0;
  38. boolean shot = false, trigger = true;
  39. //Target What is Looking For
  40. double[] want = new double[amountofvariables];
  41. double[] highrange = new double[amountofvariables];
  42. double[] lowrange = new double[amountofvariables];
  43.  
  44. //Goal Values Hard Coded
  45. //View is 640 x 400
  46. want[3] = 200; //X Center
  47. want[4] = 320; //Y Center
  48. want[5] = 40; //Width
  49. want[6] = 80; //Height
  50.  
  51. //Range That Goal Can Be within
  52. //For Example
  53. //(want x-axis) + (low range) > Targets X < (want x-axis) + (high range)
  54. //If above is true Goal is Okay. /\
  55. //X Center
  56. highrange[3] = 5; //Must Be Positive or 0
  57. lowrange[3] = -5; //Must Be Negative or 0
  58. //Y Center
  59. highrange[4] = 5; //Must Be Positive or 0
  60. lowrange[4] = -5; //Must Be Negative or 0
  61. //Width
  62. highrange[5] = 5; //Must Be Positive or 0
  63. lowrange[5] = -5; //Must Be Negative or 0
  64. //Height
  65. highrange[6] = 5; //Must Be Positive or 0
  66. lowrange[6] = -5; //Must Be Negative or 0
  67.  
  68.  
  69. //Note: Want, High Range and Low Range should probably be able to be changed from the SmartDash Board
  70.  
  71. //Init Should Not Run More than Once
  72. //Set the Ranges to actual Ranges
  73. for(int i=3; i < amountofvariables; i++){
  74. highrange[i] = highrange[i] + want[i];
  75. lowrange[i] = lowrange[i] + want[i];
  76. }
  77.  
  78. /* How Data is Sent
  79. * Bytes 16-bit word Description
  80. ----------------------------------------------------------------
  81. 0, 1 y sync: 0xaa55=normal object, 0xaa56=color code object
  82. 2, 3 y checksum (sum of all 16-bit words 2-6)
  83. 4, 5 y signature number
  84. 6, 7 y x center of object
  85. 8, 9 y y center of object
  86. 10, 11 y width of object
  87. 12, 13 y height of object
  88. */
  89. /* How Data is Stored
  90. * Bytes Description
  91. ----------------------------------------------------------------
  92. 0 sync: 0xaa55=normal object, 0xaa56=color code object
  93. 1 checksum (sum of all 16-bit words 2-6)
  94. 2 signature number
  95. 3 x center of object
  96. 4 y center of object
  97. 5 width of object
  98. 6 height of object
  99. */
  100. for(int i = 0; i < (amountofbytes * setsofdata); i++){
  101. if(i % 14 == 0){
  102. data[i] = blocksync;
  103. //System.out.println("Data["+i+"] = "+data[i]);
  104. }
  105. else{
  106. data[i] = Integer.toString(gen.nextInt(600));
  107. //System.out.println("Data["+i+"] = "+data[i]);
  108. }
  109. }
  110.  
  111. //See How hard the processes takes on different systems
  112. long startTime = System.currentTimeMillis();
  113.  
  114. //while(!shot && trigger){ //Runs until the trigger is let go or ball is shot
  115. //Decoder
  116. //Takes in all Data From Pixy and Organizes it for Conversion
  117. objects = decoder.decode(setsofdata, amountofbytes, blocksync, data, syncbyte, objects);
  118. //Convert
  119. //Takes in the objects and converts them from strings to bytes to ints into usable numbers
  120. targets = decoder.convert(amountofbytes, setsofdata, amountofvariables, objects, targets);
  121. //Filter Targets
  122. // Takes in the Use able numbers and outputs the correct target will also sort out other targets
  123. target = filter.filter(numdist, target, targets, want, setsofdata, bestcount, besttarget, amountofvariables);
  124. //Align to Target
  125. //Takes in the Correct Target and Lines the robot up to shoot and shoots
  126. shot = align.align(shot, fixed, xgood, ygood, hgood, wgood, auto, strafe, oldwidth, target, want, highrange, lowrange, LeftMotor, RightMotor);
  127. long endTime = System.currentTimeMillis();
  128. long totalTime = endTime - startTime;
  129. System.out.println("Time to Complete: Milliseconds: "+totalTime);
  130. //}
  131.  
  132.  
  133. }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement