Added color code driving, changed Plant order, Docu update

This commit is contained in:
waldluis
2023-05-05 10:40:33 +02:00
parent 0a53fe171a
commit 830d662e08
11 changed files with 70 additions and 37 deletions
+13 -5
View File
@@ -8,23 +8,31 @@ motorLeft = LargeMotor(OUTPUT_D)
motorRight = LargeMotor(OUTPUT_A)
motorUpDown = Motor(OUTPUT_C)
motorLeftRight = Motor(OUTPUT_B)
ultraSensor = UltrasonicSensor(INPUT_4)
touchSensor = TouchSensor(INPUT_1)
sensorUltraSonic = UltrasonicSensor(INPUT_4)
sensorTouch = TouchSensor(INPUT_1)
plantID = int(sys.argv[1])
# Set direction of arm rotation back to middle
if plantID % 2 == 0:
leftRight = 50 # rotating right
else:
leftRight = -50 # rotating left
motorUpDown.on_for_seconds(SpeedPercent(-50), seconds=2.8)
motorLeftRight.on_for_degrees(SpeedPercent(int(sys.argv[1])), 400)
motorLeftRight.on_for_degrees(SpeedPercent(leftRight), 400)
motorLeft.on(SpeedPercent(-70), block=False)
motorRight.on(SpeedPercent(-70))
while True:
if ultraSensor.distance_centimeters < 10:
if sensorUltraSonic.distance_centimeters < 10:
motorLeft.on(SpeedPercent(-25), block=False)
motorRight.on(SpeedPercent(-25))
break
touchSensor.wait_for_pressed(timeout_ms=None, sleep_ms=10)
sensorTouch.wait_for_pressed(timeout_ms=None, sleep_ms=10)
motorLeft.off()
motorRight.off()
+48
View File
@@ -0,0 +1,48 @@
#!/usr/bin/env pybricks-micropython
'''
Script to drive robot to plant.
Plant number is passed as argument.
'''
from ev3dev2.motor import Motor, LargeMotor, OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D, SpeedPercent
from ev3dev2.sensor.lego import ColorSensor
from ev3dev2.sensor import INPUT_2
import sys
motorRight = LargeMotor(OUTPUT_A)
motorLeft = LargeMotor(OUTPUT_D)
motorUpDown = Motor(OUTPUT_C)
motorLeftRight = Motor(OUTPUT_B)
sensorColor = ColorSensor(INPUT_2)
plantID = int(sys.argv[1])
# Set color according to plant number
if plantID == 1 or plantID == 2:
colorCode = ColorSensor.COLOR_RED
elif plantID == 3 or plantID == 4:
colorCode = ColorSensor.COLOR_GREEN
elif plantID == 5 or plantID == 6:
colorCode = ColorSensor.COLOR_BLUE
# Set direction of arm rotation
if plantID % 2 == 0:
leftRight = -50 # rotating left
else:
leftRight = 50 # rotating right
motorRight.on(SpeedPercent(70), block=False)
motorLeft.on(SpeedPercent(70))
while True:
if sensorColor.color == colorCode:
break
motorLeft.off()
motorRight.off()
motorLeftRight.on_for_degrees(SpeedPercent(leftRight), 400)
motorUpDown.on_for_seconds(SpeedPercent(50), seconds=2.8)
+1 -1
View File
@@ -10,6 +10,6 @@ motorLeftRight = Motor(OUTPUT_B)
motorRight.on_for_seconds(SpeedPercent(70), seconds=0.8, block=False)
motorLeft.on_for_seconds(SpeedPercent(70), seconds=0.8)
motorLeftRight.on_for_degrees(SpeedPercent(-50), 400)
motorLeftRight.on_for_degrees(SpeedPercent(50), 400)
motorUpDown.on_for_seconds(SpeedPercent(50), seconds=2.8)
+1 -1
View File
@@ -10,7 +10,7 @@ motorLeftRight = Motor(OUTPUT_B)
motorRight.on_for_seconds(SpeedPercent(70), seconds=0.8, block=False)
motorLeft.on_for_seconds(SpeedPercent(70), seconds=0.8)
motorLeftRight.on_for_degrees(SpeedPercent(50), 400)
motorLeftRight.on_for_degrees(SpeedPercent(-50), 400)
motorUpDown.on_for_seconds(SpeedPercent(50), seconds=2.8)
+1 -1
View File
@@ -10,7 +10,7 @@ motorLeftRight = Motor(OUTPUT_B)
motorRight.on_for_seconds(SpeedPercent(70), seconds=2.2, block=False)
motorLeft.on_for_seconds(SpeedPercent(70), seconds=2.2)
motorLeftRight.on_for_degrees(SpeedPercent(-50), 400)
motorLeftRight.on_for_degrees(SpeedPercent(50), 400)
motorUpDown.on_for_seconds(SpeedPercent(50), seconds=2.8)
+1 -1
View File
@@ -10,6 +10,6 @@ motorLeftRight = Motor(OUTPUT_B)
motorRight.on_for_seconds(SpeedPercent(70), seconds=2.2, block=False)
motorLeft.on_for_seconds(SpeedPercent(70), seconds=2.2)
motorLeftRight.on_for_degrees(SpeedPercent(50), 400)
motorLeftRight.on_for_degrees(SpeedPercent(-50), 400)
motorUpDown.on_for_seconds(SpeedPercent(50), seconds=3)
+1 -1
View File
@@ -10,7 +10,7 @@ motorLeftRight = Motor(OUTPUT_B)
motorRight.on_for_seconds(SpeedPercent(70), seconds=2.7, block=False)
motorLeft.on_for_seconds(SpeedPercent(70), seconds=2.7)
motorLeftRight.on_for_degrees(SpeedPercent(-50), 400)
motorLeftRight.on_for_degrees(SpeedPercent(50), 400)
motorUpDown.on_for_seconds(SpeedPercent(50), seconds=3)
+1 -1
View File
@@ -10,7 +10,7 @@ motorLeftRight = Motor(OUTPUT_B)
motorRight.on_for_seconds(SpeedPercent(70), seconds=2.7, block=False)
motorLeft.on_for_seconds(SpeedPercent(70), seconds=2.7)
motorLeftRight.on_for_degrees(SpeedPercent(50), 400)
motorLeftRight.on_for_degrees(SpeedPercent(-50), 400)
motorUpDown.on_for_seconds(SpeedPercent(50), seconds=3)
-21
View File
@@ -1,21 +0,0 @@
#!/usr/bin/env python3
from ev3dev2.motor import LargeMotor, OUTPUT_A, SpeedPercent
from ev3dev2.sensor.lego import TouchSensor, UltrasonicSensor
from ev3dev2.sensor import INPUT_1, INPUT_4
m = LargeMotor(OUTPUT_A)
touch = TouchSensor(INPUT_1)
ultraSonic = UltrasonicSensor(INPUT_4)
ultraSonic.MODE_US_DIST_CM
m.on(SpeedPercent(50))
while True:
if ultraSonic.distance_centimeters < 10:
m.on(SpeedPercent(25))
break
touch.wait_for_pressed(timeout_ms=None, sleep_ms=10)
m.off()