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

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