-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlemonkod.py
289 lines (255 loc) · 6.61 KB
/
lemonkod.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# Can Borcbakan, Erem Degerli, IdealabCS
# Lemon eğitim robotu
import sys
import time
from time import sleep
from machine import Pin, PWM, UART
import utime
sys.path.insert(0,"/pre-req")
from pca9685 import PCA9685
from machine import I2C
from servo2 import Servo
import _thread
#i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
#imu = MPU6050(i2c)
# servo 1 ve 30 arasında çalışıyor seb ebi dişli sayısı (180/6 = 30)
#bluetooth modülü için uart tanımlama
# uart = UART(0,9600)
led = Pin(25, Pin.OUT)
sda=Pin(0)
scl=Pin(1)
id = 0
i2c = I2C(id=id,sda=sda,scl=scl)
print(i2c.scan())
pca = PCA9685(i2c = i2c, _address = 0x40)
#Assigning the servo channel values for the PCA9685
FRF=0
FRT=15
FLF=2
FLT=3
RLF=4
RLT=5
RRF=6
RRT=7
servo = Servo(i2c=i2c,pca9685=pca)
#çift pinler femur, tek pinler tibia
def config():
servo.angle(15,FRF)
servo.angle(15,FLF)
servo.angle(15,RLF)
servo.angle(10,RRF)
servo.angle(5,FRT)
servo.angle(9,FLT)
servo.angle(11,RRT)
servo.angle(9,RLT)
def calib():
servo.angle(15,FRF)
servo.angle(15,FLF)
servo.angle(16,RLF)
servo.angle(12,RRF)
servo.angle(10,FRT)
servo.angle(16,FLT)
servo.angle(9,RRT)
servo.angle(13,RLT)
def calibF():
servo.angle(15,FRF)
servo.angle(13,FLF)
servo.angle(13,RLF)
servo.angle(12,RRF)
def calibT():
servo.angle(1,FRT)
servo.angle(30,FLT)
servo.angle(179,RRT)
servo.angle(1,RLT)
def greeting():
config()
servo.motion(0.1,1,1,FLF)
servo.motion(0.1,7.5,1,FLT)
servo.motion(0.1,8,1,FLT)
servo.motion(0.1,7.5,1,FLT)
def stop():
servo.release(FRF)
servo.release(FLF)
servo.release(RLF)
servo.release(RRF)
servo.release(FRT)
servo.release(FLT)
servo.release(RRT)
servo.release(RLT)
"""
def stand():
stop()
sleep(1)
servo.angle(9,RRF)
servo.angle(18,RLF)
servo.angle(15,FRF)
servo.angle(15,FLF)
# servo.angle(20,FLT)
sleep(0.5)
thread0 = _thread.start_new_thread(servo.motion, (0.1,12,0.1,RLT))
sleep(0.1)
servo.motion(0.1,9,0.1,RRT)
sleep(0.1)
servo.motion(0.1,8,0.1,RLT)
sleep(0.1)
servo.motion(0.1,8.9,0.1,RRT)
sleep(0.1)
servo.motion(0.1,5,0.1,FRT)
sleep(0.1)
servo.motion(0.1,9,0.1,FLT)
sleep(0.1)
servo.angle(11,RRT)
servo.angle(9,RLT)
"""
def stand():
stop()
sleep(1)
servo.angle(9,RRF)
servo.angle(18,RLF)
servo.angle(15,FRF)
servo.angle(15,FLF)
# servo.angle(20,FLT)
sleep(0.5)
thread0 = _thread.start_new_thread(servo.motion,(0.1,8,0.1,RLT))
servo.motion(0.1,8.9,0.1,RRT)
sleep(0.1)
thread0 = _thread.start_new_thread(servo.motion,(0.1,5,0.1,FRT))
servo.motion(0.1,9,0.1,FLT)
sleep(0.1)
servo.angle(11,RRT)
servo.angle(9,RLT)
def start():
servo.angle(15,FRF)
servo.angle(15,FLF)
servo.angle(15,RLF)
servo.angle(15,RRF)
servo.angle(15,FRT)
servo.angle(15,FLT)
servo.angle(15,RRT)
servo.angle(15,RLT)
servo.angle(15,FLF)
servo.angle(16,FLT)
sleep(1)
while True:
thread0 = _thread.start_new_thread(servo.motion2, (0.1,12,0.1,FLF))
servo.motion(0.1,9,0.1,FLT)
sleep(1)
thread1 = _thread.start_new_thread(servo.motion2, (0.1,9,0.1,FLF))
servo.motion(0.1,12,0.1,FLT)
"""
start()
sleep(0.5)
servo.motion(0.1,5,0.5,RRT)
sleep(1)
calib()
sleep(0.5)
stand()
while True:
gx=round(imu.gyro.x)
gy=round(imu.gyro.y)
gz=round(imu.gyro.z)
#yapılması gerekilenler:
#gyro hız bağlantısı
#femur ve tibialardaki hareket miktarını eşitlemek
# femur için 12-18 aralığı (FRF'ye göre seçtim) yeterli duruyor
def walk():
count =0
while True:
# gx=round(imu.gyro.x)
# gy=round(imu.gyro.y)
# gz=round(imu.gyro.z)
if(count==0):
posFRF=15
posFRT=5
posFLF=1
posFLT=9
posRLF=15
posRLT=9
posRRF=10
posRRT=9.5
count = 1
else:
inc=5
dec=20
posFRF=20
posFRT=20
posFLF=5
posFLT=5
posRLF=5
posRLT=20
posRRF=5
posRRT=20
while (posFRF>=5) and (posFRT>=5) and (posFLF<=20) and (posFLT<=20) and (posRLF<=20) and (posRLT>=5) and (posRRF<=20) and (posRRT>=5):
servo.angle(posRRF,RRF)
sleep(time)
servo.angle(posRRT,RRT)
sleep(time)
servo.angle(posFRF,FRF)
sleep(time)
servo.angle(posFRT,FRT)
sleep(time)
servo.angle(posRLT,RLT)
sleep(time)
servo.angle(posRLF,RLF)
sleep(time)
servo.angle(posFLF,FLF)
sleep(time)
servo.angle(posFLT,FLT)
sleep(time)
posFRF= posFRF - 0.5
posFRT= posFRT - 0.5
posFLF= posFLF + 0.5
posFLT= posFLT + 0.5
posRLF= posRLF + 0.5
posRLT= posRLT - 0.5
posRRF= posRRF + 0.5
posRRT= posRRT - 0.5
posFRF=5
posFRT=5
posFLF=20
posFLT=20
posRLF=20
posRLT=5
posRRF=20
posRRT=5
while (posFRF<=20) and (posFRT<=20) and (posFLF>=5) and (posFLT>=5) and (posRLF>=5) and (posRLT<=20) and (posRRF>=5) and (posRRT<=20):
servo.angle(posFLF,FLF)
sleep(time)
servo.angle(posFLT,FLT)
sleep(time)
servo.angle(posRLF,RLF)
sleep(time)
servo.angle(posRLT,RLT)
sleep(time)
servo.angle(posRRF,RRF)
sleep(time)
servo.angle(posRRT,RRT)
sleep(time)
servo.angle(posFRF,FRF)
sleep(time)
servo.angle(posRRT,FRT)
sleep(time)
posFRF= posFRF + 0.5
posFRT= posFRT + 0.5
posFLF= posFLF - 0.5
posFLT= posFLT - 0.5
posRLF= posRLF - 0.5
posRLT= posRLT + 0.5
posRRF= posRRF - 0.5
posRRT= posRRT + 0.5
time = 0.1
delta =0.1
config()
sleep(2)
servo.angle(5,0)
stop()
walk()
while True:
if uart.any():
command = uart.readline() #geri gelen sinyali command diye tanımladık
command.alllowercase() # bu çalışmayacak, doğru kod'a bakmak lazım
while(command=="walk"): #yürüme komutunu walk diye tanımladık
distance = dist() #and komutu ile 2 kodu birsden çalıştır
#başlangıç ve başlangıça dönüşü iflerle tasarla, artış ve azalış ilk değere kadar gitmesini engelliyor
while(distance>5):
"""