This repository has been archived by the owner on Feb 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testt.py
101 lines (90 loc) · 1.91 KB
/
testt.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
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
import RPi.GPIO as GPIO
import time
#deg90=0.335
in1 = 14 #change
in2 = 15 #change
in3 = 9 #change
in4=11 #change
en1 = 13
en2 = 12
#INITIALISE
GPIO.setmode(GPIO.BCM)
GPIO.setup(in1,GPIO.OUT)
GPIO.setup(in2,GPIO.OUT)
GPIO.setup(in4,GPIO.OUT)
GPIO.setup(in3,GPIO.OUT)
GPIO.output(in1,GPIO.LOW)
GPIO.output(in2,GPIO.LOW)
GPIO.output(in3, GPIO.LOW)
GPIO.output(in4, GPIO.LOW)
GPIO.setup(en1,GPIO.OUT)
p=GPIO.PWM(en1,1000)
GPIO.setup(en2,GPIO.OUT)
p2=GPIO.PWM(en2,1000)
#SET SPEED
p.start(60)
p2.start(60)
#MOVEMENT FUNCTIONS
def forward():
GPIO.output(in1,GPIO.LOW)
GPIO.output(in2,GPIO.HIGH)
GPIO.output(in3,GPIO.LOW)
GPIO.output(in4,GPIO.HIGH)
def backward():
GPIO.output(in1,GPIO.HIGH)
GPIO.output(in2,GPIO.LOW)
GPIO.output(in3,GPIO.HIGH)
GPIO.output(in4,GPIO.LOW)
def right():
GPIO.output(in1,GPIO.LOW)
GPIO.output(in2,GPIO.HIGH)
GPIO.output(in3,GPIO.LOW)
GPIO.output(in4,GPIO.LOW)
def left():
GPIO.output(in1,GPIO.LOW)
GPIO.output(in2,GPIO.LOW)
GPIO.output(in3,GPIO.LOW)
GPIO.output(in4,GPIO.HIGH)
def stop():
GPIO.output(in1,GPIO.LOW)
GPIO.output(in2,GPIO.LOW)
GPIO.output(in3,GPIO.LOW)
GPIO.output(in4,GPIO.LOW)
def gos(f,s):
f()
time.sleep(s)
'''
def movetank(s1,s2,tim):
p.ChangeDutyCycle(abs(s1))
p2.ChangeDutyCycle(abs(s2))
GPIO.output(in1, s1<0)
GPIO.output(in2, s1>0)
GPIO.output(in3, s2 < 0)
GPIO.output(in4, s2 > 0)
time.sleep(tim)
stop()
p.ChangeDutyCycle(60)
p2.ChangeDutyCycle(60)
forward()
time.sleep(0.1)
stop()
time.sleep(0.1)
backward()
time.sleep(0.1)
stop()
time.sleep(0.05)
'''
if __name__== "__main__":
gos(forward, 0.3)
gos(right, 0.3 )
gos(forward, 7.5)
gos(right, 1.5)
gos(forward, 8)
gos(right, 1.2)
gos(forward, 4)
gos(right, 0.5)
gos(forward, 7)
gos(right, 0.8)
gos(forward, 3)
stop()
GPIO.cleanup()