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_plant.py 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env pybricks-micropython
  2. """
  3. created by waldhauser
  4. This file contians the programm to drive to a specific plant based on the color codes
  5. The plant where the robot is has to be passed as argument
  6. """
  7. from ev3dev2.motor import Motor, LargeMotor, OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D, SpeedPercent
  8. from ev3dev2.sensor.lego import ColorSensor
  9. from ev3dev2.sensor import INPUT_2
  10. import sys
  11. motorRight = LargeMotor(OUTPUT_A)
  12. motorLeft = LargeMotor(OUTPUT_D)
  13. motorUpDown = Motor(OUTPUT_C)
  14. motorLeftRight = Motor(OUTPUT_B)
  15. sensorColor = ColorSensor(INPUT_2)
  16. plantID = int(sys.argv[1])
  17. # Set color according to plant number
  18. if plantID == 1 or plantID == 2:
  19. colorCode = ColorSensor.COLOR_RED
  20. elif plantID == 3 or plantID == 4:
  21. colorCode = ColorSensor.COLOR_GREEN
  22. elif plantID == 5 or plantID == 6:
  23. colorCode = ColorSensor.COLOR_BLUE
  24. # Set direction of arm rotation
  25. if plantID % 2 == 0:
  26. leftRight = -50 # rotating left
  27. else:
  28. leftRight = 50 # rotating right
  29. motorRight.on(SpeedPercent(70), block=False)
  30. motorLeft.on(SpeedPercent(70))
  31. while True:
  32. if sensorColor.color == colorCode:
  33. break
  34. motorLeft.off()
  35. motorRight.off()
  36. motorLeftRight.on_for_degrees(SpeedPercent(leftRight), 400)
  37. motorUpDown.on_for_seconds(SpeedPercent(50), seconds=2.8)