-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobot1.py
executable file
·86 lines (60 loc) · 1.48 KB
/
robot1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import time
from gpiozero import CamJamKitRobot
from gpiozero import DistanceSensor
#Defining pins for Distance
pinTrigger = 17
pinEcho = 18
leftMotorSpeed = 0.8
rightMotorSpeed = 0.8
sensor = DistanceSensor(echo=pinEcho, trigger=pinTrigger)
robot = CamJamKitRobot()
forward = (leftMotorSpeed, rightMotorSpeed)
right = (0, rightMotorSpeed)
left = (leftMotorSpeed, 0)
wallDistance = 40.0
def test():
str('Hello')
return str
def start():
robot.value = forward
def stop():
robot.stop()
def howFarAmI ():
while True:
dist = sensor.distance * 100
print(int(dist))
return dist
def leftMotor ():
return leftMotorSpeed
def rightMotor ():
return rightMotorSpeed
def followWall():
#while True:
counter = 0
while (counter <= 50): #we can change the value depending on how long we want to run the robot
counter = counter + 1
distance = sensor.distance * 100
print ("Distance before moving: %.1f cm" % distance)
robot.value = forward
time.sleep(0.2)
print ("went straight")
dist2 = sensor.distance * 100
if (dist2 > 10+ wallDistance):
print ("went left")
robot.value = left
time.sleep (0.05)
dist3 = sensor.distance * 100
if (dist3 > 88):
print ("went nested right")
robot.value = right
time.sleep(0.05)
elif (dist2 < wallDistance -10):
print ("went outer right")
robot.value = right
time.sleep(0.05)
else:
print ("went else straight")
robot.value = forward
time.sleep(0.3)
robot.stop()
#counter = counter + 1