repository to manage all files related to the makeathon farm bot project (Software + Documentation).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

drive_back.py 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python3
  2. """
  3. created by waldhauser
  4. This file contains the programm to drive the arm back to middle and drive the robot back to home
  5. This file is needed for the hard code driving operations
  6. The plant where the robot is has to be passed as argument
  7. """
  8. from ev3dev2.motor import Motor, LargeMotor, OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D, SpeedPercent
  9. from ev3dev2.sensor.lego import TouchSensor, UltrasonicSensor
  10. from ev3dev2.sensor import INPUT_1, INPUT_4
  11. import sys
  12. motorLeft = LargeMotor(OUTPUT_D)
  13. motorRight = LargeMotor(OUTPUT_A)
  14. motorUpDown = Motor(OUTPUT_C)
  15. motorLeftRight = Motor(OUTPUT_B)
  16. sensorUltraSonic = UltrasonicSensor(INPUT_4)
  17. sensorTouch = TouchSensor(INPUT_1)
  18. plantID = int(sys.argv[1])
  19. # Set direction of arm rotation back to middle
  20. if plantID % 2 == 0:
  21. leftRight = 50 # rotating right
  22. else:
  23. leftRight = -50 # rotating left
  24. motorUpDown.on_for_seconds(SpeedPercent(-50), seconds=2.8)
  25. motorLeftRight.on_for_degrees(SpeedPercent(leftRight), 400)
  26. motorLeft.on(SpeedPercent(-70), block=False)
  27. motorRight.on(SpeedPercent(-70))
  28. while True:
  29. if sensorUltraSonic.distance_centimeters < 10:
  30. motorLeft.on(SpeedPercent(-25), block=False)
  31. motorRight.on(SpeedPercent(-25))
  32. break
  33. sensorTouch.wait_for_pressed(timeout_ms=None, sleep_ms=10)
  34. motorLeft.off()
  35. motorRight.off()