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.1KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. sensorUltraSonic = UltrasonicSensor(INPUT_4)
  11. sensorTouch = TouchSensor(INPUT_1)
  12. plantID = int(sys.argv[1])
  13. # Set direction of arm rotation back to middle
  14. if plantID % 2 == 0:
  15. leftRight = 50 # rotating right
  16. else:
  17. leftRight = -50 # rotating left
  18. motorUpDown.on_for_seconds(SpeedPercent(-50), seconds=2.8)
  19. motorLeftRight.on_for_degrees(SpeedPercent(leftRight), 400)
  20. motorLeft.on(SpeedPercent(-70), block=False)
  21. motorRight.on(SpeedPercent(-70))
  22. while True:
  23. if sensorUltraSonic.distance_centimeters < 10:
  24. motorLeft.on(SpeedPercent(-25), block=False)
  25. motorRight.on(SpeedPercent(-25))
  26. break
  27. sensorTouch.wait_for_pressed(timeout_ms=None, sleep_ms=10)
  28. motorLeft.off()
  29. motorRight.off()