-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
155 lines (129 loc) · 4.79 KB
/
main.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
from dronekit import connect, VehicleMode, LocationGlobalRelative,Command
import hareketler.alanTara as alanTarama
import hareketler.genelHareketler as genelHareketler
#import insanTespit.insanTespit as insanTespit
import threading
import test
import time
import re
import multiprocessing
from pymavlink import mavutil
#import insanTespit.servo as servo
def connectToVehicle():
iha = connect('127.0.0.1:14550', wait_ready=True) # 127.0.0.1:14550 -> değiştirilecek
return iha
# def komutDinle(iha):
# # Listen for `STATUSTEXT` messages
# @iha.on_message('STATUSTEXT')
# def handle_statustext_message(self, name, message):
# text = message.text
# if text.startswith("commandGCS:"):
# print("Received command:", text)
# print("2")
# # Wait for messages
# while True:
# time.sleep(1)
# def komutDinle2(iha):
# @iha.on_message('STATUSTEXT')
# def handle_statustext_messages(self,name,message):
# text = message.text
# if text.startswith("commandGCS:"):
# print("Received Command:", text)
# if("alanTaraKare" in text):
# alanTaramaThread.start()
# tespitThread.start()
# elif("yuvarlakTara" in text):
# alan
# ihaya bağlan
iha = connectToVehicle()
################################### YER İSTASYONU İLETİŞİM KODU ##################################
# @iha.on_message('STATUSTEXT')
# def handle_statustext_message(self, name, message):
# text = message.text
# if text.startswith("commandGCS:"):
# # Process the message
# print("Received command:", text)
# if("alanTaraKare" in text):
# # değişkenleri topla
# text = re.findall(r"\,(.*?),", text)
# # eğer zaten istenen yükseklikteyse direkt istenen konuma git
# if(iha.location.global_relative_frame.alt >= float(text[2]) * 0.90):
# genelHareketler.konumaGit(iha,konum)
# else:
# genelHareketler.takeoff(15,iha)
# konum = LocationGlobalRelative(text[0],text[1],10)
# genelHareketler.konumaGit(iha,konum)
# konum = LocationGlobalRelative(text[0],text[1], 10) # enlem, boylam, yükseklik
# # threadleri tanımla
# tespitThread = threading.Thread(target=insanTespit.main,args=iha)
# alanTaramaThread = threading.Thread(target=alanTarama.alanTaraKare,args=(text[2], iha, konum)) # uzunluk, iha, konum
# # threadleri başlat
# tespitThread.start()
# time.sleep(5) # kamera açılana kadar bekle
# alanTaramaThread.start()
# elif("RTL" in text):
# if tespitThread.is_alive():
# tespitThread.stopped = True
# tespitThread.join()
# if alanTaramaThread.is_alive():
# alanTaramaThread.stopped = True
# alanTaramaThread.join()
# iha.mode = VehicleMode("RTL")
# elif("BRAKE" in text):
# if tespitThread.is_alive():
# tespitThread.stopped = True
# tespitThread.join()
# if alanTaramaThread.is_alive():
# alanTaramaThread.stopped = True
# alanTaramaThread.join()
# iha.mode = VehicleMode("BRAKE")
# elif("LAND" in text):
# if tespitThread.is_alive():
# tespitThread.stopped = True
# tespitThread.join()
# if alanTaramaThread.is_alive():
# alanTaramaThread.stopped = True
# alanTaramaThread.join()
# iha.mode = VehicleMode("LAND")
# while True:
# time.sleep(1)
########################################################################################
#kalkış yap
genelHareketler.takeoff(5,iha)
#konumu tanımla
konum = iha.location.global_relative_frame # -> güncel konum
#threadleri tanımla
#alanTaramaThread = threading.Thread(target=alanTarama.alanTaraKare,args=(10,iha,konum)) # kare -> çevre, yuvarlak -> çap veya yarıçap
#tespitThread = threading.Thread(target=insanTespit.main,args=iha)
# konuma git
#genelHareketler.konumaGit(iha,konum)
# alanı taramaya başla.
#tespitThread.start()
#time.sleep(5) # kameranın açılmasını bekle
#alanTaramaThread.start()
alanTarama.alanTaraKare(20,iha,konum)
smallMove = 0.000009
konum.alt = 5
while True:
if(iha.mode == "BRAKE"):
#iha.simple_goto(konum)
time.sleep(3)
#servo.runServo()
time.sleep(5)
komut = iha.commands
komut.clear()
time.sleep(1)
komut.add(Command(0, 0, 0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT, mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, 0, 0, 0, 0, 0, 0, konum.lat, konum.lon, 5))
#komut.add(Command(0, 0, 0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT, mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, 0, 0, 0, 0, 0, 0, konum.lat, konum.lon, 0))
time.sleep(1)
komut.upload()
print("Komutlar yukleniyor")
iha.mode=VehicleMode("AUTO")
print("gidiyom bn")
break
while((iha.location.global_relative_frame.lat < konum.lat + smallMove and iha.location.global_relative_frame.lat > konum.lat - smallMove
and iha.location.global_relative_frame.lon < konum.lon + smallMove and iha.location.global_relative_frame.lon > konum.lon - smallMove)) is not True:
time.sleep(1)
print("bekleniyor.")
iha.mode = VehicleMode("LAND")
exit()