onlinecodesimulator/readme.md

99 lines
1.4 KiB
Markdown

import robot
import time
robot.move(0.00006)
while True:
if robot.get_sensors()[0]["hitpoint"]["x"] is not None:
robot.turn(0.001)
elif robot.get_sensors()[1]["hitpoint"]["x"] is not None:
robot.turn(-0.001)
else:
robot.turn(0)
time.sleep(0.1)
import robot
import time
robot.move(0.00006)
while True:
left = robot.get_sensors()[0]["distance"]
right = robot.get_sensors()[1]["distance"]
print(str(int(left)) + "\t" + str(int(right)))
if left < 55:
robot.turn(0.01)
elif right < 55:
robot.turn(-0.01)
else:
robot.turn(0)
time.sleep(0.1)
#Robot 1
import time
import robot
robot.move(1)
time.sleep(1.6)
robot.move(0)
robot.turn(1)
time.sleep(2.2)
robot.turn(0)
robot.move(1)
#Robot 2
import robot
import time
robot.move(1)
time.sleep(0.8)
robot.move(0.4)
robot.turn(1)
time.sleep(4.7)
robot.move(0)
robot.turn(0)
#Robot 3
import time
import robot
robot.move(1)
while True:
if robot.get_distance_left() < 58:
robot.turn(1)
robot.move(0.2)
elif robot.get_distance_right() < 58:
robot.turn(-1)
robot.move(0.2)
else:
robot.move(1)
robot.turn(0)
time.sleep(0.01)
# FOLLOW LINE
import robot
import time
while True:
robot.move(0.1)
if robot.get_line_left():
robot.turn(-1)
elif robot.get_line_right():
robot.turn(1)
else:
robot.turn(0)
time.sleep(0.05)