forked from ideasxiang/r2auto_nav
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathir_board.py
More file actions
56 lines (40 loc) · 1.15 KB
/
Copy pathir_board.py
File metadata and controls
56 lines (40 loc) · 1.15 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
import time
import RPi.GPIO as GPIO
import serial
GPIO.setmode(GPIO.BCM)
servo_pin = 13
GPIO.setup(servo_pin, GPIO.OUT)
p= GPIO.PWM(servo_pin, 50)
p.start(2.5)
angle=36
temperature=[]
angle=[]
ser = serial.Serial('/dev/ttyUSB1', 115200, timeout=2)
while True:
readText = ser.readline()
decode = readText.decode('UTF-8')
print(decode)
def servo(tmp,tmp_am):
try:
#-------------------adjusting the angle---------------------
while (temp - temp_am > 1):
for i in range (10):
pwm = 5.0*angle/90.0+2.5
p.ChangeDutyCycle(pwm)
time.sleep(1)
temp=get_am_tmp()
an=i*36
temperature.append(temp)
angle.append(an)
max_tmp = max(temperature)
index=temperature.index(max_tmp)
max_an = angle[index]
pwm = 5.0*max_an/90.0+2.5
p.ChangeDutyCycle(pwm)
time.sleep(1)
#---------------------------------------------------------------
#---------------------shooting--------------------------------
#------------------------------------------------------------
except KeyboardInterrupt:
p.stop()
GPIO.clenup()