Files
Roboteksperimentarium/square.py
NikolajDanger 552c783ce8 turn_test.py
2022-09-07 13:31:44 +02:00

64 lines
1.2 KiB
Python

from time import sleep
import robot
POWER = 70
TURN_T = 0.079 # 10 degrees
DRIVE_T = 0.22 # 10 centimeter
RIGHT_WHEEL_OFFSET = 4
CLOCKWISE_OFFSET = 0.96
def clockwise_square(arlo):
while True:
# Driving forward
arlo.go_diff(POWER, POWER + RIGHT_WHEEL_OFFSET, 1, 1)
sleep(DRIVE_T * 10)
arlo.stop()
sleep(1)
# Turning 90 degrees
arlo.go_diff(POWER, POWER + RIGHT_WHEEL_OFFSET, 1, 0)
sleep(TURN_T * 9 * CLOCKWISE_OFFSET)
arlo.stop()
sleep(1)
def counter_square(arlo):
while True:
# Driving forward
arlo.go_diff(POWER, POWER + RIGHT_WHEEL_OFFSET, 1, 1)
sleep(DRIVE_T * 10)
arlo.stop()
sleep(1)
# Turning 90 degrees
arlo.go_diff(POWER, POWER + RIGHT_WHEEL_OFFSET, 0, 1)
sleep(TURN_T * 9)
arlo.stop()
sleep(1)
def main():
# Initializes the robot and runs the
arlo = robot.Robot()
direction = int(input("clockwise (1)/counter (2):"))
try:
if direction == 1:
clockwise_square(arlo)
else:
counter_square(arlo)
except KeyboardInterrupt:
arlo.stop()
if __name__ == "__main__":
main()