Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 KB | None | 0 0
  1. package ourproject;
  2.  
  3. import lejos.util.DebugMessages;
  4. import lejos.util.Matrix;
  5. import lejos.geom.Line;
  6. import lejos.geom.Rectangle;
  7. import lejos.nxt.Motor;
  8. import lejos.nxt.comm.RConsole;
  9. import lejos.robotics.RegulatedMotor;
  10. import lejos.robotics.localization.OdometryPoseProvider;
  11. import lejos.robotics.localization.PoseProvider;
  12.  
  13. //TASK 1
  14. //-----------
  15. //import lejos.nxt.LCD;
  16. //
  17. ///**
  18. // * A simple hello world program.
  19. // *
  20. // * @author Lawrie Griffiths
  21. // */
  22. //public class Main {
  23. // public static void main(String[] aArg) throws Exception {
  24. // LCD.drawString("Hello World", 3, 4);
  25. // Thread.sleep(2000);
  26. // }
  27. //}
  28.  
  29.  
  30. //TASK 2-3
  31. //---------------
  32.  
  33. //import lejos.nxt.Button;
  34. //import lejos.nxt.LCD;
  35. //import lejos.nxt.Motor;
  36. //import lejos.nxt.SensorPort;
  37. //import lejos.nxt.addon.GyroSensor;
  38. //import lejos.robotics.Gyroscope;
  39. //import lejos.robotics.navigation.DifferentialPilot;
  40. //import lejos.util.Delay;
  41.  
  42. /**
  43. * Test of Gyro Sensor
  44. * Records the minimum, maximum and current values
  45. *
  46. * @author Lawrie Griffiths
  47. */
  48. /*//public class Main {
  49. // public static void main(String[] args) {
  50. // Gyroscope gyro = new GyroSensor(SensorPort.S1);
  51. // float minValue = 0, maxValue = 0;
  52. //
  53. // LCD.drawString("Gyro Test:", 0, 0);
  54. // LCD.drawString("Min:", 0, 2);
  55. // LCD.drawString("Max:", 0, 3);
  56. // LCD.drawString("Current:", 0, 4);
  57. //
  58. // //while(!Button.ESCAPE.isDown()) {
  59. // DifferentialPilot pilot = new DifferentialPilot(3.26f, 19.5f, Motor.A, Motor.B, false); // parameters in inches
  60. // // pilot.setRotateSpeed(30);; // cm per second
  61. // pilot.setAcceleration(10000);
  62. // pilot.setRotateSpeed(10000);
  63. // Delay.msDelay(10000);
  64. // pilot.travel(200); // cm
  65. // pilot.rotate(90);
  66. // pilot.travel(580); // cm
  67. // pilot.rotate(90);
  68. // pilot.travel(270); // cm
  69. // pilot.rotate(90);
  70. // pilot.travel(110); // cm
  71. // pilot.rotate(90);
  72. // // degree clockwise
  73. // // pilot.travel(-50,true); // move backward for 50 cm
  74. // while(pilot.isMoving())Thread.yield();
  75. // // pilot.rotate(-90);
  76. // // pilot.rotate
  77. // // pilot.steer(-50,180,true); // turn 180 degrees to the right
  78. // // waitComplete(); // returns when previous method is complete
  79. // // pilot.steer(100); // turns with left wheel stationary
  80. // Delay.msDelay(1000);
  81. // pilot.stop();
  82. // //}
  83. // }
  84. //}
  85. */
  86. //TASK 4
  87. //-------
  88. import lejos.robotics.mapping.LineMap;
  89. import lejos.robotics.navigation.DifferentialPilot;
  90. import lejos.robotics.navigation.NavigationListener;
  91. import lejos.robotics.navigation.Navigator;
  92. import lejos.robotics.navigation.Pose;
  93. import lejos.robotics.navigation.Waypoint;
  94. import lejos.robotics.pathfinding.AstarSearchAlgorithm;
  95. import lejos.robotics.pathfinding.FourWayGridMesh;
  96. import lejos.robotics.pathfinding.NodePathFinder;
  97. import lejos.robotics.pathfinding.PathFinder;
  98. import lejos.util.PilotProps;
  99.  
  100. /**
  101. * This sample uses the A* search algorithm to find a path from one location to another. The code demonstrates
  102. * how to create a trivial LineMap, feed it to a GridMesh, and then use a pathfinder
  103. * to control the robot and allow it to navigate around map obstacles. You will need to construct a simple
  104. * pilot robot to use this class. No sensors are required.
  105. *
  106. * @author BB
  107. *
  108. */
  109. public class Main {
  110.  
  111. public static void main(String[] args) throws Exception {
  112.  
  113.  
  114. RConsole.open();
  115. DifferentialPilot robot = new DifferentialPilot(3.26f, 19.5f, Motor.A, Motor.B, false); // parameters in inches
  116.  
  117. // Create a rudimentary map:
  118. Line [] lines = new Line[3];
  119. /*lines [0] = new Line(75f, 100f, 100f, 100f);
  120. lines [1] = new Line(100, 100, 87, 75);
  121. lines [2] = new Line(87, 75, 75, 100);*/
  122. lines [0] = new Line(30, 30, 50, 65);
  123. lines [1] = new Line(50, 65, 65, 37.5f);
  124. lines [2] = new Line(65, 37.5f, 30, 30);
  125. lejos.geom.Rectangle bounds = new Rectangle(-30, -30, 150, 150);
  126. LineMap myMap = new LineMap(lines, bounds);
  127.  
  128. // Use a regular grid of node points. Grid space = 20. Clearance = 15:
  129. FourWayGridMesh grid = new FourWayGridMesh(myMap, 10, 5);
  130.  
  131. // Use A* search:
  132. AstarSearchAlgorithm alg = new AstarSearchAlgorithm();
  133.  
  134. // Give the A* search alg and grid to the PathFinder:
  135. PathFinder pf = new NodePathFinder(alg, grid);
  136.  
  137. PoseProvider posep = new OdometryPoseProvider(robot);
  138.  
  139. Navigator nav = new Navigator(robot, posep) ;
  140. nav.addNavigationListener(new NavigationListener() {
  141.  
  142. public void pathInterrupted(Waypoint waypoint, Pose pose, int sequence) {
  143. // TODO Auto-generated method stub
  144. RConsole.println("interupted :<");
  145. }
  146.  
  147. public void pathComplete(Waypoint waypoint, Pose pose, int sequence) {
  148. // TODO Auto-generated method stub
  149. RConsole.println("Pizza delivered");
  150. }
  151.  
  152. public void atWaypoint(Waypoint waypoint, Pose pose, int sequence) {
  153. // TODO Auto-generated method stub
  154. RConsole.println(waypoint.toString());
  155.  
  156. }
  157. });
  158. System.out.println("Planning path...");
  159. //nav.followPath(pf.findRoute(posep.getPose(), new Waypoint(130, 130)));
  160. nav.followPath(pf.findRoute(posep.getPose(), new Waypoint(25, 75)));
  161. nav.waitForStop();
  162.  
  163. RConsole.close();
  164. }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement