-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_program.py
More file actions
125 lines (112 loc) · 2.87 KB
/
main_program.py
File metadata and controls
125 lines (112 loc) · 2.87 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#This is then main Program, all smaller pieces contained in
#Other files.
import serial_module as serMod
from DEFs import _LEFT, _RIGHT, _BACKWARD, _FORWARD, _STOP
#import checkSensors as objSense
import RPi.GPIO as GPIO
import time
mot_left_pwm = 13
mot_right_pwm = 18
mot_left_dir = 24
mot_right_dir = 23
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(mot_left_pwm,GPIO.OUT)
GPIO.setup(mot_right_pwm,GPIO.OUT)
GPIO.setup(mot_left_dir,GPIO.OUT)
GPIO.setup(mot_right_dir,GPIO.OUT)
GPIO.output(mot_left_dir,GPIO.LOW)
GPIO.output(mot_right_dir,GPIO.LOW)
mot_left = GPIO.PWM(mot_left_pwm,500)
mot_right = GPIO.PWM(mot_right_pwm,500)
mot_left.start(0)
mot_right.start(0)
mot_delay_time = 1.8
max_us_distance = 45
def go_forward():
#mot_left.start(0)
#mot_right.start(0)
GPIO.output(mot_left_dir,GPIO.LOW)
GPIO.output(mot_right_dir,GPIO.HIGH)
mot_left.ChangeDutyCycle(84)
mot_right.ChangeDutyCycle(60)
time.sleep(mot_delay_time)
mot_left.ChangeDutyCycle(0)
mot_right.ChangeDutyCycle(0)
#mot_left.stop()
#mot_right.stop()
return
def go_left():
#mot_left.start(0)
#mot_right.start(0)
GPIO.output(mot_left_dir,GPIO.LOW)
GPIO.output(mot_right_dir,GPIO.LOW)
mot_left.ChangeDutyCycle(70)
mot_right.ChangeDutyCycle(20)
time.sleep(0.8)
mot_left.ChangeDutyCycle(0)
mot_right.ChangeDutyCycle(0)
#mot_left.stop()
#mot_right.stop()
return
def go_right():
#mot_left.start(0)
#mot_right.start(0)
GPIO.output(mot_left_dir,GPIO.LOW)
print("Right Disabled")
#GPIO.output(mot_right_dir,GPIO.HIGH)
mot_left.ChangeDutyCycle(70)
#mot_right.ChangeDutyCycle(80)
time.sleep(0.6)
mot_left.ChangeDutyCycle(0)
#mot_right.ChangeDutyCycle(0)
#mot_left.stop()
#mot_right.stop()
return
def go_backward():
#mot_left.start(0)
#mot_right.start(0)
GPIO.output(mot_left_dir,GPIO.HIGH)
GPIO.output(mot_right_dir,GPIO.LOW)
mot_left.ChangeDutyCycle(52)
mot_right.ChangeDutyCycle(75)
time.sleep(mot_delay_time)
mot_left.ChangeDutyCycle(0)
mot_right.ChangeDutyCycle(0)
#mot_left.stop()
#mot_right.stop()
return
#Main Loop
while 1:
input_data = serMod.get_serial()
#input_data = raw_input("Direction: ")
if input_data == "2":
#min_distance = objSense.check(_LEFT)
#if min_distance == 0 or min_distance > max_us_distance:
print("Going Left")
go_left()
#else:
print("Can't Move")
elif input_data == "1":
#min_distance = objSense.check(_FORWARD)
#if min_distance == 0 or min_distance > max_us_distance:
print("Going Forward")
go_forward()
#else:
print("Can't Move");
elif input_data == "3":
#min_distance = objSense.check(_RIGHT)
#if min_distance == 0 or min_distance > max_us_distance:
print("Going Right")
go_right()
#else:
print("Can't Move")
elif input_data == "4":
#min_distance = objSense.check(_BACKWARD)
#if min_distance == 0 or min_distance > max_us_distance:
print("Going Backward")
go_backward()
#else:
print("Cant Move")
else:
print("Stopping")