2023-04-22 14:59:02 +02:00
|
|
|
#!/usr/bin/env python3
|
2023-06-06 11:28:24 +02:00
|
|
|
|
|
|
|
"""
|
|
|
|
created by waldhauser
|
|
|
|
|
|
|
|
This file contains the programm to drive the arm back to middle and drive the robot back to home
|
|
|
|
This file is needed for the hard code driving operations
|
|
|
|
The plant where the robot is has to be passed as argument
|
|
|
|
"""
|
|
|
|
|
2023-04-22 14:59:02 +02:00
|
|
|
from ev3dev2.motor import Motor, LargeMotor, OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D, SpeedPercent
|
|
|
|
from ev3dev2.sensor.lego import TouchSensor, UltrasonicSensor
|
|
|
|
from ev3dev2.sensor import INPUT_1, INPUT_4
|
|
|
|
import sys
|
|
|
|
|
|
|
|
motorLeft = LargeMotor(OUTPUT_D)
|
|
|
|
motorRight = LargeMotor(OUTPUT_A)
|
|
|
|
motorUpDown = Motor(OUTPUT_C)
|
|
|
|
motorLeftRight = Motor(OUTPUT_B)
|
2023-05-05 10:40:33 +02:00
|
|
|
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
|
2023-04-22 14:59:02 +02:00
|
|
|
|
|
|
|
motorUpDown.on_for_seconds(SpeedPercent(-50), seconds=2.8)
|
2023-05-05 10:40:33 +02:00
|
|
|
motorLeftRight.on_for_degrees(SpeedPercent(leftRight), 400)
|
2023-04-22 14:59:02 +02:00
|
|
|
|
|
|
|
motorLeft.on(SpeedPercent(-70), block=False)
|
|
|
|
motorRight.on(SpeedPercent(-70))
|
|
|
|
|
|
|
|
while True:
|
2023-05-05 10:40:33 +02:00
|
|
|
if sensorUltraSonic.distance_centimeters < 10:
|
2023-04-22 14:59:02 +02:00
|
|
|
motorLeft.on(SpeedPercent(-25), block=False)
|
|
|
|
motorRight.on(SpeedPercent(-25))
|
|
|
|
break
|
|
|
|
|
2023-05-05 10:40:33 +02:00
|
|
|
sensorTouch.wait_for_pressed(timeout_ms=None, sleep_ms=10)
|
2023-04-22 14:59:02 +02:00
|
|
|
motorLeft.off()
|
|
|
|
motorRight.off()
|