Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. import lejos.hardware.port.SensorPort;
  2. import lejos.hardware.sensor.EV3ColorSensor;
  3. import lejos.hardware.sensor.EV3UltrasonicSensor;
  4. import lejos.robotics.SampleProvider;
  5. import Ressource.Robot20192020;
  6.  
  7.  
  8. public class mainRobot {
  9.  
  10. //VARIABLE
  11. static EV3ColorSensor sensor4 = new EV3ColorSensor(SensorPort.S3);
  12. static SampleProvider light4= sensor4.getMode("Red");
  13. static float sample4[] = new float[light4.sampleSize()];
  14.  
  15. static float x=(float) 0.2;
  16.  
  17. //variable obstacle
  18. static EV3UltrasonicSensor sonar = new EV3UltrasonicSensor(SensorPort.S4);
  19. static float[] value = new float[1];
  20. static float y=(float) 0.9;
  21.  
  22.  
  23. public static void main(String[] args) {
  24. Robot20192020.AfficherUnmessage("READY STEP1");
  25. Robot20192020.Attendre(); // Le robot attend que l'on appuie pour avancer.
  26. step1();
  27. closeSensor();
  28. }
  29.  
  30. public static void step1(){
  31. //boolean detection1 = false;
  32.  
  33. while (x > 0.06 && x < 0.3 && y > 0.2) {
  34. light4.fetchSample(sample4, 0);
  35. x= sample4[0];
  36. Robot20192020.AfficherUnmessageinst("DETECTION:" +x);
  37. sonar.getDistanceMode().fetchSample(value, 0);
  38. y= value[0];
  39. Robot20192020.Avancer();
  40. }
  41. Robot20192020.Arreter();
  42. Robot20192020.FaireUnePause(2);
  43. Robot20192020.FaireUneRotationAGauche(180);
  44.  
  45. }
  46.  
  47. public static void closeSensor(){
  48. sensor4.close();
  49. sonar.close();
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement