forked from jorgecrce/CamBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcambot.py
129 lines (98 loc) · 2.73 KB
/
cambot.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#imports
import webiopi
# Libreria GPIO
GPIO = webiopi.GPIO
# -------------------------------------------------- #
# Definicion constantes #
# -------------------------------------------------- #
# GPIOs motor izquierdo
L1=10 # H-Bridge 1
L2=9 # H-Bridge 2
Le=23 # PWM left
# GPIOs motor derecho
R1=17 # H-Bridge 3
R2=21 # H-Bridge 4
Re=22 #Enable PWM Right
# -------------------------------------------------- #
# Funciones motor izquierdo #
# -------------------------------------------------- #
def left_stop():
GPIO.output(L1, GPIO.LOW)
GPIO.output(L2, GPIO.LOW)
def left_forward():
GPIO.output(L1, GPIO.HIGH)
GPIO.output(L2, GPIO.LOW)
def left_backward():
GPIO.output(L1, GPIO.LOW)
GPIO.output(L2, GPIO.HIGH)
# -------------------------------------------------- #
# Funciones motor derecho #
# -------------------------------------------------- #
def right_stop():
GPIO.output(R1, GPIO.LOW)
GPIO.output(R2, GPIO.LOW)
def right_forward():
GPIO.output(R1, GPIO.HIGH)
GPIO.output(R2, GPIO.LOW)
def right_backward():
GPIO.output(R1, GPIO.LOW)
GPIO.output(R2, GPIO.HIGH)
#--------------------------------#
#Velocidades #
#--------------------------------#
def vel_left(ve):
GPIO.pulseRatio(Le, ve)
def vel_right(vel):
GPIO.pulseRatio(Re, vel)
# -------------------------------------------------- #
# Definicion macros #
# -------------------------------------------------- #
@webiopi.macro
def go_forward():
left_forward()
right_forward()
vel_left(1)
vel_right(1)
@webiopi.macro
def go_backward():
left_backward()
right_backward()
vel_left(0.5)
vel_right(0.5)
@webiopi.macro
def turn_left():
right_forward()
left_backward()
vel_left(0.2)
vel_right(0.2)
@webiopi.macro
def turn_right():
right_backward()
left_forward()
vel_left(0.2)
vel_right(0.2)
@webiopi.macro
def stop():
left_stop()
right_stop()
vel_left(0)
vel_right(0)
# -------------------------------------------------- #
# Iniciacializacion #
# -------------------------------------------------- #
def setup():
# Instalacion GPIOs
GPIO.setFunction(L1, GPIO.OUT)
GPIO.setFunction(L2, GPIO.OUT)
GPIO.setFunction(R1, GPIO.OUT)
GPIO.setFunction(R2, GPIO.OUT)
GPIO.setFunction(Re, GPIO.PWM)
GPIO.setFunction(Le, GPIO.PWM)
def destroy():
# Resetea las funciones GPIO
GPIO.setFunction(L1, GPIO.IN)
GPIO.setFunction(L2, GPIO.IN)
GPIO.setFunction(R1, GPIO.IN)
GPIO.setFunction(R2, GPIO.IN)
GPIO.setFunction(Le, GPIO.IN)
GPIO.setFunction(Re, GPIO.IN)