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 917B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env python3
  2. from ev3dev2.motor import Motor, LargeMotor, OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D, SpeedPercent
  3. from ev3dev2.sensor.lego import TouchSensor, UltrasonicSensor
  4. from ev3dev2.sensor import INPUT_1, INPUT_4
  5. import sys
  6. motorLeft = LargeMotor(OUTPUT_D)
  7. motorRight = LargeMotor(OUTPUT_A)
  8. motorUpDown = Motor(OUTPUT_C)
  9. motorLeftRight = Motor(OUTPUT_B)
  10. ultraSensor = UltrasonicSensor(INPUT_4)
  11. touchSensor = TouchSensor(INPUT_1)
  12. motorUpDown.on_for_seconds(SpeedPercent(-50), seconds=2.8)
  13. motorLeftRight.on_for_degrees(SpeedPercent(int(sys.argv[1])), 400)
  14. motorLeft.on(SpeedPercent(-70), block=False)
  15. motorRight.on(SpeedPercent(-70))
  16. while True:
  17. if ultraSensor.distance_centimeters < 10:
  18. motorLeft.on(SpeedPercent(-25), block=False)
  19. motorRight.on(SpeedPercent(-25))
  20. break
  21. touchSensor.wait_for_pressed(timeout_ms=None, sleep_ms=10)
  22. motorLeft.off()
  23. motorRight.off()