Advertisement
Guest User

Untitled

a guest
May 24th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1.  
  2. import java.io.File;
  3.  
  4. import lejos.hardware.Button;
  5. import lejos.hardware.lcd.LCD;
  6. import lejos.hardware.motor.EV3LargeRegulatedMotor;
  7. import lejos.hardware.port.MotorPort;
  8. import lejos.hardware.port.SensorPort;
  9. import lejos.hardware.sensor.EV3ColorSensor;
  10. import lejos.hardware.sensor.EV3GyroSensor;
  11. import lejos.hardware.sensor.EV3UltrasonicSensor;
  12. import lejos.robotics.SampleProvider;
  13. import lejos.robotics.navigation.DifferentialPilot;
  14. import lejos.utility.Delay;
  15. import lejos.hardware.Sound;
  16.  
  17. public class Deplacement {
  18. // DEFAULT SPEED
  19. public static final int defaultLinearSpeed = 100;
  20. public static final int defaultRotationalSpeed = 100;
  21.  
  22. // MOTORS
  23. public static final EV3LargeRegulatedMotor leftMotor = new EV3LargeRegulatedMotor(MotorPort.B);
  24. public static final EV3LargeRegulatedMotor rightMotor = new EV3LargeRegulatedMotor(MotorPort.C);
  25.  
  26. // PILOT
  27. // Initialize motor parameters
  28. private static final float wheelDiameter = 56f; // mm diameter wheel
  29. private static final float trackWidth = 123f; // mm distance bw wheels
  30. public static final DifferentialPilot pilote = new DifferentialPilot(wheelDiameter, trackWidth, leftMotor,
  31. rightMotor);
  32.  
  33. // SENSORS
  34. private static final float ultrasoundThreshold = (float) 0.10; // in m
  35. private static final EV3UltrasonicSensor ultrasoundSensor = new EV3UltrasonicSensor(SensorPort.S1);
  36. private static final EV3ColorSensor colorSensor = new EV3ColorSensor(SensorPort.S3);
  37. private static final EV3GyroSensor gyroSensor = new EV3GyroSensor(SensorPort.S4);
  38.  
  39. Point MaPosition;
  40. Point Arrive;
  41. //PositionClient robot = new PositionClient("EV3",4);
  42. MulticastClient robot = new MulticastClient();
  43. float[] maPos;
  44. //Distance d;
  45. int K1; int K2; int K3;
  46. int vmax=320;
  47. public static void main(String[] args) throws Exception {
  48. Lecture_de_Fichier coord = new Lecture_de_Fichier("Testsami.txt",8);
  49. }
  50.  
  51. Deplacement(double[][] parcours) {
  52. // le tableau parcours renvoie les points à parcourir en ordre
  53. int compt = 0;
  54. double x, y, theta, xd, yd, ex, ey, theta_d, theta_e, vg, vd, vref, w,d;
  55. while (compt < parcours.length) {
  56. //partie recuperz la position du robot
  57. maPos = robot.getCoord_mobile();
  58. x = (double)maPos[0];
  59. y = (double)maPos[1];
  60. theta =(double)maPos[3];
  61. xd = parcours[compt][0];
  62. yd = parcours[compt][1];
  63. theta_d=(float)( Math.atan2(yd-y, xd-x) * 180 / Math.PI);
  64. theta_e=(theta_d-theta);
  65. MaPosition.setX(x);MaPosition.setY(y);
  66. Arrive.setX(xd);Arrive.setY(yd);
  67. d=Math.sqrt((x - xd)*(x - xd)+(y - yd)*(y - yd));
  68. if(x <5000.0 && y<5000.0) {
  69. while (d>50) { //Math.abs(x - xd) > 50000 | Math.abs(y - yd) > 50000) { //distance en millimetre
  70. //d=new Distance(MaPosition,Arrive);
  71. //pilote.travel(d.distance*1000);
  72. vref=(d/(K1+d))*vmax*Math.cos(theta_e);
  73. w=(vref/d)*Math.sin(theta_e);
  74.  
  75. // a verifier le 89 ?
  76. vg=0.5*(2*vref-89*w)*100;
  77. vd=0.5*(2*vref+89*w)*100;
  78. leftMotor . setSpeed ((int)vg) ;
  79. rightMotor . setSpeed ((int)vd) ;
  80.  
  81. maPos = robot.getCoord_mobile();
  82. x = maPos[0]; //X
  83. y = maPos[1]; //Y
  84. theta = maPos[3];
  85. d=Math.sqrt((x - xd)*(x - xd)+(y - yd)*(y - yd));
  86. theta_d=(float)( Math.atan2(yd-y, xd-x) * 180 / Math.PI);
  87. theta_e=(theta_d-theta);
  88. //MaPosition.setX(x);MaPosition.setY(y);
  89. } // Fin si le robot atteint le point
  90. }
  91. System.out.println("Le point est atteint");
  92. compt++;
  93. } //Fin boucle de la liste
  94. } // Fin methode Deplacement
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement