Advertisement
m4ly

lego

Apr 18th, 2015
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. package lalab;
  2.  
  3. import java.io.IOException;
  4. import java.util.ArrayList;
  5.  
  6. import lejos.geom.Line;
  7. import lejos.geom.Rectangle;
  8. import lejos.nxt.Button;
  9. import lejos.nxt.LCD;
  10. import lejos.robotics.RegulatedMotor;
  11. import lejos.robotics.mapping.LineMap;
  12. import lejos.robotics.navigation.DifferentialPilot;
  13. import lejos.robotics.navigation.Pose;
  14. import lejos.robotics.navigation.Waypoint;
  15. import lejos.util.Delay;
  16. import lejos.util.PilotProps;
  17. import lejos.robotics.pathfinding.NodePathFinder;
  18. import lejos.robotics.pathfinding.Path;
  19. import lejos.robotics.pathfinding.ShortestPathFinder;
  20. import lejos.robotics.pathfinding.NavigationMesh;
  21. import lejos.robotics.pathfinding.FourWayGridMesh;
  22. import lejos.robotics.pathfinding.AstarSearchAlgorithm;
  23. import lejos.robotics.pathfinding.DijkstraPathFinder;
  24.  
  25. public class Move
  26. {
  27.  
  28. public static Line[] lines = {
  29.  
  30. new Line(-40,-42,-40,102),
  31. new Line(-42,100,22,100),
  32. new Line(20,102,20,78),
  33. new Line(18,80,82,80),
  34. new Line(80,78,80,122),
  35. new Line(78,120,122,120),
  36. new Line(120,122,120,78),
  37. new Line(118,80,162,80),
  38. new Line(160,82,160,-42),
  39. new Line(162,-40,-42,-40),
  40. };
  41.  
  42.  
  43. static RegulatedMotor leftMotor;
  44. static RegulatedMotor rightMotor;
  45.  
  46. public static Pose start = new Pose(0,0,180);
  47. public static Pose final_ = new Pose(100,100,90);
  48.  
  49.  
  50. /*public static Waypoint end_node_waypoint = new Waypoint(final_);
  51. public static Rectangle ramka = new Rectangle(150,150,250,250);
  52. public static LineMap mapa = new LineMap(lines,ramka);
  53. public static DijkstraPathFinder dijkstra = new DijkstraPathFinder(mapa);
  54. public static Path path;
  55. public static String pathString;
  56. */
  57.  
  58. public static void main(String[] args ) throws Exception
  59. {
  60.  
  61. PilotProps pp = new PilotProps();
  62. pp.loadPersistentValues();
  63. float wheelDiameter = Float.parseFloat(pp.getProperty(PilotProps.KEY_WHEELDIAMETER, "4.96"));
  64. float trackWidth = Float.parseFloat(pp.getProperty(PilotProps.KEY_TRACKWIDTH, "13.0"));
  65. leftMotor = PilotProps.getMotor(pp.getProperty(PilotProps.KEY_LEFTMOTOR, "A"));
  66. rightMotor = PilotProps.getMotor(pp.getProperty(PilotProps.KEY_RIGHTMOTOR, "B"));
  67. boolean reverse = Boolean.parseBoolean(pp.getProperty(PilotProps.KEY_REVERSE,"false"));
  68. DifferentialPilot robot = new DifferentialPilot(wheelDiameter,trackWidth,leftMotor,rightMotor,reverse);
  69.  
  70. // Wait for user to press ENTER
  71. Button.waitForAnyPress();
  72.  
  73.  
  74. robot.setAcceleration(4000);
  75. robot.setTravelSpeed(20); // cm/sec
  76. robot.setRotateSpeed(180); // deg/sec
  77. robot.travel(100,true);
  78. while(robot.isMoving())
  79. Thread.yield();
  80. robot.rotate(90);
  81.  
  82. robot.travel(100,true);
  83. while(robot.isMoving())
  84. Thread.yield();
  85.  
  86. robot.rotate(90);
  87. robot.travel(100,true);
  88. while(robot.isMoving())
  89. Thread.yield();
  90. robot.rotate(90);
  91. robot.travel(100,true);
  92.  
  93.  
  94. // robot.forward();
  95.  
  96. /*
  97. * Delay.msDelay(1000);;
  98.  
  99. robot.stop();
  100. showCount(robot, 0);
  101.  
  102. robot.backward();
  103. Delay.msDelay(1000);;
  104.  
  105. robot.stop();
  106. showCount(robot, 1);
  107. robot.travel(10,true);
  108.  
  109. while(robot.isMoving())
  110. Thread.yield();
  111. showCount(robot, 2);
  112. robot.travel(-10);
  113. showCount(robot, 3);
  114.  
  115. for(int i = 0; i<4; i++)
  116. {
  117. robot.rotate(90);
  118. }
  119.  
  120. showCount(robot, 4);
  121.  
  122. for(int i = 0; i<4; i++)
  123. {
  124. robot.rotate(-90,true);
  125. while(robot.isMoving())
  126. Thread.yield();
  127. }
  128. showCount(robot, 5);
  129. robot.steer(-50,180,true);
  130.  
  131. while(robot.isMoving())
  132. Thread.yield();
  133.  
  134. robot.steer(-50,-180);
  135. showCount(robot, 6);
  136. robot.steer(50,180);
  137. robot.steer(50, -180);
  138. showCount(robot, 7);
  139. robot.travel(10,true);
  140. Delay.msDelay(500);
  141. robot.stop();
  142. robot.travel(-10);
  143. robot.rotate(720);
  144. */
  145. // Exit after any button is pressed
  146. Button.waitForAnyPress();
  147. }
  148.  
  149. public static void showCount(DifferentialPilot robot, int i)
  150. {
  151. LCD.drawInt(leftMotor.getTachoCount(),0,i);
  152. LCD.drawInt(rightMotor.getTachoCount(),7,i);
  153. }
  154.  
  155. public void stop() {
  156. //while(Button.waitForAnyPress()) {
  157.  
  158.  
  159. }
  160.  
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement