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_straight.py 950B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env python3
  2. """
  3. created by waldhauser
  4. This file contains the programm to drive the robot back to the starting position
  5. This file is needed for the color code drive operation
  6. No arguments are needed
  7. The end is determined by the UltraSonic- and TouchSensor
  8. """
  9. from ev3dev2.motor import LargeMotor, OUTPUT_A, OUTPUT_D, SpeedPercent
  10. from ev3dev2.sensor.lego import TouchSensor, UltrasonicSensor
  11. from ev3dev2.sensor import INPUT_1, INPUT_4
  12. motorLeft = LargeMotor(OUTPUT_D)
  13. motorRight = LargeMotor(OUTPUT_A)
  14. sensorUltraSonic = UltrasonicSensor(INPUT_4)
  15. sensorTouch = TouchSensor(INPUT_1)
  16. motorLeft.on(SpeedPercent(-70), block=False)
  17. motorRight.on(SpeedPercent(-70))
  18. while True:
  19. if sensorUltraSonic.distance_centimeters < 10:
  20. motorLeft.on(SpeedPercent(-25), block=False)
  21. motorRight.on(SpeedPercent(-25))
  22. break
  23. sensorTouch.wait_for_pressed(timeout_ms=None, sleep_ms=10)
  24. motorLeft.off()
  25. motorRight.off()