From 24a3cc9724299bbc89ffe5a8b210d6ecd54468eb Mon Sep 17 00:00:00 2001 From: Fernando Julio Cendra Date: Thu, 25 Jun 2020 22:18:38 +0800 Subject: [PATCH 01/41] addding new folder --- model/clearbot.weights | 3 - report/Confidence.py | 7 ++ report/Label.py | 6 ++ report/Location.py | 13 +++ report/__pycache__/Confidence.cpython-37.pyc | Bin 0 -> 529 bytes report/__pycache__/Label.cpython-37.pyc | Bin 0 -> 499 bytes report/__pycache__/Location.cpython-37.pyc | Bin 0 -> 774 bytes report/__pycache__/test1.cpython-37.pyc | Bin 0 -> 3704 bytes report/dronekit.py | 102 +++++++++++++++++++ report/main.py | 26 +++++ report/report.py | 45 ++++++++ report/report_folder/report.json | 1 + report/reports.py | 0 13 files changed, 200 insertions(+), 3 deletions(-) delete mode 100644 model/clearbot.weights create mode 100644 report/Confidence.py create mode 100644 report/Label.py create mode 100644 report/Location.py create mode 100644 report/__pycache__/Confidence.cpython-37.pyc create mode 100644 report/__pycache__/Label.cpython-37.pyc create mode 100644 report/__pycache__/Location.cpython-37.pyc create mode 100644 report/__pycache__/test1.cpython-37.pyc create mode 100644 report/dronekit.py create mode 100644 report/main.py create mode 100644 report/report.py create mode 100644 report/report_folder/report.json create mode 100644 report/reports.py diff --git a/model/clearbot.weights b/model/clearbot.weights deleted file mode 100644 index 8156a77..0000000 --- a/model/clearbot.weights +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:fdb7cd1bb42f6d1abfa579d0d9b81137ed5b5e8bc0749901b8aa216891c2c671 -size 257373000 diff --git a/report/Confidence.py b/report/Confidence.py new file mode 100644 index 0000000..66923a4 --- /dev/null +++ b/report/Confidence.py @@ -0,0 +1,7 @@ +class Confidence: + def __init__(self, i): + self.i = i + + def get_confidence(self): + return self.i + \ No newline at end of file diff --git a/report/Label.py b/report/Label.py new file mode 100644 index 0000000..24427ef --- /dev/null +++ b/report/Label.py @@ -0,0 +1,6 @@ +class Label: + def __init__(self, z): + self.z = z + + def get_label(self): + return self.z \ No newline at end of file diff --git a/report/Location.py b/report/Location.py new file mode 100644 index 0000000..ca33c5a --- /dev/null +++ b/report/Location.py @@ -0,0 +1,13 @@ +class Location: + def __init__(self, x, y): + self.x = x + self.y = y + + def get_x(self): + return self.x + + def get_y(self): + return self.y + + def get_coordinate(self): + return (self.x, self.y) \ No newline at end of file diff --git a/report/__pycache__/Confidence.cpython-37.pyc b/report/__pycache__/Confidence.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e44090e1f283cdcd8b2b80838c515553a72e23b8 GIT binary patch literal 529 zcmY*VJx{|h5Is9di6Y7X6A}|!76wLyP(_j0y1*1gSjBcxP(F&C4xnu9pW!cgvg< z!k(eikT3-aS4{C8B%bn=kI`2F?oC`YugX=XbSbr@Ju-@fIl_{thBY9N6*t%-W{zbs zcfQs6%Fx^=7$3v$`Q26eT-8M`E2UGT*OjR+(|>}C^}7p&$jYo1f)*_~U>_%=nZ7R> z_0T91S~U|)8hGuMwDd7Ebe~p3=K_4XqZeHZIsA@lJ>ThwZ+~hL2PCmv7Fq}w2~kvP xlT&^u#M@?>cO64I%)ve@-M|oy=_Ok#g)H>i3SO>_Bca2J3$Ht-8`}Lwz#kBCY6buR literal 0 HcmV?d00001 diff --git a/report/__pycache__/Label.cpython-37.pyc b/report/__pycache__/Label.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..df2c2c517c660250908425d0d1654ae78e4ddf81 GIT binary patch literal 499 zcmY*Vy-ve05I#Fe2^9s286F@D10zDH0wfmH1*RzCNMnPFoTk|6K$VTY46o#sM}Ucm zyF`iLr0>4_@%cOZaxxhM+2j59gCqXrq_=>ADZw3*y8#7CYzgl&1tsqw2@0wYCMlW{ z+z~kqsZfwgC6wGk8mK^p#G#64Zseoee6CHwBW%o!D}v*F8qolfARQL7M0l}Dqz|1o zPnOSpfDMU$j<3(Mc~zIDsFcpEURAa}&Dy(9R&PE=Tr3wgBF{K>AU6A5yKfbO%Vf-q zc83uK4ZQUFt!N@Fe@Ls`xrkD~`>bm;{2Weum4i-Y=*^Od*IDMJM)YIEvQlfq@gCyq sIyYU%vasFxFT+o@e7Ws+bX9JCespqBq^HjMcAyi>a1*)Ib80$jdbf&c&j literal 0 HcmV?d00001 diff --git a/report/__pycache__/Location.cpython-37.pyc b/report/__pycache__/Location.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c14abae7969271a7fbd964481875abaeaafbb028 GIT binary patch literal 774 zcma)4OH0E*5T4yUx-D%{FJ8R{#DfP9B2rZFqP=(v#U*A_iKI#0q|lVy?4R*3oB_PiM@E8BT~PcE9K*-= zhB#USW#1f@>&4nW#-=DI2w=T1ud{RU7McN^z6;UKS>?Pnblcsp2Ja zx`U!%1xP43O00}oZ0PWk%}bU$Mro!&G}e@$Df1Pyh3fO*>U8vwWRu8GR4~%PG|}1d zs0KTl=B1D_jKfSy%1uoaz-+eIZDMM_kK3t;G;!6LjYa`a-~F(v1BYp zpd$5L`x|quV}?$P_8ohZK+3Ws(Nm`{w-LxoBphXb(<)TSkph;guTY}Q8WZD#|E?0Ks ztApP9LwfJ8;jQSY=iYki3`sdFi!>|>oT0Ga?)UA?a(DPityWg>`tALHe|cF|l)vfE z_$uPVW4wbdn$a34pt?$5HPyamYWz0vLJsm! zfa32tv&b|kU8t;Rl^~B+KTtr2xmOCzU1;VUl%FfD%0I}Zv~ppo<9it@06YYeCQi}ABHY7JiE`p0PcJ2#1XrO;3Gr$1`CAU zcAenJNCw71j5ZTzjCsZ}69NA9Y|l4r4~)JO1k^roZ4|-Jt9!ss_k!cprbDWMgx5bDo{nQLk;Ta=U^Td(3fEmme5zA0ZsH(ScVn!HCTl;^mSN=4fOM{ z30vqFU>k0sUxeFWpkIPJ@CNz@?7&_0O}Gd5(J#ZB@D}iJ3xy9!B{rDGS8b*#n0a-4*k)s8)|+m7o9 zhXrP?D+Vo<6E@No8+s$cW-<*+?y!h0V>KJGnl#ufibCB@mb6*zMT^?%a$Le0vNpgc zMPi5{O5o%EO-Y;)i^~SjB9Yf{WOF&8^LpAt1j%_8EIVS*en%1EdzVhr8BR>T-JgNQV^Xfry)q(Fi(4%`u*5KEN$ia{4ioJ&(3aY^5R7N7#Cp=45bsLF$vT(> z%)ne^Ctb@w$(V5Q^Cw?eUq9KC2&?f-}~sgmuJhF51i%>4ba@nckDwlIczM zoq@H&ZLi0=jt7jVQ-;+DV#SybB<`hnrgC#SbNYeC*KsVY4;)-AUMFj(Tb75n#^4Vn z8Jp8GE^)K#DV_SRuzOi@niFyo>_?KCmYo zEkWsG@Rh`$ob@TF!`51;TajSP3d@!ie`nxx)v|sa+AdASvUmkYG7U0RrtxJmD`cn&iZ&!pr3c?6vqgrMC%;98lEvvf5iJ?2R(SypRcXNk zG`gziZuX1%9k$B2fh6BcoN8^JBa=rH76#n$M3`qU9T8Pk{0_C}H`Q`gj@s;l)}T`Q|a?SBCoB<=tJ literal 0 HcmV?d00001 diff --git a/report/dronekit.py b/report/dronekit.py new file mode 100644 index 0000000..c5d20ed --- /dev/null +++ b/report/dronekit.py @@ -0,0 +1,102 @@ +try: + from dronekit import connect, VehicleMode, LocationGlobalRelative +except: + print("No module named dronekit, try to establish connection between jetson nano and mission planner") + exit(0) + +# Connect to the Vehicle +vehicle = connect('/dev/ttyTHS1', wait_ready=True, baud=57600) + +vehicle.mode = VehicleMode("MANUAL") +vehicle.armed = True + +class test1(): + def firmware_version(self): + return vehicle.version + + def vehicle_capabilities(self): + return vehicle.capabilities.ftp + + def do_capture_global_location(self): + return vehicle.location.global_frame + + def do_capture_relative_global_location(self): + return vehicle.location.global_relative_frame + + def do_capture_altitude(self): + return vehicle.altitude + + def do_capture_velocity(self): + return vehicle.velocity + + def do_capture_gps(self): + return vehicle.gps_0 + + def do_capture_ground_speed(self): + return vehicle.groundspeed + + def do_capture_air_speed(self): + return vehicle.airspeed + + def gimbal_status(self): + return vehicle.gimbal + + def battery_status(self): + return vehicle.battery + + def EKF_OK(self): + return vehicle.ekf_ok + + def last_heartbeat(self): + return vehicle.last_heartbeat + + def range_finder(self): + return vehicle.rangefinder + + def range_finder_distance(self): + return vehicle.rangefinder.distance + + def range_finder_voltage(self): + return vehicle.rangefinder.voltage + + def heading(self): + return vehicle.heading + + def vehicle_is_armable(self): + return vehicle.is_armable + + def system_status(self): + return vehicle.system_status.state + + def vehicle_mode_name(self): + return vehicle.mode.name + + def check_vehicle_armed(self): + return vehicle.armed + + + + +# vehicle is an instance of the Vehicle class +#print('Autopilot Firmware version: %s' % vehicle.version) +#print('Autopilot capabilities (supports ftp): %s' % vehicle.capabilities.ftp) +#print('Global Location: %s' % vehicle.location.global_frame) +#print('Global Location (relative altitude): %s' % vehicle.location.global_relative_frame) +#print('Local Location: %s' % vehicle.location.local_frame) #NED +#print('Attitude: %s' % vehicle.attitude) +#print('Velocity: %s' % vehicle.velocity) +#print('GPS: %s' % vehicle.gps_0) +#print('Groundspeed: %s' % vehicle.groundspeed) +#print('Airspeed: %s' % vehicle.airspeed) +#print('Gimbal status: %s' % vehicle.gimbal) +#print('Battery: %s' % vehicle.battery) +#print('EKF OK?: %s' % vehicle.ekf_ok) +#print('Last Heartbeat: %s' % vehicle.last_heartbeat) +#print('Rangefinder: %s' % vehicle.rangefinder) +#print('Rangefinder distance: %s' % vehicle.rangefinder.distance) +#print('Rangefinder voltage: %s' % vehicle.rangefinder.voltage) +#print('Heading: %s' % vehicle.heading) +#print('Is Armable?: %s' % vehicle.is_armable) +#print('System status: %s' % vehicle.system_status.state) +#print('Mode: %s' % vehicle.mode.name) # settable +#print('Armed: %s' % vehicle.armed) # settable \ No newline at end of file diff --git a/report/main.py b/report/main.py new file mode 100644 index 0000000..4863ba1 --- /dev/null +++ b/report/main.py @@ -0,0 +1,26 @@ +import asyncio +import sys +import os +import time + + +sys.path.insert(1, "/botmlcode/") + + +from yolo_object_detection import yolo_object_detection +from dronekit import dronekit + +def run(): + os.system('python /botmlcode/yolo_object_detection.py') + time.sleep(60) + + + + + + + + + + + diff --git a/report/report.py b/report/report.py new file mode 100644 index 0000000..584aaa7 --- /dev/null +++ b/report/report.py @@ -0,0 +1,45 @@ +import json + +from Location import Location +from Confidence import Confidence +from Label import Label + +class Report: + def __init__(self, label, confidence, location): + self.label = Label(label) + self.confidence = Confidence(confidence) + self.location = Location(location[0], location[1]) + self.report = {} + + def create_report(self): + report = { + "label": self.label.get_label(), + "confidence": self.confidence.get_confidence(), + "location": self.location.get_coordinate() + } + + self.report = report + + def print_report(self): + print(self.report) + + def write_report(self, path): + with open(path, 'a') as file_stream: + json.dump(self.report, file_stream) + + + #def get_label(self): + # return yolo_object_detection.LABELS + + #def get_confidence(self): + # return yolo_object_detection.confidence + + #def get_location(self): + # return test1.do_capture_relative_global_location(self) + +report = Report("metal", 98.5, (102, 71)) +report.print_report() +report.create_report() +report.print_report() +report.write_report('report_folder/report.json') + diff --git a/report/report_folder/report.json b/report/report_folder/report.json new file mode 100644 index 0000000..8b06288 --- /dev/null +++ b/report/report_folder/report.json @@ -0,0 +1 @@ +{"label": "metal", "confidence": 98.5, "location": [102, 71]}{"label": "metal", "confidence": 98.5, "location": [102, 71]} \ No newline at end of file diff --git a/report/reports.py b/report/reports.py new file mode 100644 index 0000000..e69de29 From b9d78e8d714f6b5eb2ab9381dba8c0acbfe43722 Mon Sep 17 00:00:00 2001 From: Fernando Julio Cendra Date: Fri, 26 Jun 2020 10:52:43 +0800 Subject: [PATCH 02/41] rename file from dronekit.py to pixhawk,py --- report/main.py | 2 +- report/{dronekit.py => pixhawk.py} | 0 report/report_folder/report.json | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename report/{dronekit.py => pixhawk.py} (100%) diff --git a/report/main.py b/report/main.py index 4863ba1..bb71fe8 100644 --- a/report/main.py +++ b/report/main.py @@ -8,7 +8,7 @@ from yolo_object_detection import yolo_object_detection -from dronekit import dronekit +from pixhawk import pixhawk def run(): os.system('python /botmlcode/yolo_object_detection.py') diff --git a/report/dronekit.py b/report/pixhawk.py similarity index 100% rename from report/dronekit.py rename to report/pixhawk.py diff --git a/report/report_folder/report.json b/report/report_folder/report.json index 8b06288..295dca2 100644 --- a/report/report_folder/report.json +++ b/report/report_folder/report.json @@ -1 +1 @@ -{"label": "metal", "confidence": 98.5, "location": [102, 71]}{"label": "metal", "confidence": 98.5, "location": [102, 71]} \ No newline at end of file +{"label": "metal", "confidence": 98.5, "location": [102, 71]}{"label": "metal", "confidence": 98.5, "location": [102, 71]}{"label": "metal", "confidence": 98.5, "location": [102, 71]}{"label": "metal", "confidence": 98.5, "location": [102, 71]} \ No newline at end of file From f7ecef6792f7d86669191c3947f50f76195ce89d Mon Sep 17 00:00:00 2001 From: Fernando Julio Cendra Date: Fri, 26 Jun 2020 11:55:59 +0800 Subject: [PATCH 03/41] updated version --- report/main.py | 25 +++++++++++++++++++------ report/pixhawk.py | 2 +- report/report.py | 10 +++++----- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/report/main.py b/report/main.py index bb71fe8..e4c0413 100644 --- a/report/main.py +++ b/report/main.py @@ -6,14 +6,27 @@ sys.path.insert(1, "/botmlcode/") - from yolo_object_detection import yolo_object_detection from pixhawk import pixhawk - -def run(): - os.system('python /botmlcode/yolo_object_detection.py') - time.sleep(60) - +from report import Report + +yolo_object_detection.run() + +while True: + if (yolo_object_detection.detected): + pixhawk.run() + time.sleep(10) + location_pixhawk = pixhawk.vehicle.do_capture_global_location() + label_yolo = yolo_object_detection.LABEL + confidence_yolo = yolo_object_detection.confidence + report = Report(label_yolo, confidence_yolo, location_pixhawk) + report.create_report() + report.print_report() + report.write_report('report_folder/report.json') + + else: + pass + diff --git a/report/pixhawk.py b/report/pixhawk.py index c5d20ed..e439bd3 100644 --- a/report/pixhawk.py +++ b/report/pixhawk.py @@ -10,7 +10,7 @@ vehicle.mode = VehicleMode("MANUAL") vehicle.armed = True -class test1(): +class pixhawk: def firmware_version(self): return vehicle.version diff --git a/report/report.py b/report/report.py index 584aaa7..452a5ee 100644 --- a/report/report.py +++ b/report/report.py @@ -37,9 +37,9 @@ def write_report(self, path): #def get_location(self): # return test1.do_capture_relative_global_location(self) -report = Report("metal", 98.5, (102, 71)) -report.print_report() -report.create_report() -report.print_report() -report.write_report('report_folder/report.json') +#report = Report("metal", 98.5, (102, 71)) +#report.print_report() +#report.create_report() +#report.print_report() +#report.write_report('report_folder/report.json') From 71adcfcd74ddabaf6add3909fd49027b6eebda58 Mon Sep 17 00:00:00 2001 From: fcendra Date: Fri, 26 Jun 2020 13:49:17 +0800 Subject: [PATCH 04/41] new commit --- report/Confidence.pyc | Bin 0 -> 655 bytes report/Label.pyc | Bin 0 -> 625 bytes report/Location.py | 10 ++---- report/Location.pyc | Bin 0 -> 981 bytes report/__pycache__/Confidence.cpython-36.pyc | Bin 0 -> 536 bytes report/__pycache__/Label.cpython-36.pyc | Bin 0 -> 506 bytes report/__pycache__/Location.cpython-36.pyc | Bin 0 -> 528 bytes report/__pycache__/pixhawk.cpython-36.pyc | Bin 0 -> 3724 bytes report/__pycache__/report.cpython-36.pyc | Bin 0 -> 1186 bytes report/main.py | 32 +++++++++---------- report/pixhawk.py | 24 +++++++++----- report/pixhawk.pyc | Bin 0 -> 4459 bytes report/report.py | 2 +- report/report_folder/report.json | 2 +- 14 files changed, 36 insertions(+), 34 deletions(-) create mode 100644 report/Confidence.pyc create mode 100644 report/Label.pyc create mode 100644 report/Location.pyc create mode 100644 report/__pycache__/Confidence.cpython-36.pyc create mode 100644 report/__pycache__/Label.cpython-36.pyc create mode 100644 report/__pycache__/Location.cpython-36.pyc create mode 100644 report/__pycache__/pixhawk.cpython-36.pyc create mode 100644 report/__pycache__/report.cpython-36.pyc create mode 100644 report/pixhawk.pyc diff --git a/report/Confidence.pyc b/report/Confidence.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f03e7a77347a5edfe2c877637eee206a6a693222 GIT binary patch literal 655 zcmbu6zfQw25XR3je=C(0i6_WH{Q?Lfx_3w>GGG6@T6qj(k)hK+X-(awI{@$#PS&cvl$B+qzHE*^bEocmp3zh~RPwtuGk8~heug}5_or*Hh2&aG!ucS`U8__G#U5&h;sysk19s+Kgg>~Otfyy-^ zoB=FREm#5Ex)?=jNxCWvv|EOK+%Rbd*a_MZnKZd7S#O>&^6@1RBM%SOEj8ClM25ge z_27G}T4$SK;iE$IuJxT&gWdWes^s^4`y5a3voY(#8nF}?4e98xWjYTm@p=ydwk7Bu+j cwt45@qErBcx2HjmlQLl7GXsEQX-Kle%yBv_V7p?ohwRpZ)HR9kb_ar1S96IKiJF+LbM}~{or0-Z!8a-e^jr@O-m=K4r15*DW3dlp>;b{kL`^7eb})N;gu1sVD~ z3onBgWJ@eo(Jw4;ir3`lwDtf1 literal 0 HcmV?d00001 diff --git a/report/__pycache__/Confidence.cpython-36.pyc b/report/__pycache__/Confidence.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..37878d86ae2dd7fa69955a2dd3ff4fafef7da13d GIT binary patch literal 536 zcmY*VJ5Iwu5S?Ay!LkSiR7hOF1-PI^C{hZ#G;}UlncWQ-`4e`X0%R(384kfkw&e^o zRGG15kPdTn$V%rhL}LcYmP#QDy{>{s?BYb|xZ=W_p6Ql$Edut9 CUv2>a literal 0 HcmV?d00001 diff --git a/report/__pycache__/Label.cpython-36.pyc b/report/__pycache__/Label.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..56ff3daa6ffbb4497d84bd27d532fd4d6dc924ad GIT binary patch literal 506 zcmY*Vy-ve05I#Fe2@wT}nFk;X8CVgj#K3~Ouw~$s#s-RPWtZ7_v7!gFX!{*(|$kH0PsbaETC*baHr&ML4gu`!n@2t$$LnHlIoL5$`%B7 zMovR66y#C~CHIgADo`QCP(`#i^U+5>(mf%7gGqUU>!< zChig?q9=WK=lk*Z=`QE<^mF^O>Hy#yFKX99dP8tdA7`$XKz{H zBdh91LvvqXA`HLh`Lk|RE^1Yp2kml1QwuFsZq!;Emyb*r>vx}UUbU6uoPMz6fNhVb ziLomfbI(Qic^(r!E=t#Yk!NvIWM^DOep|z1!TRKIxk?nM1+n-rxG0AJo zMse;_&KoT^HRXq#zi!HU=onIA4)!_e5Qa$1DA-adVM*9m@O*vzCv#fy$<@GgO}iEW Ef4awOKL7v# literal 0 HcmV?d00001 diff --git a/report/__pycache__/pixhawk.cpython-36.pyc b/report/__pycache__/pixhawk.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..03e9e0c8872e3c96872a7b856b52d073f72101ed GIT binary patch literal 3724 zcmb7{TXWk)6vriB6~}gNcJ66PdZBJgOb2F|VSq^oXv;KBn6|)-9@vq6){Yw4GOKk$ z`r1A*!w2Cz@JaN>@Wcn;g(uFDC3h26C9+57$kJc?|Lxh8wEn18tNifG-#;GJ4C7Bj z`4n+~AGhEu3}Ari83WTc2RS=8$lH0-;3niC4+SXxnzsu)2c_30FR&uyF_s<~PzLLb z0oLoBU51(GMyv7{wq&&OVY%xMhrBDp+3)$W+x7TUA9%QY;CCJA`ol+_-*LQW+{0g| z{8hCL{Io6Q`HRQT@4s-3Kd_CQT{&}H$pm-c+%9ySG1#T24-UV3aL^@_u2+!LW0H;BO2&Pw<$r15mUu!UtHqy|DbP`}47LcG5MmFZ7{I+n2Zn1q@)I&^-JNLs$s7*Apc? z8ijxEwvYV*Z)33?(eY&)w}IEiy0--%`9iiwlh*e}=b^=zJH+a;MQWL9Xqd0&WBa}2 zq@IHurSZ~?NLsnDd^#Co+7SVcZp##9)VxI#7XA$9d#)IqIfAoTw~R*<@72WnvPjQB z4HCo4+=L=8DtN@McAb&aaXnYMJh1aUIZ9z^#LP^+U`^rKOn7v{EKH&0#gpEy_M>Uf zdcqm-6tH#hiAj#JOtCz2_rj6|0Kqu3t> z?86j>x>5?%-BIk9HB~@K2Itwn@W(?4Mw~;6|BC7#saYi7RY10NAc{5vk>$AJT{sN| z2c;91J%wfZ2+#>LfRy^~0N-{gRjEzRvOqd=9Nbs@n@KG$C^8tAJC2lGq|M2Cd^)!N zSh1eYhl`R7-X(t0WBy4>r%PWydB~2Qe4<#^lip5FUEM0IdrlzPF~0R=hdWYlDd^$; zsp2>7;>D{o_|6Jv*ylZW2wdn*!)hd96V2y}dn4(sD$slDUv**~Tf>Emi}PmKO?&z^ z)#h0u-d8}jbRbh@cB1mB?@6bh2GqC!6l+=`r*(BCG}Hf#ieub`Fd5 zL`gvs*U|q#VVFK^F0_%!zA&IAeqortwpmCzNJ>V+BL!jYav7#7J%)DJi#QUgFQBFF zG4Gz>>NEOBLW9QPnL;pK3uttQtu literal 0 HcmV?d00001 diff --git a/report/__pycache__/report.cpython-36.pyc b/report/__pycache__/report.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..694e0f690e85f87a400a2404ce43562c7fd67780 GIT binary patch literal 1186 zcmZuw&2H2%5cW@!&8FFc)Cwe?fJmr&;EJkBJ#eX3q8vauV5PB36Xj=dTve>Lr!8mh zh!^0MeC5OgaN)#^y}Mm19C>EqvB%#xGk!UlBwrT4KYR-a`AK#L2m1u(a125cNgI-* zW({p=PAS^FVJ*vQx zmz7jqso*a>D=t)1;>OKjV4T1lUVu;}r;_AMQpxT}&Lx)t=)hl=hjJui_>bfmE=+86 zuI9ZqCD3vMHO4!IIXnkp$daz;k_c+pk~xc;V9A{oRs=keBoK?vvXRE)Hf#{0#?08H z+=AB_*T&77nT@o&Ity$tsOC~f;MOA)F^C^T?}7T0O|SY^P0L0V`l2^em~B(`QceBw zwK|%Awy_XZR~aGj{D6Yc#C?lLp61bJM@i8O12G}!E#D=nNljP4t7bKKI;g`H6!ts6 zrAy3&=gVdpe}EYhfF$zqM`eUh0`kfC@qZ@~2yL_2Ygu)LQF;uE8Pf?UXFK{{q_Acu zrB<*{c-s50(f0Bhf(x4p@#(r~yhl$UlE!T6$0(klxX+lguy#5Gft}zg2K9>K lam?Ln7U~1sfvIvY#yuhD`d=g)zw%Iyv7kO2OMynp{sJ{!{Xzf$ literal 0 HcmV?d00001 diff --git a/report/main.py b/report/main.py index e4c0413..fb6520f 100644 --- a/report/main.py +++ b/report/main.py @@ -1,31 +1,31 @@ -import asyncio +#import asyncio import sys import os import time -sys.path.insert(1, "/botmlcode/") +sys.path.insert(0, "/botmlcode/") -from yolo_object_detection import yolo_object_detection -from pixhawk import pixhawk +#from yolo_object_detection import yolo_object_detection +from pixhawk import Pixhawk from report import Report -yolo_object_detection.run() - +#yolo_object_detection.run() +#time.sleep(60) +count = 0 while True: - if (yolo_object_detection.detected): - pixhawk.run() - time.sleep(10) - location_pixhawk = pixhawk.vehicle.do_capture_global_location() - label_yolo = yolo_object_detection.LABEL - confidence_yolo = yolo_object_detection.confidence - report = Report(label_yolo, confidence_yolo, location_pixhawk) + if (count % 2)==0: + pixhawk = Pixhawk() + location_pixhawk = pixhawk.do_capture_global_location() + #label_yolo = yolo_object_detection.LABEL() + #confidence_yolo = yolo_object_detection.confidence() + report = Report("litter", 97, str(location_pixhawk)) report.create_report() report.print_report() report.write_report('report_folder/report.json') - - else: - pass + time.sleep(10) + count += 1 + diff --git a/report/pixhawk.py b/report/pixhawk.py index e439bd3..8b3b098 100644 --- a/report/pixhawk.py +++ b/report/pixhawk.py @@ -1,16 +1,24 @@ -try: - from dronekit import connect, VehicleMode, LocationGlobalRelative -except: - print("No module named dronekit, try to establish connection between jetson nano and mission planner") - exit(0) +#try: +# from dronekit import connect, VehicleMode, LocationGlobalRelative +#except: +# print("No module named dronekit, try to establish connection between jetson nano and mission planner") +# exit(0) # Connect to the Vehicle -vehicle = connect('/dev/ttyTHS1', wait_ready=True, baud=57600) +#vehicle = connect('/dev/ttyTHS1', wait_ready=True, baud=57600) +#vehicle.mode = VehicleMode("MANUAL") +#vehicle.armed = True +#from dronekit import connect, VehicleMode, LocationGlobalRelative +from dronekit import connect, VehicleMode, LocationGlobalRelative +vehicle = connect('/dev/ttyTHS1', wait_ready=True, baud=57600) vehicle.mode = VehicleMode("MANUAL") vehicle.armed = True - -class pixhawk: +class Pixhawk: + def __init__(self): + pass + + def firmware_version(self): return vehicle.version diff --git a/report/pixhawk.pyc b/report/pixhawk.pyc new file mode 100644 index 0000000000000000000000000000000000000000..15f50404fe038b6c051c2c0d0ed12b026c81305e GIT binary patch literal 4459 zcmb_fTaOzx6h4#eeY^MVQXxPiuAwS~f{>6v6$`Xm(RPu%iT*-L>GW+$sTdu-1ffBw#~k5B#gwUuA8KYr{`@mt{kpYoIc#9|zh zCei^#L~%f^fZ`gpY82P0Rj1(FWRHR%&^0=^Z{|qX>1jYg63}-hAk7`~WaddPkY41G zT5Ew!jr0=UG7BUZF$!gg^fKvdq*v%?qNhaPx46AZM~yWGVgKY`qt2RJWYI~J#B`in zW&In|x1Gp5O0{u&+L2>-~p*Sp)l|uTD?S{1EW)XZ+;9 zvM>bh*%eF=)6WipQYU5}il-h5lRf8qnDTkAEP{RvF~^HuVP==SvI5pIv|13~Vh^nP zo;7#_L+hm1ys|-h-7A} zQ{Z(&rnoRaof1nb30=TV4zX0&%!+MZ9ro8QV?UeVnMJ%XYZ3n(){|fX`6_bO4Rs}4 z?_9<^H4PX1E6LBpH!|!i>&8{Y!ZY}$re7|LZ=OHw4RZNj72ps~7Xx*Whh=dgCH1m& znCN_9jIIJ5V(cP1Z(Vxxh|<#TRW_>(BR2B|jBI)W@XfLSks5n8<`iB9g}6gZtVvGs zZkWGa78mwRTRCU4O11?euP|32yHyq$7&9kbnVwX^7_8lWa8G{qpjj3W))uMU$v!7z z*EY&k08Aj{-!BUZyE9Ws&vb2~O;!OOpE$iqIkEZSENruH5aM3?*5eL55#nt3}T$wt3(>dYd#Miip9;3fJ2iL&Wz#kaW^xb4-Ay}^ex4*;5v_7o;u~`)Kf~}B1B`JI%iO4Zetn-oc sI2#&&2N%d}0=dM`f3+oeFMKlL{SIc%L3lj~gL*I@tk-YUHiG5aUzwwj-v9sr literal 0 HcmV?d00001 diff --git a/report/report.py b/report/report.py index 452a5ee..f56cb7a 100644 --- a/report/report.py +++ b/report/report.py @@ -8,7 +8,7 @@ class Report: def __init__(self, label, confidence, location): self.label = Label(label) self.confidence = Confidence(confidence) - self.location = Location(location[0], location[1]) + self.location = Location(location) self.report = {} def create_report(self): diff --git a/report/report_folder/report.json b/report/report_folder/report.json index 295dca2..d02bff3 100644 --- a/report/report_folder/report.json +++ b/report/report_folder/report.json @@ -1 +1 @@ -{"label": "metal", "confidence": 98.5, "location": [102, 71]}{"label": "metal", "confidence": 98.5, "location": [102, 71]}{"label": "metal", "confidence": 98.5, "location": [102, 71]}{"label": "metal", "confidence": 98.5, "location": [102, 71]} \ No newline at end of file +{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=7.26"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=7.21"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=7.18"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=7.86"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=8.32"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=8.47"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=8.3"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=8.87"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=8.25"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=8.24"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=8.27"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=8.4"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=8.39"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=8.28"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=8.06"} \ No newline at end of file From 630a21f64581ae394d680f92c8638cba5edaa7f5 Mon Sep 17 00:00:00 2001 From: fcendra Date: Fri, 26 Jun 2020 15:16:41 +0800 Subject: [PATCH 05/41] new commit --- report/__pycache__/report.cpython-36.pyc | Bin 1186 -> 1219 bytes report/main.py | 3 ++- report/report.py | 4 ++-- report/report_folder/report.json | 1 - report/reports.py | 5 +++++ 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/report/__pycache__/report.cpython-36.pyc b/report/__pycache__/report.cpython-36.pyc index 694e0f690e85f87a400a2404ce43562c7fd67780..7d2f7b1a44037928c2f5597cc3bf6493efec06eb 100644 GIT binary patch delta 160 zcmZ3)d6<*an3tEUbl%svH5)mnGchtvUdU9;C^lJ?Sto{P`rLO#Qwd`hQw>8Fa}84pQwnnmOD_u}LpVbULm)#CLj;fxX3%8yyTzFJk_D(SM3d?2 zsb8d)sf00$sfHnoxrV8kiIE|kA%!83A&4OYNCz`$GWp$NOq@KIIe<}W@;l}TMzP5g bS;QyDu?X{UaxfRM0*%sSEfStw%i;zAT{0X$ diff --git a/report/main.py b/report/main.py index fb6520f..e60d8ad 100644 --- a/report/main.py +++ b/report/main.py @@ -23,7 +23,8 @@ report.create_report() report.print_report() report.write_report('report_folder/report.json') - time.sleep(10) + + time.sleep(5) count += 1 diff --git a/report/report.py b/report/report.py index f56cb7a..001d607 100644 --- a/report/report.py +++ b/report/report.py @@ -17,7 +17,6 @@ def create_report(self): "confidence": self.confidence.get_confidence(), "location": self.location.get_coordinate() } - self.report = report def print_report(self): @@ -25,7 +24,8 @@ def print_report(self): def write_report(self, path): with open(path, 'a') as file_stream: - json.dump(self.report, file_stream) + json.dump(self.report, file_stream, indent=4, sort_keys= True) + #def get_label(self): diff --git a/report/report_folder/report.json b/report/report_folder/report.json index d02bff3..e69de29 100644 --- a/report/report_folder/report.json +++ b/report/report_folder/report.json @@ -1 +0,0 @@ -{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=7.26"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=7.21"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=7.18"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=7.86"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=8.32"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=8.47"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=8.3"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=8.87"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=8.25"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=8.24"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=8.27"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=8.4"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=8.39"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=8.28"}{"label": "litter", "confidence": 97, "location": "LocationGlobal:lat=0.0,lon=0.0,alt=8.06"} \ No newline at end of file diff --git a/report/reports.py b/report/reports.py index e69de29..cd2c278 100644 --- a/report/reports.py +++ b/report/reports.py @@ -0,0 +1,5 @@ + + + + + From e33d01bd52eb1f56d48d700bb056e8df81224330 Mon Sep 17 00:00:00 2001 From: utkarsh867 Date: Fri, 26 Jun 2020 12:03:25 +0530 Subject: [PATCH 06/41] Adds names for the different classes --- model/clearbot.names | 128 +++++++++++++++++++++---------------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/model/clearbot.names b/model/clearbot.names index d742f21..4635999 100644 --- a/model/clearbot.names +++ b/model/clearbot.names @@ -1,64 +1,64 @@ -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter -litter \ No newline at end of file +Aerosol +Aluminium foil +Battery +Aluminium blister pack +Carded blister pack +Clear plastic bottle +Glass bottle +Other plastic bottle +Plastic bottle cap +Metal bottle cap +Broken glass +Drink can +Food Can +Corrugated carton +Drink carton +Egg carton +Meal carton +Other carton +Paper cup +Disposable plastic cup +Foam cup +Glass cup +Other plastic cup +Food waste +Plastic lid +Metal lid +Magazine paper +Tissues +Wrapping paper +Normal paper +Paper bag +Plastified paper bag +Pizza box +Garbage bag +Single-use carrier bag +Polypropylene bag +Produce bag +Cereal bag +Bread bag +Plastic film +Crisp packet +Other plastic wrapper +Retort pouch +Spread tub +Tupperware +Disposable food container +Foam food container +Other plastic container +Plastic glooves +Plastic utensils +Pop tab +Rope & strings +Scrap metal +Shoe +Six pack rings +Squeezable tube +Plastic straw +Paper straw +Styrofoam piece +Toilet tube +Unlabeled litter +Glass jar +Other plastic +Cigarette \ No newline at end of file From 550a5a981b68ffd9b150eca1f4919f6a0f8bbe63 Mon Sep 17 00:00:00 2001 From: utkarsh867 Date: Fri, 26 Jun 2020 14:04:48 +0530 Subject: [PATCH 07/41] Makes an abstraction for the YOLO object detection code --- .gitignore | 1 + model/clearbot_26_06_20.weights | 3 + yolo_object_detection.py | 299 +++++++++++++------------------- 3 files changed, 128 insertions(+), 175 deletions(-) create mode 100755 model/clearbot_26_06_20.weights diff --git a/.gitignore b/.gitignore index fb2d9db..0deda3c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .vscode/ .venv/ +.idea/ \ No newline at end of file diff --git a/model/clearbot_26_06_20.weights b/model/clearbot_26_06_20.weights new file mode 100755 index 0000000..d9f6c7f --- /dev/null +++ b/model/clearbot_26_06_20.weights @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d32f01f148ed1c663150721dd4833319cd87c38536c9c3cda57dee50a5bbf592 +size 257373000 diff --git a/yolo_object_detection.py b/yolo_object_detection.py index fef240d..10bb516 100644 --- a/yolo_object_detection.py +++ b/yolo_object_detection.py @@ -1,180 +1,129 @@ -# USAGE -# python yolo_object_detection.py --input ../example_videos/janie.mp4 --output ../output_videos/yolo_janie.avi --yolo yolo-coco --display 0 -# python yolo_object_detection.py --input ../example_videos/janie.mp4 --output ../output_videos/yolo_janie.avi --yolo yolo-coco --display 0 --use-gpu 1 - -# import the necessary packages -from imutils.video import FPS import numpy as np -import argparse import cv2 import os -# construct the argument parse and parse the arguments -ap = argparse.ArgumentParser() -ap.add_argument("-i", "--input", type=str, default="", - help="path to (optional) input video file") -ap.add_argument("-o", "--output", type=str, default="", - help="path to (optional) output video file") -ap.add_argument("-d", "--display", type=int, default=1, - help="whether or not output frame should be displayed") -ap.add_argument("-y", "--yolo", required=True, - help="base path to YOLO directory") -ap.add_argument("-c", "--confidence", type=float, default=0.5, - help="minimum probability to filter weak detections") -ap.add_argument("-t", "--threshold", type=float, default=0.3, - help="threshold when applyong non-maxima suppression") -ap.add_argument("-u", "--use-gpu", type=bool, default=0, - help="boolean indicating if CUDA GPU should be used") -args = vars(ap.parse_args()) - -# load the COCO class labels our YOLO model was trained on -labelsPath = os.path.sep.join([args["yolo"], "clearbot.names"]) -LABELS = open(labelsPath).read().strip().split("\n") - -# initialize a list of colors to represent each possible class label -np.random.seed(42) -COLORS = np.random.randint(0, 255, size=(len(LABELS), 3), - dtype="uint8") - -# derive the paths to the YOLO weights and model configuration -weightsPath = os.path.sep.join([args["yolo"], "clearbot.weights"]) -configPath = os.path.sep.join([args["yolo"], "clearbot.cfg"]) - -# load our YOLO object detector trained on COCO dataset (80 classes) -print("[INFO] loading YOLO from disk...") -net = cv2.dnn.readNetFromDarknet(configPath, weightsPath) - -# check if we are going to use GPU -if args["use_gpu"]: - # set CUDA as the preferable backend and target - print("[INFO] setting preferable backend and target to CUDA...") - net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA) - net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA) - -# determine only the *output* layer names that we need from YOLO -ln = net.getLayerNames() -ln = [ln[i[0] - 1] for i in net.getUnconnectedOutLayers()] - -# initialize the width and height of the frames in the video file -W = None -H = None - -# initialize the video stream and pointer to output video file, then -# start the FPS timer -print("[INFO] accessing video stream...") -vs = cv2.VideoCapture(args["input"] if args["input"] else 0) -writer = None -fps = FPS().start() - -# loop over frames from the video file stream -while True: - # read the next frame from the file - (grabbed, frame) = vs.read() - - # if the frame was not grabbed, then we have reached the end - # of the stream - if not grabbed: - break - - # if the frame dimensions are empty, grab them - if W is None or H is None: - (H, W) = frame.shape[:2] - # construct a blob from the input frame and then perform a forward - # pass of the YOLO object detector, giving us our bounding boxes - # and associated probabilities - blob = cv2.dnn.blobFromImage(frame, 1 / 255.0, (416, 416), - swapRB=True, crop=False) - net.setInput(blob) - layerOutputs = net.forward(ln) - - # initialize our lists of detected bounding boxes, confidences, - # and class IDs, respectively - boxes = [] - confidences = [] - classIDs = [] - - # loop over each of the layer outputs - for output in layerOutputs: - # loop over each of the detections - for detection in output: - # extract the class ID and confidence (i.e., probability) - # of the current object detection - scores = detection[5:] - classID = np.argmax(scores) - confidence = scores[classID] - - # filter out weak predictions by ensuring the detected - # probability is greater than the minimum probability - if confidence > args["confidence"]: - # scale the bounding box coordinates back relative to - # the size of the image, keeping in mind that YOLO - # actually returns the center (x, y)-coordinates of - # the bounding box followed by the boxes' width and - # height - box = detection[0:4] * np.array([W, H, W, H]) - (centerX, centerY, width, height) = box.astype("int") - - # use the center (x, y)-coordinates to derive the top - # and and left corner of the bounding box - x = int(centerX - (width / 2)) - y = int(centerY - (height / 2)) - - # update our list of bounding box coordinates, - # confidences, and class IDs - boxes.append([x, y, int(width), int(height)]) - confidences.append(float(confidence)) - classIDs.append(classID) - - # apply non-maxima suppression to suppress weak, overlapping - # bounding boxes - idxs = cv2.dnn.NMSBoxes(boxes, confidences, args["confidence"], - args["threshold"]) - - # ensure at least one detection exists - if len(idxs) > 0: - # loop over the indexes we are keeping - for i in idxs.flatten(): - # extract the bounding box coordinates - (x, y) = (boxes[i][0], boxes[i][1]) - (w, h) = (boxes[i][2], boxes[i][3]) - - # draw a bounding box rectangle and label on the frame - color = [int(c) for c in COLORS[classIDs[i]]] - cv2.rectangle(frame, (x, y), (x + w, y + h), color, 2) - text = "{}: {:.4f}".format(LABELS[classIDs[i]], - confidences[i]) - cv2.putText(frame, text, (x, y - 5), - cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2) - - # check to see if the output frame should be displayed to our - # screen - if args["display"] > 0: - # show the output frame - cv2.imshow("Frame", frame) - key = cv2.waitKey(1) & 0xFF - - # if the `q` key was pressed, break from the loop - if key == ord("q"): - break - - # if an output video file path has been supplied and the video - # writer has not been initialized, do so now - if args["output"] != "" and writer is None: - # initialize our video writer - fourcc = cv2.VideoWriter_fourcc(*"MJPG") - writer = cv2.VideoWriter(args["output"], fourcc, 30, - (frame.shape[1], frame.shape[0]), True) - - # if the video writer is not None, write the frame to the output - # video file - if writer is not None: - writer.write(frame) - - # update the FPS counter - fps.update() - -# stop the timer and display FPS information -fps.stop() -print("[INFO] elasped time: {:.2f}".format(fps.elapsed())) -print("[INFO] approx. FPS: {:.2f}".format(fps.fps())) \ No newline at end of file +class Detector: + net = None + confidence_threshold = 0 + nms_threshold = 0 + LABELS = None + ln = None + + def __init__(self, model_path, use_gpu=False, confidence_thres=0.5, nms_thres=0.3): + """ + Initialise a instance for YOLOv4 object detection. + :param model_path: The path of the model relative to the python script + :param use_gpu: Whether to use GPU CUDA or not. + :param confidence_thres: The confidence threshold of the results (0 to 1). + :param nms_thres: The NMS threshold of the results + """ + self.confidence_threshold = confidence_thres + self.nms_threshold = nms_thres + # initialize a list of colors to represent each possible class label + labels_path = os.path.sep.join([model_path, "clearbot.names"]) + self.LABELS = open(labels_path).read().strip().split("\n") + + weights_path = os.path.sep.join([model_path, "clearbot_26_06_20.weights"]) + config_path = os.path.sep.join([model_path, "clearbot.cfg"]) + print("[INFO] loading YOLO from disk...") + self.net = cv2.dnn.readNetFromDarknet(config_path, weights_path) + + if use_gpu: + # set CUDA as the preferable backend and target + print("[INFO] setting preferable backend and target to CUDA...") + self.net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA) + self.net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA) + + # determine only the *output* layer names that we need from YOLO + self.ln = self.net.getLayerNames() + self.ln = [self.ln[i[0] - 1] for i in self.net.getUnconnectedOutLayers()] + + def detect(self, frame): + """ + Detect the objects in the frame + :param frame: Frame that has been captured from the OpenCV video stream + :return: dict object with the objects and the bounding boxes + """ + + # construct a blob from the input frame and then perform a forward + # pass of the YOLO object detector, giving us our bounding boxes + # and associated probabilities + (H, W) = frame.shape[:2] + blob = cv2.dnn.blobFromImage( + frame, 1 / 255.0, (416, 416), swapRB=True, crop=False + ) + self.net.setInput(blob) + layer_outputs = self.net.forward(self.ln) + + boxes = [] + confidences = [] + class_ids = [] + + for output in layer_outputs: + # loop over each of the detections + for detection in output: + # extract the class ID and confidence (i.e., probability) + # of the current object detection + scores = detection[5:] + class_id = np.argmax(scores) + confidence = scores[class_id] + + # filter out weak predictions by ensuring the detected + # probability is greater than the minimum probability + if confidence > self.confidence_threshold: + # scale the bounding box coordinates back relative to + # the size of the image, keeping in mind that YOLO + # actually returns the center (x, y)-coordinates of + # the bounding box followed by the boxes' width and + # height + box = detection[0:4] * np.array([W, H, W, H]) + (centerX, centerY, width, height) = box.astype("int") + + # use the center (x, y)-coordinates to derive the top + # and and left corner of the bounding box + x = int(centerX - (width / 2)) + y = int(centerY - (height / 2)) + + # update our list of bounding box coordinates, + # confidences, and class IDs + boxes.append([x, y, int(width), int(height)]) + confidences.append(float(confidence)) + class_ids.append(class_id) + + # Gives the indexes of the boxes that we should use + idxs = cv2.dnn.NMSBoxes(boxes, confidences, self.confidence_threshold, self.nms_threshold) + result = [] + + # Extract the results from the detector + if len(idxs) > 0: + # loop over the indexes we are keeping + for i in idxs.flatten(): + # extract the bounding box coordinates + (x, y) = (boxes[i][0], boxes[i][1]) + (w, h) = (boxes[i][2], boxes[i][3]) + class_id = class_ids[i] + label = self.LABELS[class_id] + confidence = confidences[i] + result.append({ + "label": label, + "confidence": confidence, + "bbox": { + "x": x, + "y": y, + "width": w, + "height": h + } + }) + return result + + +# Sample code for using object detection +# print("[INFO] accessing video stream...") +# vs = cv2.VideoCapture(0) +# detector = Detector("model", use_gpu=True) +# while True: +# (grabbed, frame) = vs.read() +# if not grabbed: +# break +# result = detector.detect(frame) From 0e243299e81bd8f23482684f5e93f34b857e67ef Mon Sep 17 00:00:00 2001 From: utkarsh867 Date: Fri, 26 Jun 2020 14:10:19 +0530 Subject: [PATCH 08/41] Adds arguments for files --- yolo_object_detection.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/yolo_object_detection.py b/yolo_object_detection.py index 10bb516..349f772 100644 --- a/yolo_object_detection.py +++ b/yolo_object_detection.py @@ -10,7 +10,8 @@ class Detector: LABELS = None ln = None - def __init__(self, model_path, use_gpu=False, confidence_thres=0.5, nms_thres=0.3): + def __init__(self, model_path, use_gpu=False, confidence_thres=0.5, nms_thres=0.3, weights_file="clearbot.weights", + config_file="clearbot.cfg", names_file="clearbot.names"): """ Initialise a instance for YOLOv4 object detection. :param model_path: The path of the model relative to the python script @@ -21,11 +22,11 @@ def __init__(self, model_path, use_gpu=False, confidence_thres=0.5, nms_thres=0. self.confidence_threshold = confidence_thres self.nms_threshold = nms_thres # initialize a list of colors to represent each possible class label - labels_path = os.path.sep.join([model_path, "clearbot.names"]) + labels_path = os.path.sep.join([model_path, names_file]) self.LABELS = open(labels_path).read().strip().split("\n") - weights_path = os.path.sep.join([model_path, "clearbot_26_06_20.weights"]) - config_path = os.path.sep.join([model_path, "clearbot.cfg"]) + weights_path = os.path.sep.join([model_path, weights_file]) + config_path = os.path.sep.join([model_path, config_file]) print("[INFO] loading YOLO from disk...") self.net = cv2.dnn.readNetFromDarknet(config_path, weights_path) @@ -117,11 +118,10 @@ def detect(self, frame): }) return result - # Sample code for using object detection # print("[INFO] accessing video stream...") # vs = cv2.VideoCapture(0) -# detector = Detector("model", use_gpu=True) +# detector = Detector("model", use_gpu=True, weights_file="clearbot_26_06_20.weights") # while True: # (grabbed, frame) = vs.read() # if not grabbed: From a2d0dded64f1c44a7c39568e805c42cb69c49b26 Mon Sep 17 00:00:00 2001 From: utkarsh867 Date: Fri, 26 Jun 2020 15:16:02 +0530 Subject: [PATCH 09/41] Refactors code for optimised imports --- {model => detector/model}/clearbot.cfg | 0 {model => detector/model}/clearbot.names | 0 .../model}/clearbot_26_06_20.weights | 0 yolo_object_detection.py => detector/yolo.py | 0 report/__pycache__/Confidence.cpython-36.pyc | Bin 536 -> 0 bytes report/__pycache__/Confidence.cpython-37.pyc | Bin 529 -> 0 bytes report/__pycache__/Label.cpython-36.pyc | Bin 506 -> 0 bytes report/__pycache__/Label.cpython-37.pyc | Bin 499 -> 0 bytes report/__pycache__/Location.cpython-36.pyc | Bin 528 -> 0 bytes report/__pycache__/Location.cpython-37.pyc | Bin 774 -> 0 bytes report/__pycache__/pixhawk.cpython-36.pyc | Bin 3724 -> 0 bytes report/__pycache__/report.cpython-36.pyc | Bin 1219 -> 0 bytes report/__pycache__/test1.cpython-37.pyc | Bin 3704 -> 0 bytes 13 files changed, 0 insertions(+), 0 deletions(-) rename {model => detector/model}/clearbot.cfg (100%) rename {model => detector/model}/clearbot.names (100%) rename {model => detector/model}/clearbot_26_06_20.weights (100%) rename yolo_object_detection.py => detector/yolo.py (100%) delete mode 100644 report/__pycache__/Confidence.cpython-36.pyc delete mode 100644 report/__pycache__/Confidence.cpython-37.pyc delete mode 100644 report/__pycache__/Label.cpython-36.pyc delete mode 100644 report/__pycache__/Label.cpython-37.pyc delete mode 100644 report/__pycache__/Location.cpython-36.pyc delete mode 100644 report/__pycache__/Location.cpython-37.pyc delete mode 100644 report/__pycache__/pixhawk.cpython-36.pyc delete mode 100644 report/__pycache__/report.cpython-36.pyc delete mode 100644 report/__pycache__/test1.cpython-37.pyc diff --git a/model/clearbot.cfg b/detector/model/clearbot.cfg similarity index 100% rename from model/clearbot.cfg rename to detector/model/clearbot.cfg diff --git a/model/clearbot.names b/detector/model/clearbot.names similarity index 100% rename from model/clearbot.names rename to detector/model/clearbot.names diff --git a/model/clearbot_26_06_20.weights b/detector/model/clearbot_26_06_20.weights similarity index 100% rename from model/clearbot_26_06_20.weights rename to detector/model/clearbot_26_06_20.weights diff --git a/yolo_object_detection.py b/detector/yolo.py similarity index 100% rename from yolo_object_detection.py rename to detector/yolo.py diff --git a/report/__pycache__/Confidence.cpython-36.pyc b/report/__pycache__/Confidence.cpython-36.pyc deleted file mode 100644 index 37878d86ae2dd7fa69955a2dd3ff4fafef7da13d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 536 zcmY*VJ5Iwu5S?Ay!LkSiR7hOF1-PI^C{hZ#G;}UlncWQ-`4e`X0%R(384kfkw&e^o zRGG15kPdTn$V%rhL}LcYmP#QDy{>{s?BYb|xZ=W_p6Ql$Edut9 CUv2>a diff --git a/report/__pycache__/Confidence.cpython-37.pyc b/report/__pycache__/Confidence.cpython-37.pyc deleted file mode 100644 index e44090e1f283cdcd8b2b80838c515553a72e23b8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 529 zcmY*VJx{|h5Is9di6Y7X6A}|!76wLyP(_j0y1*1gSjBcxP(F&C4xnu9pW!cgvg< z!k(eikT3-aS4{C8B%bn=kI`2F?oC`YugX=XbSbr@Ju-@fIl_{thBY9N6*t%-W{zbs zcfQs6%Fx^=7$3v$`Q26eT-8M`E2UGT*OjR+(|>}C^}7p&$jYo1f)*_~U>_%=nZ7R> z_0T91S~U|)8hGuMwDd7Ebe~p3=K_4XqZeHZIsA@lJ>ThwZ+~hL2PCmv7Fq}w2~kvP xlT&^u#M@?>cO64I%)ve@-M|oy=_Ok#g)H>i3SO>_Bca2J3$Ht-8`}Lwz#kBCY6buR diff --git a/report/__pycache__/Label.cpython-36.pyc b/report/__pycache__/Label.cpython-36.pyc deleted file mode 100644 index 56ff3daa6ffbb4497d84bd27d532fd4d6dc924ad..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 506 zcmY*Vy-ve05I#Fe2@wT}nFk;X8CVgj#K3~Ouw~$s#s-RPWtZ7_v7!gFX!{*(|$kH0PsbaETC*baHr&ML4gu`!n@2t$$LnHlIoL5$`%B7 zMovR66y#C~CHIgADo`QCP(`#i^U+4_@%cOZaxxhM+2j59gCqXrq_=>ADZw3*y8#7CYzgl&1tsqw2@0wYCMlW{ z+z~kqsZfwgC6wGk8mK^p#G#64Zseoee6CHwBW%o!D}v*F8qolfARQL7M0l}Dqz|1o zPnOSpfDMU$j<3(Mc~zIDsFcpEURAa}&Dy(9R&PE=Tr3wgBF{K>AU6A5yKfbO%Vf-q zc83uK4ZQUFt!N@Fe@Ls`xrkD~`>bm;{2Weum4i-Y=*^Od*IDMJM)YIEvQlfq@gCyq sIyYU%vasFxFT+o@e7Ws+bX9JCespqBq^HjMcAyi>a1*)Ib80$jdbf&c&j diff --git a/report/__pycache__/Location.cpython-36.pyc b/report/__pycache__/Location.cpython-36.pyc deleted file mode 100644 index 7ced60307e6229f30d85336ca3e3a286b2634a55..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 528 zcmY*Vy-ve05I*OpL=i=Tg@qT0kjTJ_P$dQy)P*fWtza7nO5$R>5>(mf%7gGqUU>!< zChig?q9=WK=lk*Z=`QE<^mF^O>Hy#yFKX99dP8tdA7`$XKz{H zBdh91LvvqXA`HLh`Lk|RE^1Yp2kml1QwuFsZq!;Emyb*r>vx}UUbU6uoPMz6fNhVb ziLomfbI(Qic^(r!E=t#Yk!NvIWM^DOep|z1!TRKIxk?nM1+n-rxG0AJo zMse;_&KoT^HRXq#zi!HU=onIA4)!_e5Qa$1DA-adVM*9m@O*vzCv#fy$<@GgO}iEW Ef4awOKL7v# diff --git a/report/__pycache__/Location.cpython-37.pyc b/report/__pycache__/Location.cpython-37.pyc deleted file mode 100644 index c14abae7969271a7fbd964481875abaeaafbb028..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 774 zcma)4OH0E*5T4yUx-D%{FJ8R{#DfP9B2rZFqP=(v#U*A_iKI#0q|lVy?4R*3oB_PiM@E8BT~PcE9K*-= zhB#USW#1f@>&4nW#-=DI2w=T1ud{RU7McN^z6;UKS>?Pnblcsp2Ja zx`U!%1xP43O00}oZ0PWk%}bU$Mro!&G}e@$Df1Pyh3fO*>U8vwWRu8GR4~%PG|}1d zs0KTl=B1D_jKfSy%1uoaz-+eIZDMM_kK3t;G;!6LjYa`a-~F(v1BYp zpd$5L`x|quV}?$P_8ohZK+3Ws@Wcn;g(uFDC3h26C9+57$kJc?|Lxh8wEn18tNifG-#;GJ4C7Bj z`4n+~AGhEu3}Ari83WTc2RS=8$lH0-;3niC4+SXxnzsu)2c_30FR&uyF_s<~PzLLb z0oLoBU51(GMyv7{wq&&OVY%xMhrBDp+3)$W+x7TUA9%QY;CCJA`ol+_-*LQW+{0g| z{8hCL{Io6Q`HRQT@4s-3Kd_CQT{&}H$pm-c+%9ySG1#T24-UV3aL^@_u2+!LW0H;BO2&Pw<$r15mUu!UtHqy|DbP`}47LcG5MmFZ7{I+n2Zn1q@)I&^-JNLs$s7*Apc? z8ijxEwvYV*Z)33?(eY&)w}IEiy0--%`9iiwlh*e}=b^=zJH+a;MQWL9Xqd0&WBa}2 zq@IHurSZ~?NLsnDd^#Co+7SVcZp##9)VxI#7XA$9d#)IqIfAoTw~R*<@72WnvPjQB z4HCo4+=L=8DtN@McAb&aaXnYMJh1aUIZ9z^#LP^+U`^rKOn7v{EKH&0#gpEy_M>Uf zdcqm-6tH#hiAj#JOtCz2_rj6|0Kqu3t> z?86j>x>5?%-BIk9HB~@K2Itwn@W(?4Mw~;6|BC7#saYi7RY10NAc{5vk>$AJT{sN| z2c;91J%wfZ2+#>LfRy^~0N-{gRjEzRvOqd=9Nbs@n@KG$C^8tAJC2lGq|M2Cd^)!N zSh1eYhl`R7-X(t0WBy4>r%PWydB~2Qe4<#^lip5FUEM0IdrlzPF~0R=hdWYlDd^$; zsp2>7;>D{o_|6Jv*ylZW2wdn*!)hd96V2y}dn4(sD$slDUv**~Tf>Emi}PmKO?&z^ z)#h0u-d8}jbRbh@cB1mB?@6bh2GqC!6l+=`r*(BCG}Hf#ieub`Fd5 zL`gvs*U|q#VVFK^F0_%!zA&IAeqortwpmCzNJ>V+BL!jYav7#7J%)DJi#QUgFQBFF zG4Gz>>NEOBLW9QPnL;pK3uttQtu diff --git a/report/__pycache__/report.cpython-36.pyc b/report/__pycache__/report.cpython-36.pyc deleted file mode 100644 index 7d2f7b1a44037928c2f5597cc3bf6493efec06eb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1219 zcmZuw&2H2%5cW@!&8E8r34{bsKqS;Xa79(69=KF1QIJ46V5PB36Y{e-URABq)AovZ z0mL1NC-Rk3AAk!dX6)^FdCeM@F=q!gZ+ONjc}Zj_qiZ6g70UuiUz2on12M=vr8Yk5irkc43wCnY zwWp<2ZK2>VJjzd0UEs#s!N53x**^oJNJb^en52?jlZ;C)1JHrLEDPmG#_%7>F{}25O9V2(y0*!jOTk=s*NDY+%mfCK$N0!jga|k_2MWc{ zxE*T@j}QX}CG_&a`u1&q;e6o6PME@UN!|kkn@Z9Z`|{+98Co%b!UrZ9HtXkrlDF_` zUXf$+4m5xZ=a%L-Sf)2Avr*Z?V=#8yL*t5%>Y~RM>K3ZCLDhF4<+53L7TmG0!6G+j z+0JQME72RsV{hU^4Cx5AJ?|@#%c5CxS31JfjS2e$o`nct diff --git a/report/__pycache__/test1.cpython-37.pyc b/report/__pycache__/test1.cpython-37.pyc deleted file mode 100644 index c3e6617c4fb29462a465d78e619d12d587acf79a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3704 zcmb7HOK;mo5GJV?t(PB?-*&>(Nm`{w-LxoBphXb(<)TSkph;guTY}Q8WZD#|E?0Ks ztApP9LwfJ8;jQSY=iYki3`sdFi!>|>oT0Ga?)UA?a(DPityWg>`tALHe|cF|l)vfE z_$uPVW4wbdn$a34pt?$5HPyamYWz0vLJsm! zfa32tv&b|kU8t;Rl^~B+KTtr2xmOCzU1;VUl%FfD%0I}Zv~ppo<9it@06YYeCQi}ABHY7JiE`p0PcJ2#1XrO;3Gr$1`CAU zcAenJNCw71j5ZTzjCsZ}69NA9Y|l4r4~)JO1k^roZ4|-Jt9!ss_k!cprbDWMgx5bDo{nQLk;Ta=U^Td(3fEmme5zA0ZsH(ScVn!HCTl;^mSN=4fOM{ z30vqFU>k0sUxeFWpkIPJ@CNz@?7&_0O}Gd5(J#ZB@D}iJ3xy9!B{rDGS8b*#n0a-4*k)s8)|+m7o9 zhXrP?D+Vo<6E@No8+s$cW-<*+?y!h0V>KJGnl#ufibCB@mb6*zMT^?%a$Le0vNpgc zMPi5{O5o%EO-Y;)i^~SjB9Yf{WOF&8^LpAt1j%_8EIVS*en%1EdzVhr8BR>T-JgNQV^Xfry)q(Fi(4%`u*5KEN$ia{4ioJ&(3aY^5R7N7#Cp=45bsLF$vT(> z%)ne^Ctb@w$(V5Q^Cw?eUq9KC2&?f-}~sgmuJhF51i%>4ba@nckDwlIczM zoq@H&ZLi0=jt7jVQ-;+DV#SybB<`hnrgC#SbNYeC*KsVY4;)-AUMFj(Tb75n#^4Vn z8Jp8GE^)K#DV_SRuzOi@niFyo>_?KCmYo zEkWsG@Rh`$ob@TF!`51;TajSP3d@!ie`nxx)v|sa+AdASvUmkYG7U0RrtxJmD`cn&iZ&!pr3c?6vqgrMC%;98lEvvf5iJ?2R(SypRcXNk zG`gziZuX1%9k$B2fh6BcoN8^JBa=rH76#n$M3`qU9T8Pk{0_C}H`Q`gj@s;l)}T`Q|a?SBCoB<=tJ From 55ff55606827dfa4f67a401692a9db1bf859fd8a Mon Sep 17 00:00:00 2001 From: utkarsh867 Date: Fri, 26 Jun 2020 15:16:02 +0530 Subject: [PATCH 10/41] Refactors code for optimised imports --- .gitignore | 3 +- detector/__init__.py | 0 detector/yolo.py | 6 +-- main.py | 15 ++++++ report/Location.py | 1 - report/__init__.py | 0 report/main.py | 47 +++++------------ report/pixhawk.py | 121 +++++++++++++++++++------------------------ report/report.py | 8 +-- report/reports.py | 5 -- 10 files changed, 90 insertions(+), 116 deletions(-) create mode 100644 detector/__init__.py create mode 100644 main.py create mode 100644 report/__init__.py diff --git a/.gitignore b/.gitignore index 0deda3c..2732f71 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .vscode/ .venv/ -.idea/ \ No newline at end of file +.idea/ +__pycache__/ \ No newline at end of file diff --git a/detector/__init__.py b/detector/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/detector/yolo.py b/detector/yolo.py index 349f772..9cf57e0 100644 --- a/detector/yolo.py +++ b/detector/yolo.py @@ -22,11 +22,11 @@ def __init__(self, model_path, use_gpu=False, confidence_thres=0.5, nms_thres=0. self.confidence_threshold = confidence_thres self.nms_threshold = nms_thres # initialize a list of colors to represent each possible class label - labels_path = os.path.sep.join([model_path, names_file]) + labels_path = os.path.sep.join([os.path.dirname(os.path.realpath(__file__)), model_path, names_file]) self.LABELS = open(labels_path).read().strip().split("\n") - weights_path = os.path.sep.join([model_path, weights_file]) - config_path = os.path.sep.join([model_path, config_file]) + weights_path = os.path.sep.join([os.path.dirname(os.path.realpath(__file__)), model_path, weights_file]) + config_path = os.path.sep.join([os.path.dirname(os.path.realpath(__file__)), model_path, config_file]) print("[INFO] loading YOLO from disk...") self.net = cv2.dnn.readNetFromDarknet(config_path, weights_path) diff --git a/main.py b/main.py new file mode 100644 index 0000000..4ada071 --- /dev/null +++ b/main.py @@ -0,0 +1,15 @@ +from detector import yolo +import cv2 + +""" +Sample code importing the detector module +""" +print("[INFO] accessing video stream...") +vs = cv2.VideoCapture(0) +detector = yolo.Detector("model", use_gpu=True, weights_file="clearbot_26_06_20.weights") +while True: + (grabbed, frame) = vs.read() + if not grabbed: + break + result = detector.detect(frame) + print(result) \ No newline at end of file diff --git a/report/Location.py b/report/Location.py index 05a7a2f..1643b98 100644 --- a/report/Location.py +++ b/report/Location.py @@ -4,4 +4,3 @@ def __init__(self, x): def get_coordinate(self): return self.x - diff --git a/report/__init__.py b/report/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/report/main.py b/report/main.py index e60d8ad..ce350e5 100644 --- a/report/main.py +++ b/report/main.py @@ -1,40 +1,17 @@ -#import asyncio -import sys -import os import time +from .pixhawk import Pixhawk +from .report import Report -sys.path.insert(0, "/botmlcode/") - -#from yolo_object_detection import yolo_object_detection -from pixhawk import Pixhawk -from report import Report - -#yolo_object_detection.run() -#time.sleep(60) count = 0 while True: - if (count % 2)==0: - pixhawk = Pixhawk() - location_pixhawk = pixhawk.do_capture_global_location() - #label_yolo = yolo_object_detection.LABEL() - #confidence_yolo = yolo_object_detection.confidence() - report = Report("litter", 97, str(location_pixhawk)) - report.create_report() - report.print_report() - report.write_report('report_folder/report.json') - - time.sleep(5) - count += 1 - - - - - - - - - - - - + if (count % 2) == 0: + pixhawk = Pixhawk() + location_pixhawk = pixhawk.do_capture_global_location() + report = Report("litter", 97, str(location_pixhawk)) + report.create_report() + report.print_report() + report.write_report('report_folder/report.json') + + time.sleep(5) + count += 1 diff --git a/report/pixhawk.py b/report/pixhawk.py index 8b3b098..3c710fb 100644 --- a/report/pixhawk.py +++ b/report/pixhawk.py @@ -1,110 +1,97 @@ -#try: -# from dronekit import connect, VehicleMode, LocationGlobalRelative -#except: -# print("No module named dronekit, try to establish connection between jetson nano and mission planner") -# exit(0) - -# Connect to the Vehicle -#vehicle = connect('/dev/ttyTHS1', wait_ready=True, baud=57600) - -#vehicle.mode = VehicleMode("MANUAL") -#vehicle.armed = True -#from dronekit import connect, VehicleMode, LocationGlobalRelative from dronekit import connect, VehicleMode, LocationGlobalRelative -vehicle = connect('/dev/ttyTHS1', wait_ready=True, baud=57600) -vehicle.mode = VehicleMode("MANUAL") -vehicle.armed = True + + class Pixhawk: - def __init__(self): - pass - - + vehicle = None + + def __init__(self, connection_port="/dev/ttyTHS1", baud=57600): + self.vehicle = connect(connection_port, wait_ready=True, baud=baud) + self.vehicle.mode = VehicleMode("MANUAL") + self.vehicle.armed = True + def firmware_version(self): - return vehicle.version + return self.vehicle.version def vehicle_capabilities(self): - return vehicle.capabilities.ftp + return self.vehicle.capabilities.ftp def do_capture_global_location(self): - return vehicle.location.global_frame + return self.vehicle.location.global_frame def do_capture_relative_global_location(self): - return vehicle.location.global_relative_frame + return self.vehicle.location.global_relative_frame def do_capture_altitude(self): - return vehicle.altitude + return self.vehicle.altitude def do_capture_velocity(self): - return vehicle.velocity + return self.vehicle.velocity def do_capture_gps(self): - return vehicle.gps_0 + return self.vehicle.gps_0 def do_capture_ground_speed(self): - return vehicle.groundspeed + return self.vehicle.groundspeed def do_capture_air_speed(self): - return vehicle.airspeed + return self.vehicle.airspeed def gimbal_status(self): - return vehicle.gimbal + return self.vehicle.gimbal def battery_status(self): - return vehicle.battery + return self.vehicle.battery def EKF_OK(self): - return vehicle.ekf_ok + return self.vehicle.ekf_ok def last_heartbeat(self): - return vehicle.last_heartbeat + return self.vehicle.last_heartbeat def range_finder(self): - return vehicle.rangefinder + return self.vehicle.rangefinder def range_finder_distance(self): - return vehicle.rangefinder.distance + return self.vehicle.rangefinder.distance def range_finder_voltage(self): - return vehicle.rangefinder.voltage + return self.vehicle.rangefinder.voltage def heading(self): - return vehicle.heading + return self.vehicle.heading def vehicle_is_armable(self): - return vehicle.is_armable + return self.vehicle.is_armable def system_status(self): - return vehicle.system_status.state + return self.vehicle.system_status.state def vehicle_mode_name(self): - return vehicle.mode.name + return self.vehicle.mode.name def check_vehicle_armed(self): - return vehicle.armed - - - - -# vehicle is an instance of the Vehicle class -#print('Autopilot Firmware version: %s' % vehicle.version) -#print('Autopilot capabilities (supports ftp): %s' % vehicle.capabilities.ftp) -#print('Global Location: %s' % vehicle.location.global_frame) -#print('Global Location (relative altitude): %s' % vehicle.location.global_relative_frame) -#print('Local Location: %s' % vehicle.location.local_frame) #NED -#print('Attitude: %s' % vehicle.attitude) -#print('Velocity: %s' % vehicle.velocity) -#print('GPS: %s' % vehicle.gps_0) -#print('Groundspeed: %s' % vehicle.groundspeed) -#print('Airspeed: %s' % vehicle.airspeed) -#print('Gimbal status: %s' % vehicle.gimbal) -#print('Battery: %s' % vehicle.battery) -#print('EKF OK?: %s' % vehicle.ekf_ok) -#print('Last Heartbeat: %s' % vehicle.last_heartbeat) -#print('Rangefinder: %s' % vehicle.rangefinder) -#print('Rangefinder distance: %s' % vehicle.rangefinder.distance) -#print('Rangefinder voltage: %s' % vehicle.rangefinder.voltage) -#print('Heading: %s' % vehicle.heading) -#print('Is Armable?: %s' % vehicle.is_armable) -#print('System status: %s' % vehicle.system_status.state) -#print('Mode: %s' % vehicle.mode.name) # settable -#print('Armed: %s' % vehicle.armed) # settable \ No newline at end of file + return self.vehicle.armed + + def debug(self): + print('Autopilot Firmware version: %s' % self.vehicle.version) + print('Autopilot capabilities (supports ftp): %s' % self.vehicle.capabilities.ftp) + print('Global Location: %s' % self.vehicle.location.global_frame) + print('Global Location (relative altitude): %s' % self.vehicle.location.global_relative_frame) + print('Local Location: %s' % self.vehicle.location.local_frame) + print('Attitude: %s' % self.vehicle.attitude) + print('Velocity: %s' % self.vehicle.velocity) + print('GPS: %s' % self.vehicle.gps_0) + print('Groundspeed: %s' % self.vehicle.groundspeed) + print('Airspeed: %s' % self.vehicle.airspeed) + print('Gimbal status: %s' % self.vehicle.gimbal) + print('Battery: %s' % self.vehicle.battery) + print('EKF OK?: %s' % self.vehicle.ekf_ok) + print('Last Heartbeat: %s' % self.vehicle.last_heartbeat) + print('Rangefinder: %s' % self.vehicle.rangefinder) + print('Rangefinder distance: %s' % self.vehicle.rangefinder.distance) + print('Rangefinder voltage: %s' % self.vehicle.rangefinder.voltage) + print('Heading: %s' % self.vehicle.heading) + print('Is Armable?: %s' % self.vehicle.is_armable) + print('System status: %s' % self.vehicle.system_status.state) + print('Mode: %s' % self.vehicle.mode.name) + print('Armed: %s' % self.vehicle.armed) diff --git a/report/report.py b/report/report.py index 001d607..fadd184 100644 --- a/report/report.py +++ b/report/report.py @@ -1,8 +1,9 @@ import json -from Location import Location -from Confidence import Confidence -from Label import Label +from .Location import Location +from .Confidence import Confidence +from .Label import Label + class Report: def __init__(self, label, confidence, location): @@ -42,4 +43,3 @@ def write_report(self, path): #report.create_report() #report.print_report() #report.write_report('report_folder/report.json') - diff --git a/report/reports.py b/report/reports.py index cd2c278..e69de29 100644 --- a/report/reports.py +++ b/report/reports.py @@ -1,5 +0,0 @@ - - - - - From f49c7a52abc29401f517028dffd290179045b940 Mon Sep 17 00:00:00 2001 From: utkarsh867 Date: Fri, 26 Jun 2020 15:58:15 +0530 Subject: [PATCH 11/41] Adds deleted weights from the repo --- detector/model/clearbot.weights | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 detector/model/clearbot.weights diff --git a/detector/model/clearbot.weights b/detector/model/clearbot.weights new file mode 100644 index 0000000..8156a77 --- /dev/null +++ b/detector/model/clearbot.weights @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fdb7cd1bb42f6d1abfa579d0d9b81137ed5b5e8bc0749901b8aa216891c2c671 +size 257373000 From 5f7b8a39d32485db4b14210f55dc219168d485d6 Mon Sep 17 00:00:00 2001 From: utkarsh867 Date: Fri, 26 Jun 2020 16:00:55 +0530 Subject: [PATCH 12/41] Updates README --- README.md | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/README.md b/README.md index b983104..6efba54 100644 --- a/README.md +++ b/README.md @@ -48,15 +48,7 @@ Now, for the last step, make sure that you have `.venv` active using the command If the above runs without errors, you have installed things correctly. -#### Running the code on the Jetson Nano for detection - -To run the detection, use the commands: - -```bash -python yolo_object_detection.py -y model -``` - -This should pull up a screen with the live feed from the camera. +### Misc instructions if you have not compiled OpenCV yet #### OpenCV compile CMake From 5bb04c20d172e0316671c0b644fc277f224938e4 Mon Sep 17 00:00:00 2001 From: Fernando Julio Cendra Date: Sat, 27 Jun 2020 16:30:48 +0800 Subject: [PATCH 13/41] add some features --- report/main.py | 9 +++++++-- report/pixhawk.py | 1 - report/report.py | 14 +++++++++----- report/report_folder/report.json | 5 +++++ report/report_folder/reports.json | 19 +++++++++++++++++++ report/reports.py | 31 +++++++++++++++++++++++++++++++ 6 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 report/report_folder/reports.json diff --git a/report/main.py b/report/main.py index ce350e5..f24ddf1 100644 --- a/report/main.py +++ b/report/main.py @@ -2,8 +2,13 @@ from .pixhawk import Pixhawk from .report import Report +from .reports import Reports + +report_path = 'report_folder/report.json' +reports_path = 'report_folder/reports.json' count = 0 +reports = Reports() while True: if (count % 2) == 0: pixhawk = Pixhawk() @@ -11,7 +16,7 @@ report = Report("litter", 97, str(location_pixhawk)) report.create_report() report.print_report() - report.write_report('report_folder/report.json') - + report.write_report(report_path) + reports.combine(reports_path) time.sleep(5) count += 1 diff --git a/report/pixhawk.py b/report/pixhawk.py index 3c710fb..3f840d2 100644 --- a/report/pixhawk.py +++ b/report/pixhawk.py @@ -1,6 +1,5 @@ from dronekit import connect, VehicleMode, LocationGlobalRelative - class Pixhawk: vehicle = None diff --git a/report/report.py b/report/report.py index fadd184..ec38905 100644 --- a/report/report.py +++ b/report/report.py @@ -1,8 +1,12 @@ import json -from .Location import Location -from .Confidence import Confidence -from .Label import Label +#from .Location import Location +#from .Confidence import Confidence +#from .Label import Label + +from Location import Location +from Confidence import Confidence +from Label import Label class Report: @@ -24,7 +28,7 @@ def print_report(self): print(self.report) def write_report(self, path): - with open(path, 'a') as file_stream: + with open(path, 'w') as file_stream: json.dump(self.report, file_stream, indent=4, sort_keys= True) @@ -38,7 +42,7 @@ def write_report(self, path): #def get_location(self): # return test1.do_capture_relative_global_location(self) -#report = Report("metal", 98.5, (102, 71)) +#report = Report("metal", 98.5, "hi") #report.print_report() #report.create_report() #report.print_report() diff --git a/report/report_folder/report.json b/report/report_folder/report.json index e69de29..c721859 100644 --- a/report/report_folder/report.json +++ b/report/report_folder/report.json @@ -0,0 +1,5 @@ +{ + "confidence": 97, + "label": "litter", + "location": "hello" +} \ No newline at end of file diff --git a/report/report_folder/reports.json b/report/report_folder/reports.json new file mode 100644 index 0000000..1a2ec65 --- /dev/null +++ b/report/report_folder/reports.json @@ -0,0 +1,19 @@ +{ + "Clearbot": [ + { + "confidence": 97, + "label": "litter", + "location": "hello" + }, + { + "confidence": 97, + "label": "litter", + "location": "hello" + }, + { + "confidence": 97, + "label": "litter", + "location": "hello" + } + ] +} \ No newline at end of file diff --git a/report/reports.py b/report/reports.py index e69de29..fc49ea7 100644 --- a/report/reports.py +++ b/report/reports.py @@ -0,0 +1,31 @@ +from pathlib import Path +import json + +data_folder = Path("report_folder/") +file_to_open = data_folder / "report.json" + +class Reports: + + def __init__(self): + self.json_object= {} + self.reports_array= [] + + def combine(self, path): + with open(file_to_open, 'r') as open_file: + self.json_object= json.load(open_file) + + with open(path, 'r') as file_stream: + reports_json = json.load(file_stream) + + if(reports_json.get("Clearbot") != None): + self.reports_array = reports_json["Clearbot"] + self.reports_array.append(self.json_object) + else: + self.reports_array = [self.json_object] + + with open(path, 'w') as write_file: + json.dump({ 'Clearbot': self.reports_array }, write_file, indent=4, sort_keys=True) + + + + \ No newline at end of file From 1b472dd3c98f68954984bd2c50d0c86c79816529 Mon Sep 17 00:00:00 2001 From: Fernando Julio Cendra Date: Sat, 27 Jun 2020 21:10:07 +0800 Subject: [PATCH 14/41] yolo.py functions has been added to main.py --- report/Confidence.py | 6 +++--- report/Label.py | 6 +++--- report/Location.py | 6 +++--- report/main.py | 24 +++++++++++++++++++----- report/report.py | 32 ++++++-------------------------- 5 files changed, 34 insertions(+), 40 deletions(-) diff --git a/report/Confidence.py b/report/Confidence.py index 66923a4..6afe48d 100644 --- a/report/Confidence.py +++ b/report/Confidence.py @@ -1,7 +1,7 @@ class Confidence: - def __init__(self, i): - self.i = i + def __init__(self, y): + self.y = y[1] def get_confidence(self): - return self.i + return self.y \ No newline at end of file diff --git a/report/Label.py b/report/Label.py index 24427ef..b10d5d7 100644 --- a/report/Label.py +++ b/report/Label.py @@ -1,6 +1,6 @@ class Label: - def __init__(self, z): - self.z = z + def __init__(self, x): + self.x = x[0] def get_label(self): - return self.z \ No newline at end of file + return self.x \ No newline at end of file diff --git a/report/Location.py b/report/Location.py index 1643b98..ca12f86 100644 --- a/report/Location.py +++ b/report/Location.py @@ -1,6 +1,6 @@ class Location: - def __init__(self, x): - self.x = x + def __init__(self, z): + self.z = z def get_coordinate(self): - return self.x + return self.z diff --git a/report/main.py b/report/main.py index f24ddf1..538cfe7 100644 --- a/report/main.py +++ b/report/main.py @@ -1,4 +1,6 @@ import time +import cv2 +from detector import yolo from .pixhawk import Pixhawk from .report import Report @@ -7,16 +9,28 @@ report_path = 'report_folder/report.json' reports_path = 'report_folder/reports.json' -count = 0 +print("[INFO] accessing video stream...") +vs = cv2.VideoCapture(0) +detector = yolo.Detector("model", use_gpu=True, weights_file="clearbot_26_06_20.weights") + reports = Reports() +previous = 0 + while True: - if (count % 2) == 0: + (grabbed, frame) = vs.read() + if not grabbed: + break + result = detector.detect(frame) + current = len(result) + if (current > 0 and current > previous): + result_object = result[current - 1] pixhawk = Pixhawk() - location_pixhawk = pixhawk.do_capture_global_location() - report = Report("litter", 97, str(location_pixhawk)) + yolo_result = result_object + pixhawk_location = str(pixhawk.do_capture_global_location()) + report = Report(yolo_result, pixhawk_location) report.create_report() report.print_report() report.write_report(report_path) reports.combine(reports_path) + previous = current time.sleep(5) - count += 1 diff --git a/report/report.py b/report/report.py index ec38905..ef331fd 100644 --- a/report/report.py +++ b/report/report.py @@ -1,18 +1,14 @@ import json -#from .Location import Location -#from .Confidence import Confidence -#from .Label import Label - -from Location import Location -from Confidence import Confidence -from Label import Label +from .Location import Location +from .Confidence import Confidence +from .Label import Label class Report: - def __init__(self, label, confidence, location): - self.label = Label(label) - self.confidence = Confidence(confidence) + def __init__(self, yolo, location): + self.label = Label(yolo) + self.confidence = Confidence(yolo) self.location = Location(location) self.report = {} @@ -31,19 +27,3 @@ def write_report(self, path): with open(path, 'w') as file_stream: json.dump(self.report, file_stream, indent=4, sort_keys= True) - - - #def get_label(self): - # return yolo_object_detection.LABELS - - #def get_confidence(self): - # return yolo_object_detection.confidence - - #def get_location(self): - # return test1.do_capture_relative_global_location(self) - -#report = Report("metal", 98.5, "hi") -#report.print_report() -#report.create_report() -#report.print_report() -#report.write_report('report_folder/report.json') From dabbb66f1fe7814dbcd82159e77eaa75e560412e Mon Sep 17 00:00:00 2001 From: Fernando Julio Cendra Date: Mon, 29 Jun 2020 22:16:47 +0800 Subject: [PATCH 15/41] Adding some features in report.py --- main.py | 47 +++++++++++++--- report/clearbot_attributes/Air_speed.py | 7 +++ report/clearbot_attributes/Altitude.py | 7 +++ report/clearbot_attributes/Battery_status.py | 7 +++ .../Check_vehicle_armed.py | 6 +++ .../{ => clearbot_attributes}/Confidence.py | 2 +- .../{ => clearbot_attributes}/Confidence.pyc | Bin report/clearbot_attributes/Ekf_ok.py | 6 +++ .../clearbot_attributes/Firmware_version.py | 7 +++ report/clearbot_attributes/Gimbal_status.py | 7 +++ report/clearbot_attributes/Gps.py | 7 +++ report/clearbot_attributes/Ground_speed.py | 7 +++ report/clearbot_attributes/Heading.py | 6 +++ report/{ => clearbot_attributes}/Label.py | 2 +- report/{ => clearbot_attributes}/Label.pyc | Bin report/clearbot_attributes/Last_heartbeat.py | 6 +++ report/{ => clearbot_attributes}/Location.py | 2 +- report/{ => clearbot_attributes}/Location.pyc | Bin .../Range_finder_distance.py | 6 +++ .../Range_finder_voltage.py | 6 +++ report/clearbot_attributes/System_status.py | 6 +++ .../Vehicle_capabilties.py | 7 +++ .../clearbot_attributes/Vehicle_is_armable.py | 6 +++ .../clearbot_attributes/Vehicle_mode_name.py | 6 +++ report/clearbot_attributes/Velocity.py | 7 +++ report/clearbot_attributes/__init__.py | 4 ++ report/pixhawk.py | 28 +++++++++- report/report.py | 51 ++++++++++++++---- 28 files changed, 234 insertions(+), 19 deletions(-) create mode 100644 report/clearbot_attributes/Air_speed.py create mode 100644 report/clearbot_attributes/Altitude.py create mode 100644 report/clearbot_attributes/Battery_status.py create mode 100644 report/clearbot_attributes/Check_vehicle_armed.py rename report/{ => clearbot_attributes}/Confidence.py (76%) rename report/{ => clearbot_attributes}/Confidence.pyc (100%) create mode 100644 report/clearbot_attributes/Ekf_ok.py create mode 100644 report/clearbot_attributes/Firmware_version.py create mode 100644 report/clearbot_attributes/Gimbal_status.py create mode 100644 report/clearbot_attributes/Gps.py create mode 100644 report/clearbot_attributes/Ground_speed.py create mode 100644 report/clearbot_attributes/Heading.py rename report/{ => clearbot_attributes}/Label.py (76%) rename report/{ => clearbot_attributes}/Label.pyc (100%) create mode 100644 report/clearbot_attributes/Last_heartbeat.py rename report/{ => clearbot_attributes}/Location.py (76%) rename report/{ => clearbot_attributes}/Location.pyc (100%) create mode 100644 report/clearbot_attributes/Range_finder_distance.py create mode 100644 report/clearbot_attributes/Range_finder_voltage.py create mode 100644 report/clearbot_attributes/System_status.py create mode 100644 report/clearbot_attributes/Vehicle_capabilties.py create mode 100644 report/clearbot_attributes/Vehicle_is_armable.py create mode 100644 report/clearbot_attributes/Vehicle_mode_name.py create mode 100644 report/clearbot_attributes/Velocity.py create mode 100644 report/clearbot_attributes/__init__.py diff --git a/main.py b/main.py index 4ada071..c1319ac 100644 --- a/main.py +++ b/main.py @@ -1,15 +1,50 @@ -from detector import yolo +import time import cv2 +from detector import yolo +from report import report +from report import reports +from report import pixhawk + +report_path = 'report/report_folder/report.json' +reports_path = 'report/report_folder/reports.json' -""" -Sample code importing the detector module -""" print("[INFO] accessing video stream...") -vs = cv2.VideoCapture(0) +vs = cv2.VideoCapture(1) detector = yolo.Detector("model", use_gpu=True, weights_file="clearbot_26_06_20.weights") + +reports = reports.Reports() +previous = 0 + while True: (grabbed, frame) = vs.read() if not grabbed: break result = detector.detect(frame) - print(result) \ No newline at end of file + current = len(result) + if (current > 0 and current > previous): + result_object = result[current - 1] + pixhawk = pixhawk.Pixhawk() + pixhawk_data = pixhawk.get_data() + yolo_result = result_object + report = report.Report(yolo_result, pixhawk_data) + report.create_report() + report.print_report() + report.write_report(report_path) + reports.combine(reports_path) + previous = current + time.sleep(5) +# from detector import yolo +# import cv2 + +# """ +# Sample code importing the detector module +# """ +# print("[INFO] accessing video stream...") +# vs = cv2.VideoCapture(0) +# detector = yolo.Detector("model", use_gpu=True, weights_file="clearbot_26_06_20.weights") +# while True: +# (grabbed, frame) = vs.read() +# if not grabbed: +# break +# result = detector.detect(frame) +# print(result) diff --git a/report/clearbot_attributes/Air_speed.py b/report/clearbot_attributes/Air_speed.py new file mode 100644 index 0000000..9ca173e --- /dev/null +++ b/report/clearbot_attributes/Air_speed.py @@ -0,0 +1,7 @@ +class Air_speed: + def __init__(self, y): + self.y = y["air_speed"] + + def get_air_speed(self): + return self.y + \ No newline at end of file diff --git a/report/clearbot_attributes/Altitude.py b/report/clearbot_attributes/Altitude.py new file mode 100644 index 0000000..9d9f856 --- /dev/null +++ b/report/clearbot_attributes/Altitude.py @@ -0,0 +1,7 @@ +class Altitude: + def __init__(self, y): + self.y = y["altitude"] + + def get_altitude(self): + return self.y + \ No newline at end of file diff --git a/report/clearbot_attributes/Battery_status.py b/report/clearbot_attributes/Battery_status.py new file mode 100644 index 0000000..b420a34 --- /dev/null +++ b/report/clearbot_attributes/Battery_status.py @@ -0,0 +1,7 @@ +class Battery_status: + def __init__(self, y): + self.y = y["battery_status"] + + def get_battery(self): + return self.y + \ No newline at end of file diff --git a/report/clearbot_attributes/Check_vehicle_armed.py b/report/clearbot_attributes/Check_vehicle_armed.py new file mode 100644 index 0000000..b0dc5dd --- /dev/null +++ b/report/clearbot_attributes/Check_vehicle_armed.py @@ -0,0 +1,6 @@ +class Check_vehicle_armed: + def __init__(self, y): + self.y = y["check_vehicle_armed"] + + def get_check(self): + return self.y \ No newline at end of file diff --git a/report/Confidence.py b/report/clearbot_attributes/Confidence.py similarity index 76% rename from report/Confidence.py rename to report/clearbot_attributes/Confidence.py index 6afe48d..9c80331 100644 --- a/report/Confidence.py +++ b/report/clearbot_attributes/Confidence.py @@ -1,6 +1,6 @@ class Confidence: def __init__(self, y): - self.y = y[1] + self.y = y["confidence"] def get_confidence(self): return self.y diff --git a/report/Confidence.pyc b/report/clearbot_attributes/Confidence.pyc similarity index 100% rename from report/Confidence.pyc rename to report/clearbot_attributes/Confidence.pyc diff --git a/report/clearbot_attributes/Ekf_ok.py b/report/clearbot_attributes/Ekf_ok.py new file mode 100644 index 0000000..e8cb72f --- /dev/null +++ b/report/clearbot_attributes/Ekf_ok.py @@ -0,0 +1,6 @@ +class Ekf_ok: + def __init__(self, y): + self.y = y["EKF_OK"] + + def get_ekf(self): + return self.y \ No newline at end of file diff --git a/report/clearbot_attributes/Firmware_version.py b/report/clearbot_attributes/Firmware_version.py new file mode 100644 index 0000000..30ba39a --- /dev/null +++ b/report/clearbot_attributes/Firmware_version.py @@ -0,0 +1,7 @@ +class Firmware_version: + def __init__(self, y): + self.y = y["firmware_version"] + + def get_version(self): + return self.y + \ No newline at end of file diff --git a/report/clearbot_attributes/Gimbal_status.py b/report/clearbot_attributes/Gimbal_status.py new file mode 100644 index 0000000..ac69f3b --- /dev/null +++ b/report/clearbot_attributes/Gimbal_status.py @@ -0,0 +1,7 @@ +class Gimbal_status: + def __init__(self, y): + self.y = y["gimbal_status"] + + def get_status(self): + return self.y + \ No newline at end of file diff --git a/report/clearbot_attributes/Gps.py b/report/clearbot_attributes/Gps.py new file mode 100644 index 0000000..1114940 --- /dev/null +++ b/report/clearbot_attributes/Gps.py @@ -0,0 +1,7 @@ +class Gps: + def __init__(self, y): + self.y = y["gps"] + + def get_gps(self): + return self.y + \ No newline at end of file diff --git a/report/clearbot_attributes/Ground_speed.py b/report/clearbot_attributes/Ground_speed.py new file mode 100644 index 0000000..4732964 --- /dev/null +++ b/report/clearbot_attributes/Ground_speed.py @@ -0,0 +1,7 @@ +class Ground_speed: + def __init__(self, y): + self.y = y["ground_speed"] + + def get_speed(self): + return self.y + \ No newline at end of file diff --git a/report/clearbot_attributes/Heading.py b/report/clearbot_attributes/Heading.py new file mode 100644 index 0000000..eae3f32 --- /dev/null +++ b/report/clearbot_attributes/Heading.py @@ -0,0 +1,6 @@ +class Heading: + def __init__(self, y): + self.y = y["heading"] + + def get_heading(self): + return self.y \ No newline at end of file diff --git a/report/Label.py b/report/clearbot_attributes/Label.py similarity index 76% rename from report/Label.py rename to report/clearbot_attributes/Label.py index b10d5d7..53a3285 100644 --- a/report/Label.py +++ b/report/clearbot_attributes/Label.py @@ -1,6 +1,6 @@ class Label: def __init__(self, x): - self.x = x[0] + self.x = x["label"] def get_label(self): return self.x \ No newline at end of file diff --git a/report/Label.pyc b/report/clearbot_attributes/Label.pyc similarity index 100% rename from report/Label.pyc rename to report/clearbot_attributes/Label.pyc diff --git a/report/clearbot_attributes/Last_heartbeat.py b/report/clearbot_attributes/Last_heartbeat.py new file mode 100644 index 0000000..73331f6 --- /dev/null +++ b/report/clearbot_attributes/Last_heartbeat.py @@ -0,0 +1,6 @@ +class Last_heartbeat: + def __init__(self, y): + self.y = y["last_heartbeat"] + + def get_last_heartbeat(self): + return self.y \ No newline at end of file diff --git a/report/Location.py b/report/clearbot_attributes/Location.py similarity index 76% rename from report/Location.py rename to report/clearbot_attributes/Location.py index ca12f86..3bf02d5 100644 --- a/report/Location.py +++ b/report/clearbot_attributes/Location.py @@ -1,6 +1,6 @@ class Location: def __init__(self, z): - self.z = z + self.z = z["location"] def get_coordinate(self): return self.z diff --git a/report/Location.pyc b/report/clearbot_attributes/Location.pyc similarity index 100% rename from report/Location.pyc rename to report/clearbot_attributes/Location.pyc diff --git a/report/clearbot_attributes/Range_finder_distance.py b/report/clearbot_attributes/Range_finder_distance.py new file mode 100644 index 0000000..1317366 --- /dev/null +++ b/report/clearbot_attributes/Range_finder_distance.py @@ -0,0 +1,6 @@ +class Range_finder_distance: + def __init__(self, y): + self.y = y["range_finder_distance"] + + def get_distance(self): + return self.y \ No newline at end of file diff --git a/report/clearbot_attributes/Range_finder_voltage.py b/report/clearbot_attributes/Range_finder_voltage.py new file mode 100644 index 0000000..10c55b0 --- /dev/null +++ b/report/clearbot_attributes/Range_finder_voltage.py @@ -0,0 +1,6 @@ +class Range_finder_voltage: + def __init__(self, y): + self.y = y["range_finder_voltage"] + + def get_voltage(self): + return self.y \ No newline at end of file diff --git a/report/clearbot_attributes/System_status.py b/report/clearbot_attributes/System_status.py new file mode 100644 index 0000000..dfd2368 --- /dev/null +++ b/report/clearbot_attributes/System_status.py @@ -0,0 +1,6 @@ +class System_status: + def __init__(self, y): + self.y = y["system_status"] + + def get_system_status(self): + return self.y \ No newline at end of file diff --git a/report/clearbot_attributes/Vehicle_capabilties.py b/report/clearbot_attributes/Vehicle_capabilties.py new file mode 100644 index 0000000..b33a711 --- /dev/null +++ b/report/clearbot_attributes/Vehicle_capabilties.py @@ -0,0 +1,7 @@ +class Vehicle_capabilities: + def __init__(self, y): + self.y = y["vehicle_capabilities"] + + def get_capabilities(self): + return self.y + \ No newline at end of file diff --git a/report/clearbot_attributes/Vehicle_is_armable.py b/report/clearbot_attributes/Vehicle_is_armable.py new file mode 100644 index 0000000..9a5ee4f --- /dev/null +++ b/report/clearbot_attributes/Vehicle_is_armable.py @@ -0,0 +1,6 @@ +class Vehicle_is_armable: + def __init__(self, y): + self.y = y["vehicle_is_armable"] + + def get_armable(self): + return self.y \ No newline at end of file diff --git a/report/clearbot_attributes/Vehicle_mode_name.py b/report/clearbot_attributes/Vehicle_mode_name.py new file mode 100644 index 0000000..2fcff54 --- /dev/null +++ b/report/clearbot_attributes/Vehicle_mode_name.py @@ -0,0 +1,6 @@ +class Vehicle_mode_name: + def __init__(self, y): + self.y = y["vehicle_mode_name"] + + def get_name(self): + return self.y \ No newline at end of file diff --git a/report/clearbot_attributes/Velocity.py b/report/clearbot_attributes/Velocity.py new file mode 100644 index 0000000..87658d8 --- /dev/null +++ b/report/clearbot_attributes/Velocity.py @@ -0,0 +1,7 @@ +class Velocity: + def __init__(self, y): + self.y = y["velocity"] + + def get_velocity(self): + return self.y + \ No newline at end of file diff --git a/report/clearbot_attributes/__init__.py b/report/clearbot_attributes/__init__.py new file mode 100644 index 0000000..1cb91d4 --- /dev/null +++ b/report/clearbot_attributes/__init__.py @@ -0,0 +1,4 @@ +from os.path import dirname, basename, isfile, join +import glob +modules = glob.glob(join(dirname(__file__), "*.py")) +__all__ = [ basename(f)[:-3] for f in modules if isfile(f) and not f.endswith('__init__.py')] \ No newline at end of file diff --git a/report/pixhawk.py b/report/pixhawk.py index 3f840d2..f0af9c0 100644 --- a/report/pixhawk.py +++ b/report/pixhawk.py @@ -7,6 +7,7 @@ def __init__(self, connection_port="/dev/ttyTHS1", baud=57600): self.vehicle = connect(connection_port, wait_ready=True, baud=baud) self.vehicle.mode = VehicleMode("MANUAL") self.vehicle.armed = True + self.result = [] def firmware_version(self): return self.vehicle.version @@ -50,7 +51,7 @@ def last_heartbeat(self): def range_finder(self): return self.vehicle.rangefinder - def range_finder_distance(self): + def range_finder_distance(self): return self.vehicle.rangefinder.distance def range_finder_voltage(self): @@ -70,6 +71,31 @@ def vehicle_mode_name(self): def check_vehicle_armed(self): return self.vehicle.armed + + def get_data(self): + result.append({ + "firmware_version" : firmware_version(), + "vehicle_capabilities" : vehicle_capabilities(), + "location" :do_capture_global_location(), + "altitude" : do_capture_altitude(), + "velocity" : do_capture_velocity(), + "gps" : do_capture_gps(), + "ground_speed" : do_capture_ground_speed(), + "air_speed" : do_capture_air_speed(), + "gimbal_status" : gimbal_status(), + "battery_status" : battery_status(), + "EKF_OK" : EKF_OK(), + "last_heartbeat" : last_heartbeat(), + "range_finder_distance" : range_finder_distance(), + "range_finder_voltage" : range_finder_voltage(), + "heading" : heading(), + "vehicle_is_armable" : vehicle_is_armable(), + "system_status" : system_status(), + "vehicle_mode_name" : vehicle_mode_name(), + "check_vehicle_armed" : check_vehicle_armed() + }) + self.result = result + return result def debug(self): print('Autopilot Firmware version: %s' % self.vehicle.version) diff --git a/report/report.py b/report/report.py index ef331fd..ecaa12b 100644 --- a/report/report.py +++ b/report/report.py @@ -1,22 +1,55 @@ import json -from .Location import Location -from .Confidence import Confidence -from .Label import Label - +from clearbot_attributes import * class Report: - def __init__(self, yolo, location): - self.label = Label(yolo) - self.confidence = Confidence(yolo) - self.location = Location(location) + def __init__(self, yolo, pixhawk): + self.label = Label.Label(yolo) + self.confidence = Confidence.Confidence(yolo) + self.firmware_version = Firmware_version.Firmware_version(pixhawk) + self.vehicle_capabiliteis = Vehicle_capabilities.Vehicle_capabilities(pixhawk) + self.location = Location.Location(pixhawk) + self.altitude = Altitude.Altitude(pixhawk) + self.velocity = Velocity.Velocity(pixhawk) + self.gps = Gps.Gps(pixhawk) + self.ground_speed = Ground_speed.Ground_speed(pixhawk) + self.air_speed = Air_speed.Air_speed(pixhawk) + self.gimbal_status = Gimbal_status.Gimbal_status(pixhawk) + self.battery_status = Battery_status.Battery_status(pixhawk) + self.ekf_ok = Ekf_ok.Ekf_ok(pixhawk) + self.last_heartbeat = Last_heartbeat.Last_heartbeat(pixhawk) + self.range_finder_distance = Range_finder_distance.Range_finder_distance(pixhawk) + self.range_finder_voltage = Range_finder_voltage.Range_finder_voltage(pixhawk) + self.heading = Heading.Heading(pixhawk) + self.vehicle_is_armable = Vehicle_is_armable.Vehicle_is_armable(pixhawk) + self.system_status = System_status.System_status(pixhawk) + self.vehicle_mode_name = Vehicle_mode_name.Vehicle_mode_name(pixhawk) + self.check_vehicle_armed = Check_vehicle_armed.Check_vehicle_armed(pixhawk) self.report = {} def create_report(self): report = { "label": self.label.get_label(), "confidence": self.confidence.get_confidence(), - "location": self.location.get_coordinate() + "firmware_version" : self.firmware_version.get_version(), + "vehicle_capabilities" : self.vehicle_capabilities.get_capabilities, + "location" :self.location.get_coordinate(), + "altitude" : self.altitude.get_altitude, + "velocity" : self.velocity.get_velocity(), + "gps" : self.gps.get_gps(), + "ground_speed" : self.ground_speed.get_speed(), + "air_speed" : self.air_speed.get_air_speed(), + "gimbal_status" : self.gimbal_status.get_status(), + "battery_status" : self.battery_status.get_battery(), + "EKF_OK" : self.ekf_ok.get_ekf(), + "last_heartbeat" : self.last_heartbeat.get_last_heartbeat(), + "range_finder_distance" : self.range_finder_distance.get_distance(), + "range_finder_voltage" : self.range_finder_voltage.get_voltage, + "heading" : self.heading.get_heading(), + "vehicle_is_armable" : self.vehicle_is_armable.get_armable(), + "system_status" : self.system_status.get_system_status(), + "vehicle_mode_name" : self.vehicle_mode_name.get_name(), + "check_vehicle_armed" : self.check_vehicle_armed.get_check() } self.report = report From 76399c8eab66526083febbae4418a8b2f026b5cb Mon Sep 17 00:00:00 2001 From: fcendra Date: Thu, 2 Jul 2020 12:44:12 +0800 Subject: [PATCH 16/41] New features --- main.py | 22 +- report/clearbot_attributes/Air_speed.py | 2 +- report/clearbot_attributes/Altitude.py | 7 - report/clearbot_attributes/Attitude.py | 7 + report/clearbot_attributes/Battery_status.py | 2 +- .../Check_vehicle_armed.py | 2 +- report/clearbot_attributes/Ekf_ok.py | 2 +- .../clearbot_attributes/Firmware_version.py | 3 +- report/clearbot_attributes/Gimbal_status.py | 2 +- report/clearbot_attributes/Gps.py | 2 +- report/clearbot_attributes/Ground_speed.py | 2 +- report/clearbot_attributes/Heading.py | 2 +- report/clearbot_attributes/Last_heartbeat.py | 2 +- report/clearbot_attributes/Location.py | 2 +- .../Range_finder_distance.py | 2 +- .../Range_finder_voltage.py | 2 +- report/clearbot_attributes/System_status.py | 2 +- ...capabilties.py => Vehicle_capabilities.py} | 2 +- .../clearbot_attributes/Vehicle_is_armable.py | 2 +- .../clearbot_attributes/Vehicle_mode_name.py | 2 +- report/clearbot_attributes/Velocity.py | 2 +- report/pixhawk.py | 69 ++-- report/report.py | 12 +- report/report_folder/report.json | 24 +- report/report_folder/reports.json | 368 ++++++++++++++++++ report/reports.py | 2 +- 26 files changed, 479 insertions(+), 69 deletions(-) delete mode 100644 report/clearbot_attributes/Altitude.py create mode 100644 report/clearbot_attributes/Attitude.py rename report/clearbot_attributes/{Vehicle_capabilties.py => Vehicle_capabilities.py} (73%) diff --git a/main.py b/main.py index c1319ac..d859a61 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,6 @@ import time import cv2 + from detector import yolo from report import report from report import reports @@ -9,7 +10,7 @@ reports_path = 'report/report_folder/reports.json' print("[INFO] accessing video stream...") -vs = cv2.VideoCapture(1) +vs = cv2.VideoCapture(0) detector = yolo.Detector("model", use_gpu=True, weights_file="clearbot_26_06_20.weights") reports = reports.Reports() @@ -21,18 +22,19 @@ break result = detector.detect(frame) current = len(result) - if (current > 0 and current > previous): + print(result) + if (current > 0): result_object = result[current - 1] - pixhawk = pixhawk.Pixhawk() - pixhawk_data = pixhawk.get_data() + pixhawk_init = pixhawk.Pixhawk() + pixhawk_data = pixhawk_init.get_data() + print(pixhawk_data) yolo_result = result_object - report = report.Report(yolo_result, pixhawk_data) - report.create_report() - report.print_report() - report.write_report(report_path) + get_report = report.Report(yolo_result, pixhawk_data) + get_report.create_report() + get_report.print_report() + get_report.write_report(report_path) reports.combine(reports_path) - previous = current - time.sleep(5) + # from detector import yolo # import cv2 diff --git a/report/clearbot_attributes/Air_speed.py b/report/clearbot_attributes/Air_speed.py index 9ca173e..453813b 100644 --- a/report/clearbot_attributes/Air_speed.py +++ b/report/clearbot_attributes/Air_speed.py @@ -1,6 +1,6 @@ class Air_speed: def __init__(self, y): - self.y = y["air_speed"] + self.y = y[7] def get_air_speed(self): return self.y diff --git a/report/clearbot_attributes/Altitude.py b/report/clearbot_attributes/Altitude.py deleted file mode 100644 index 9d9f856..0000000 --- a/report/clearbot_attributes/Altitude.py +++ /dev/null @@ -1,7 +0,0 @@ -class Altitude: - def __init__(self, y): - self.y = y["altitude"] - - def get_altitude(self): - return self.y - \ No newline at end of file diff --git a/report/clearbot_attributes/Attitude.py b/report/clearbot_attributes/Attitude.py new file mode 100644 index 0000000..79f3a5f --- /dev/null +++ b/report/clearbot_attributes/Attitude.py @@ -0,0 +1,7 @@ +class Attitude: + def __init__(self, y): + self.y = y[3] + + def get_attitude(self): + return self.y + \ No newline at end of file diff --git a/report/clearbot_attributes/Battery_status.py b/report/clearbot_attributes/Battery_status.py index b420a34..b3533a4 100644 --- a/report/clearbot_attributes/Battery_status.py +++ b/report/clearbot_attributes/Battery_status.py @@ -1,6 +1,6 @@ class Battery_status: def __init__(self, y): - self.y = y["battery_status"] + self.y = y[9] def get_battery(self): return self.y diff --git a/report/clearbot_attributes/Check_vehicle_armed.py b/report/clearbot_attributes/Check_vehicle_armed.py index b0dc5dd..b9e6919 100644 --- a/report/clearbot_attributes/Check_vehicle_armed.py +++ b/report/clearbot_attributes/Check_vehicle_armed.py @@ -1,6 +1,6 @@ class Check_vehicle_armed: def __init__(self, y): - self.y = y["check_vehicle_armed"] + self.y = y[18] def get_check(self): return self.y \ No newline at end of file diff --git a/report/clearbot_attributes/Ekf_ok.py b/report/clearbot_attributes/Ekf_ok.py index e8cb72f..08568e0 100644 --- a/report/clearbot_attributes/Ekf_ok.py +++ b/report/clearbot_attributes/Ekf_ok.py @@ -1,6 +1,6 @@ class Ekf_ok: def __init__(self, y): - self.y = y["EKF_OK"] + self.y = y[10] def get_ekf(self): return self.y \ No newline at end of file diff --git a/report/clearbot_attributes/Firmware_version.py b/report/clearbot_attributes/Firmware_version.py index 30ba39a..ea04b88 100644 --- a/report/clearbot_attributes/Firmware_version.py +++ b/report/clearbot_attributes/Firmware_version.py @@ -1,6 +1,7 @@ class Firmware_version: def __init__(self, y): - self.y = y["firmware_version"] + #self.y = y["firmware_version"] + self.y = y[0] def get_version(self): return self.y diff --git a/report/clearbot_attributes/Gimbal_status.py b/report/clearbot_attributes/Gimbal_status.py index ac69f3b..eb2089c 100644 --- a/report/clearbot_attributes/Gimbal_status.py +++ b/report/clearbot_attributes/Gimbal_status.py @@ -1,6 +1,6 @@ class Gimbal_status: def __init__(self, y): - self.y = y["gimbal_status"] + self.y = y[8] def get_status(self): return self.y diff --git a/report/clearbot_attributes/Gps.py b/report/clearbot_attributes/Gps.py index 1114940..58fe7a3 100644 --- a/report/clearbot_attributes/Gps.py +++ b/report/clearbot_attributes/Gps.py @@ -1,6 +1,6 @@ class Gps: def __init__(self, y): - self.y = y["gps"] + self.y = y[5] def get_gps(self): return self.y diff --git a/report/clearbot_attributes/Ground_speed.py b/report/clearbot_attributes/Ground_speed.py index 4732964..ddfd71b 100644 --- a/report/clearbot_attributes/Ground_speed.py +++ b/report/clearbot_attributes/Ground_speed.py @@ -1,6 +1,6 @@ class Ground_speed: def __init__(self, y): - self.y = y["ground_speed"] + self.y = y[6] def get_speed(self): return self.y diff --git a/report/clearbot_attributes/Heading.py b/report/clearbot_attributes/Heading.py index eae3f32..b099888 100644 --- a/report/clearbot_attributes/Heading.py +++ b/report/clearbot_attributes/Heading.py @@ -1,6 +1,6 @@ class Heading: def __init__(self, y): - self.y = y["heading"] + self.y = y[14] def get_heading(self): return self.y \ No newline at end of file diff --git a/report/clearbot_attributes/Last_heartbeat.py b/report/clearbot_attributes/Last_heartbeat.py index 73331f6..7ddabfc 100644 --- a/report/clearbot_attributes/Last_heartbeat.py +++ b/report/clearbot_attributes/Last_heartbeat.py @@ -1,6 +1,6 @@ class Last_heartbeat: def __init__(self, y): - self.y = y["last_heartbeat"] + self.y = y[11] def get_last_heartbeat(self): return self.y \ No newline at end of file diff --git a/report/clearbot_attributes/Location.py b/report/clearbot_attributes/Location.py index 3bf02d5..a88c035 100644 --- a/report/clearbot_attributes/Location.py +++ b/report/clearbot_attributes/Location.py @@ -1,6 +1,6 @@ class Location: def __init__(self, z): - self.z = z["location"] + self.z = z[2] def get_coordinate(self): return self.z diff --git a/report/clearbot_attributes/Range_finder_distance.py b/report/clearbot_attributes/Range_finder_distance.py index 1317366..7c32b82 100644 --- a/report/clearbot_attributes/Range_finder_distance.py +++ b/report/clearbot_attributes/Range_finder_distance.py @@ -1,6 +1,6 @@ class Range_finder_distance: def __init__(self, y): - self.y = y["range_finder_distance"] + self.y = y[12] def get_distance(self): return self.y \ No newline at end of file diff --git a/report/clearbot_attributes/Range_finder_voltage.py b/report/clearbot_attributes/Range_finder_voltage.py index 10c55b0..00a0cf5 100644 --- a/report/clearbot_attributes/Range_finder_voltage.py +++ b/report/clearbot_attributes/Range_finder_voltage.py @@ -1,6 +1,6 @@ class Range_finder_voltage: def __init__(self, y): - self.y = y["range_finder_voltage"] + self.y = y[13] def get_voltage(self): return self.y \ No newline at end of file diff --git a/report/clearbot_attributes/System_status.py b/report/clearbot_attributes/System_status.py index dfd2368..c3b4698 100644 --- a/report/clearbot_attributes/System_status.py +++ b/report/clearbot_attributes/System_status.py @@ -1,6 +1,6 @@ class System_status: def __init__(self, y): - self.y = y["system_status"] + self.y = y[16] def get_system_status(self): return self.y \ No newline at end of file diff --git a/report/clearbot_attributes/Vehicle_capabilties.py b/report/clearbot_attributes/Vehicle_capabilities.py similarity index 73% rename from report/clearbot_attributes/Vehicle_capabilties.py rename to report/clearbot_attributes/Vehicle_capabilities.py index b33a711..5386c93 100644 --- a/report/clearbot_attributes/Vehicle_capabilties.py +++ b/report/clearbot_attributes/Vehicle_capabilities.py @@ -1,6 +1,6 @@ class Vehicle_capabilities: def __init__(self, y): - self.y = y["vehicle_capabilities"] + self.y = y[1] def get_capabilities(self): return self.y diff --git a/report/clearbot_attributes/Vehicle_is_armable.py b/report/clearbot_attributes/Vehicle_is_armable.py index 9a5ee4f..ed78573 100644 --- a/report/clearbot_attributes/Vehicle_is_armable.py +++ b/report/clearbot_attributes/Vehicle_is_armable.py @@ -1,6 +1,6 @@ class Vehicle_is_armable: def __init__(self, y): - self.y = y["vehicle_is_armable"] + self.y = y[15] def get_armable(self): return self.y \ No newline at end of file diff --git a/report/clearbot_attributes/Vehicle_mode_name.py b/report/clearbot_attributes/Vehicle_mode_name.py index 2fcff54..2564984 100644 --- a/report/clearbot_attributes/Vehicle_mode_name.py +++ b/report/clearbot_attributes/Vehicle_mode_name.py @@ -1,6 +1,6 @@ class Vehicle_mode_name: def __init__(self, y): - self.y = y["vehicle_mode_name"] + self.y = y[17] def get_name(self): return self.y \ No newline at end of file diff --git a/report/clearbot_attributes/Velocity.py b/report/clearbot_attributes/Velocity.py index 87658d8..8f715ad 100644 --- a/report/clearbot_attributes/Velocity.py +++ b/report/clearbot_attributes/Velocity.py @@ -1,6 +1,6 @@ class Velocity: def __init__(self, y): - self.y = y["velocity"] + self.y = y[4] def get_velocity(self): return self.y diff --git a/report/pixhawk.py b/report/pixhawk.py index f0af9c0..c2e0800 100644 --- a/report/pixhawk.py +++ b/report/pixhawk.py @@ -4,9 +4,9 @@ class Pixhawk: vehicle = None def __init__(self, connection_port="/dev/ttyTHS1", baud=57600): + self.vehicle = connect(connection_port, wait_ready=True, baud=baud) self.vehicle.mode = VehicleMode("MANUAL") - self.vehicle.armed = True self.result = [] def firmware_version(self): @@ -73,29 +73,50 @@ def check_vehicle_armed(self): return self.vehicle.armed def get_data(self): - result.append({ - "firmware_version" : firmware_version(), - "vehicle_capabilities" : vehicle_capabilities(), - "location" :do_capture_global_location(), - "altitude" : do_capture_altitude(), - "velocity" : do_capture_velocity(), - "gps" : do_capture_gps(), - "ground_speed" : do_capture_ground_speed(), - "air_speed" : do_capture_air_speed(), - "gimbal_status" : gimbal_status(), - "battery_status" : battery_status(), - "EKF_OK" : EKF_OK(), - "last_heartbeat" : last_heartbeat(), - "range_finder_distance" : range_finder_distance(), - "range_finder_voltage" : range_finder_voltage(), - "heading" : heading(), - "vehicle_is_armable" : vehicle_is_armable(), - "system_status" : system_status(), - "vehicle_mode_name" : vehicle_mode_name(), - "check_vehicle_armed" : check_vehicle_armed() - }) - self.result = result - return result + # self.result.append + # "firmware_version" : self.vehicle.version, + # "vehicle_capabilities" : self.vehicle.capabilities.ftp, + # "location" :self.vehicle.location.global_frame, + # "altitude" : self.vehicle.attitude, + # "velocity" : self.vehicle.velocity, + # "gps" : self.vehicle.gps_0, + # "ground_speed" : self.vehicle.groundspeed, + # "air_speed" : self.vehicle.airspeed, + # "gimbal_status" : self.vehicle.gimbal, + # "battery_status" : self.vehicle.battery, + # "EKF_OK" : self.vehicle.ekf_ok, + # "last_heartbeat" : self.vehicle.last_heartbeat, + # "range_finder_distance" : self.vehicle.rangefinder.distance, + # "range_finder_voltage" : self.vehicle.rangefinder.voltage, + # "heading" : self.vehicle.heading, + # "vehicle_is_armable" : self.vehicle.is_armable, + # "system_status" : self.vehicle.system_status.state, + # "vehicle_mode_name" : self.vehicle.mode.name, + # "check_vehicle_armed" : self.vehicle.armed + # }) + self.result=[ + str(self.vehicle.version), + str(self.vehicle.capabilities.ftp), + str(self.vehicle.location.global_frame), + str(self.vehicle.attitude), + str(self.vehicle.velocity), + str(self.vehicle.gps_0), + self.vehicle.groundspeed, + self.vehicle.airspeed, + str(self.vehicle.gimbal), + str(self.vehicle.battery), + self.vehicle.ekf_ok, + self.vehicle.last_heartbeat, + str(self.vehicle.rangefinder.distance), + str(self.vehicle.rangefinder.voltage), + self.vehicle.heading, + self.vehicle.is_armable, + self.vehicle.system_status.state, + self.vehicle.mode.name, + self.vehicle.armed + ] + #self.result = result + return self.result def debug(self): print('Autopilot Firmware version: %s' % self.vehicle.version) diff --git a/report/report.py b/report/report.py index ecaa12b..ecf0e70 100644 --- a/report/report.py +++ b/report/report.py @@ -1,15 +1,15 @@ import json -from clearbot_attributes import * +from report.clearbot_attributes import * class Report: def __init__(self, yolo, pixhawk): self.label = Label.Label(yolo) self.confidence = Confidence.Confidence(yolo) self.firmware_version = Firmware_version.Firmware_version(pixhawk) - self.vehicle_capabiliteis = Vehicle_capabilities.Vehicle_capabilities(pixhawk) + self.vehicle_capabilities = Vehicle_capabilities.Vehicle_capabilities(pixhawk) self.location = Location.Location(pixhawk) - self.altitude = Altitude.Altitude(pixhawk) + self.attitude = Attitude.Attitude(pixhawk) self.velocity = Velocity.Velocity(pixhawk) self.gps = Gps.Gps(pixhawk) self.ground_speed = Ground_speed.Ground_speed(pixhawk) @@ -32,9 +32,9 @@ def create_report(self): "label": self.label.get_label(), "confidence": self.confidence.get_confidence(), "firmware_version" : self.firmware_version.get_version(), - "vehicle_capabilities" : self.vehicle_capabilities.get_capabilities, + "vehicle_capabilities" : self.vehicle_capabilities.get_capabilities(), "location" :self.location.get_coordinate(), - "altitude" : self.altitude.get_altitude, + "attitude" : self.attitude.get_attitude(), "velocity" : self.velocity.get_velocity(), "gps" : self.gps.get_gps(), "ground_speed" : self.ground_speed.get_speed(), @@ -44,7 +44,7 @@ def create_report(self): "EKF_OK" : self.ekf_ok.get_ekf(), "last_heartbeat" : self.last_heartbeat.get_last_heartbeat(), "range_finder_distance" : self.range_finder_distance.get_distance(), - "range_finder_voltage" : self.range_finder_voltage.get_voltage, + "range_finder_voltage" : self.range_finder_voltage.get_voltage(), "heading" : self.heading.get_heading(), "vehicle_is_armable" : self.vehicle_is_armable.get_armable(), "system_status" : self.system_status.get_system_status(), diff --git a/report/report_folder/report.json b/report/report_folder/report.json index c721859..0b875b1 100644 --- a/report/report_folder/report.json +++ b/report/report_folder/report.json @@ -1,5 +1,23 @@ { - "confidence": 97, - "label": "litter", - "location": "hello" + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=-0.06688760966062546,yaw=0.8089165091514587,roll=-0.42657241225242615", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5623620748519897, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 46, + "label": "Egg carton", + "last_heartbeat": 0.1956399999999121, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=0.0", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" } \ No newline at end of file diff --git a/report/report_folder/reports.json b/report/report_folder/reports.json index 1a2ec65..adba6a1 100644 --- a/report/report_folder/reports.json +++ b/report/report_folder/reports.json @@ -14,6 +14,374 @@ "confidence": 97, "label": "litter", "location": "hello" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.01909925416111946,yaw=2.4231948852539062,roll=-0.4838428497314453", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5103110074996948, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 138, + "label": "Single-use carrier bag", + "last_heartbeat": 0.528749322999829, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-2.06", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.008913249708712101,yaw=2.566417694091797,roll=-0.4564279317855835", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.944784939289093, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 147, + "label": "Clear plastic bottle", + "last_heartbeat": 0.7555133850000857, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-2.19", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.008600435219705105,yaw=2.637603759765625,roll=-0.468279629945755", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.8287092447280884, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 151, + "label": "Clear plastic bottle", + "last_heartbeat": 0.7411906769993948, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-1.88", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.002421633806079626,yaw=2.63266658782959,roll=-0.33760201930999756", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.7057521343231201, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 150, + "label": "Single-use carrier bag", + "last_heartbeat": 0.45644921800067095, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-1.71", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.0019324326422065496,yaw=2.634483814239502,roll=-0.3371628522872925", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6058073043823242, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 150, + "label": "Single-use carrier bag", + "last_heartbeat": 0.6393409370002701, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-1.92", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.004327771253883839,yaw=2.628669261932373,roll=-0.3355568051338196", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6313447952270508, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 150, + "label": "Single-use carrier bag", + "last_heartbeat": 0.12869474000035552, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-2.05", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.004637624602764845,yaw=2.655484676361084,roll=-0.38725385069847107", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5052488446235657, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 152, + "label": "Plastified paper bag", + "last_heartbeat": 0.8054212500001086, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-2.3", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.004376034252345562,yaw=2.653416395187378,roll=-0.38649651408195496", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6701147556304932, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 152, + "label": "Plastified paper bag", + "last_heartbeat": 0.9475373960003708, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-1.5", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.0039167385548353195,yaw=2.6539077758789062,roll=-0.38680440187454224", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.8561442494392395, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 152, + "label": "Crisp packet", + "last_heartbeat": 0.689201406000393, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-1.46", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.0024878692347556353,yaw=2.6573050022125244,roll=-0.3856864869594574", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.674862802028656, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 152, + "label": "Tissues", + "last_heartbeat": 0.17121276000034413, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-1.95", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=-0.07103683799505234,yaw=0.7741695046424866,roll=-0.41734689474105835", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5699434280395508, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 44, + "label": "Paper straw", + "last_heartbeat": 0.21931572999983473, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-0.45", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=-0.069066122174263,yaw=0.7767916917800903,roll=-0.4175513684749603", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5248982310295105, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 44, + "label": "Glass bottle", + "last_heartbeat": 0.06126848900021287, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-0.22", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=-0.07107638567686081,yaw=0.7734728455543518,roll=-0.4168369174003601", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.7648918628692627, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 44, + "label": "Spread tub", + "last_heartbeat": 0.17502203099957114, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-0.51", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=-0.06390124559402466,yaw=0.7821321487426758,roll=-0.42286205291748047", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.516333818435669, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 44, + "label": "Squeezable tube", + "last_heartbeat": 0.17359416599902033, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-0.36", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=-0.06786604225635529,yaw=0.8050878047943115,roll=-0.4275035560131073", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5929812788963318, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 46, + "label": "Broken glass", + "last_heartbeat": 0.29605604100106575, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-0.33", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=-0.06688760966062546,yaw=0.8089165091514587,roll=-0.42657241225242615", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5623620748519897, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 46, + "label": "Egg carton", + "last_heartbeat": 0.1956399999999121, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=0.0", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" } ] } \ No newline at end of file diff --git a/report/reports.py b/report/reports.py index fc49ea7..1a098f1 100644 --- a/report/reports.py +++ b/report/reports.py @@ -1,7 +1,7 @@ from pathlib import Path import json -data_folder = Path("report_folder/") +data_folder = Path("report/report_folder/") file_to_open = data_folder / "report.json" class Reports: From 28b5cbb7ed0be1f1b951ad50813d0f57a312513c Mon Sep 17 00:00:00 2001 From: fcendra Date: Fri, 3 Jul 2020 13:51:16 +0800 Subject: [PATCH 17/41] Adding features for thingspeak --- main.py | 25 ++++++++--------------- report/thing_speak.py | 46 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 17 deletions(-) create mode 100644 report/thing_speak.py diff --git a/main.py b/main.py index d859a61..92b40b9 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,7 @@ from report import report from report import reports from report import pixhawk +from report import thing_speak report_path = 'report/report_folder/report.json' reports_path = 'report/report_folder/reports.json' @@ -29,24 +30,14 @@ pixhawk_data = pixhawk_init.get_data() print(pixhawk_data) yolo_result = result_object + + #post to thingspeak.com + visualize = thing_speak.Thing_speak(yolo_result, pixhawk_data)) + visualize.show_thingspeak() + + #saved to reports.json get_report = report.Report(yolo_result, pixhawk_data) get_report.create_report() get_report.print_report() get_report.write_report(report_path) - reports.combine(reports_path) - -# from detector import yolo -# import cv2 - -# """ -# Sample code importing the detector module -# """ -# print("[INFO] accessing video stream...") -# vs = cv2.VideoCapture(0) -# detector = yolo.Detector("model", use_gpu=True, weights_file="clearbot_26_06_20.weights") -# while True: -# (grabbed, frame) = vs.read() -# if not grabbed: -# break -# result = detector.detect(frame) -# print(result) + reports.combine(reports_path) \ No newline at end of file diff --git a/report/thing_speak.py b/report/thing_speak.py new file mode 100644 index 0000000..5dc8f11 --- /dev/null +++ b/report/thing_speak.py @@ -0,0 +1,46 @@ +import paho.mqtt.publish as publish +from report.clearbot_attributes import * +import time + +channelID = "1092630" +apiKey = "FGN0JQQLW5D88TJ1" + +topic = "channels/"+ channelID +"/publish/"+ apiKey +mqttHost = "mqtt.thingspeak.com" +tTransport = "tcp" +tPort = 1883 +tTLS = None + + +class Thing_speak: + + def __init__(yolo_result, pixhawk_data): + self.label = Label.Label(yolo) + self.confidence = Confidence.Confidence(yolo) + self.location = Location.Location(pixhawk) + self.battery_status = Battery_status.Battery_status(pixhawk) + self.system_status = System_status.System_status(pixhawk) + + def show_thingspeak(self): + #get gps_location from string variable and stored it in a list + gps_location=[] + location_string = self.location.get_coordinate() + location_list = location_string.split() + for i in location_list: + try: + result = float(i) + gps_location.append(result) + except: + continue + + #payload + tPayload = "field1=" + gps_location + "&field2=" + str(self.label.get_label()) + "&field3=" + str(self.confidence.get_confidence()) + "&field4=" + str(self.system_status.get_system_status()) + "&field5=" + str(self.battery_status.get_battery()) + + print("[INFO] Data prepared to be uploaded") + + try: + #publish the data + publish.single(topic, payload = tPayload, hostname = mqttHost, port = tPort, tls = tTLS, transport = tTransport) + print("[INFO] Data send for two fields: ") + except: + print("[INFO] Failure in sending data") \ No newline at end of file From f168fd0bebfc8375745072d43cd2c7017c63bd41 Mon Sep 17 00:00:00 2001 From: Fernando Julio Cendra Date: Tue, 7 Jul 2020 21:22:33 +0800 Subject: [PATCH 18/41] Adding features (thinkspeak) --- main.py | 2 +- report/thing_speak.py | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 92b40b9..7e58394 100644 --- a/main.py +++ b/main.py @@ -32,7 +32,7 @@ yolo_result = result_object #post to thingspeak.com - visualize = thing_speak.Thing_speak(yolo_result, pixhawk_data)) + visualize = thing_speak.Thing_speak(yolo_result, pixhawk_data) visualize.show_thingspeak() #saved to reports.json diff --git a/report/thing_speak.py b/report/thing_speak.py index 5dc8f11..6e94f25 100644 --- a/report/thing_speak.py +++ b/report/thing_speak.py @@ -1,6 +1,7 @@ import paho.mqtt.publish as publish from report.clearbot_attributes import * import time +import re channelID = "1092630" apiKey = "FGN0JQQLW5D88TJ1" @@ -14,7 +15,7 @@ class Thing_speak: - def __init__(yolo_result, pixhawk_data): + def __init__(self,yolo, pixhawk): self.label = Label.Label(yolo) self.confidence = Confidence.Confidence(yolo) self.location = Location.Location(pixhawk) @@ -23,24 +24,24 @@ def __init__(yolo_result, pixhawk_data): def show_thingspeak(self): #get gps_location from string variable and stored it in a list - gps_location=[] location_string = self.location.get_coordinate() - location_list = location_string.split() - for i in location_list: - try: - result = float(i) - gps_location.append(result) - except: - continue + gps_location = re.findall(r"[-+]?\d*\.\d+|\d+", location_string) + + label_data = str(self.label.get_label()) + confidence_data = str(self.confidence.get_confidence()) + lat = gps_location[0] + lon = gps_location[1] + battery_status_data = str(self.battery_status.get_battery()) + system_status_data = str(self.system_status.get_system_status()) #payload - tPayload = "field1=" + gps_location + "&field2=" + str(self.label.get_label()) + "&field3=" + str(self.confidence.get_confidence()) + "&field4=" + str(self.system_status.get_system_status()) + "&field5=" + str(self.battery_status.get_battery()) + tPayload = "field1=" + lat + "&field2=" + lon + "&field3=" + confidence_data + "&field4=" + system_status_data + "&field5=" + battery_status_data + "&field6=" + label_data print("[INFO] Data prepared to be uploaded") try: #publish the data publish.single(topic, payload = tPayload, hostname = mqttHost, port = tPort, tls = tTLS, transport = tTransport) - print("[INFO] Data send for two fields: ") + print("[INFO] Data sent successfully") except: print("[INFO] Failure in sending data") \ No newline at end of file From 4a5a28b2560692cac8e2efb5cc4c51f385e7c3b5 Mon Sep 17 00:00:00 2001 From: utkarsh867 Date: Thu, 9 Jul 2020 01:44:15 +0530 Subject: [PATCH 19/41] Code refactoring, adds error handling, logging --- .gitignore | 3 +- detector/yolo.py | 2 +- main.py | 80 +++++++++++++++++++++++++++++++++++------------- 3 files changed, 61 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 2732f71..42f978b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .vscode/ .venv/ .idea/ -__pycache__/ \ No newline at end of file +__pycache__/ +.DS_Store \ No newline at end of file diff --git a/detector/yolo.py b/detector/yolo.py index 9cf57e0..1e76a34 100644 --- a/detector/yolo.py +++ b/detector/yolo.py @@ -21,7 +21,7 @@ def __init__(self, model_path, use_gpu=False, confidence_thres=0.5, nms_thres=0. """ self.confidence_threshold = confidence_thres self.nms_threshold = nms_thres - # initialize a list of colors to represent each possible class label + labels_path = os.path.sep.join([os.path.dirname(os.path.realpath(__file__)), model_path, names_file]) self.LABELS = open(labels_path).read().strip().split("\n") diff --git a/main.py b/main.py index 7e58394..067c839 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,7 @@ import time +import argparse +import logging +from serial import serialutil import cv2 from detector import yolo @@ -10,34 +13,67 @@ report_path = 'report/report_folder/report.json' reports_path = 'report/report_folder/reports.json' -print("[INFO] accessing video stream...") +parser = argparse.ArgumentParser(description="Clearbot AI and PController") +parser.add_argument('-v', '--video_out', type=bool, default=False, help="Show the camera video output") +parser.add_argument('--debug', type=bool, default=False, help="Switch to debug mode") +args = parser.parse_args() + +# Added the logging package instead of printing data randomly +if args.debug: + logging.getLogger().setLevel(logging.DEBUG) +else: + logging.getLogger().setLevel(logging.INFO) + +logging.info("accessing video stream...") vs = cv2.VideoCapture(0) -detector = yolo.Detector("model", use_gpu=True, weights_file="clearbot_26_06_20.weights") +detector = yolo.Detector("model", use_gpu=True) reports = reports.Reports() -previous = 0 while True: (grabbed, frame) = vs.read() if not grabbed: break result = detector.detect(frame) - current = len(result) - print(result) - if (current > 0): - result_object = result[current - 1] - pixhawk_init = pixhawk.Pixhawk() - pixhawk_data = pixhawk_init.get_data() - print(pixhawk_data) - yolo_result = result_object - - #post to thingspeak.com - visualize = thing_speak.Thing_speak(yolo_result, pixhawk_data) - visualize.show_thingspeak() - - #saved to reports.json - get_report = report.Report(yolo_result, pixhawk_data) - get_report.create_report() - get_report.print_report() - get_report.write_report(report_path) - reports.combine(reports_path) \ No newline at end of file + for box in result: + bbox = box["bbox"] + x = bbox["x"] + y = bbox["y"] + w = bbox["width"] + h = bbox["height"] + cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2) + + logging.debug(result) + + for r in result: + # This loop is iterating over all YOLO results + # TODO: Optimise this section so that each frame is sent only once. + try: + pixhawk_init = pixhawk.Pixhawk() + pixhawk_data = pixhawk_init.get_data() + logging.debug(pixhawk_data) + + # post to thingspeak.com + visualize = thing_speak.Thing_speak(r, pixhawk_data) + visualize.show_thingspeak() + + # saved to reports.json + get_report = report.Report(r, pixhawk_data) + get_report.create_report() + get_report.print_report() + get_report.write_report(report_path) + reports.combine(reports_path) + + except serialutil.SerialException as e: + # @utkarsh867: 9th July, 2020 + # I added this exception handler so that the code does not crash when it does not find a serial connection + # to the Pixhawk + logging.error(e) + + cv2.imshow("Clearbot", frame) + # If this is not there, frame will not actually show: I did not dig into the explanation + if cv2.waitKey(1) & 0xFF == ord('q'): + break + +vs.release() +cv2.destroyAllWindows() From 7b7e82abe478f52ba2d05ab209a0d84e0ce40575 Mon Sep 17 00:00:00 2001 From: utkarsh867 Date: Thu, 9 Jul 2020 01:55:00 +0530 Subject: [PATCH 20/41] Adds FPS counter, shows video on flag --- main.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 067c839..2e277a0 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ import argparse import logging from serial import serialutil +from imutils.video import FPS import cv2 from detector import yolo @@ -30,6 +31,9 @@ reports = reports.Reports() + +fps = FPS().start() + while True: (grabbed, frame) = vs.read() if not grabbed: @@ -70,10 +74,15 @@ # to the Pixhawk logging.error(e) - cv2.imshow("Clearbot", frame) - # If this is not there, frame will not actually show: I did not dig into the explanation - if cv2.waitKey(1) & 0xFF == ord('q'): - break + if args.video_out: + cv2.imshow("Clearbot", frame) + # If this is not there, frame will not actually show: I did not dig into the explanation + if cv2.waitKey(1) & 0xFF == ord('q'): + break + + fps.update() +fps.stop() +logging.info("approx. FPS: {:.2f}".format(fps.fps())) vs.release() cv2.destroyAllWindows() From ba0dfcbcbcd3e6064b213f518e6e9d974d80910d Mon Sep 17 00:00:00 2001 From: fcendra Date: Thu, 9 Jul 2020 15:00:14 +0800 Subject: [PATCH 21/41] Adding some code in thingspeak.py --- detector/yolo.py | 2 +- report/report_folder/report.json | 12 +- report/report_folder/reports.json | 598 ++++++++++++++++++++++++++++++ report/thing_speak.py | 2 +- 4 files changed, 606 insertions(+), 8 deletions(-) diff --git a/detector/yolo.py b/detector/yolo.py index 1e76a34..145619d 100644 --- a/detector/yolo.py +++ b/detector/yolo.py @@ -10,7 +10,7 @@ class Detector: LABELS = None ln = None - def __init__(self, model_path, use_gpu=False, confidence_thres=0.5, nms_thres=0.3, weights_file="clearbot.weights", + def __init__(self, model_path, use_gpu=False, confidence_thres=0.5, nms_thres=0.3, weights_file="clearbot_26_06_20.weights", config_file="clearbot.cfg", names_file="clearbot.names"): """ Initialise a instance for YOLOv4 object detection. diff --git a/report/report_folder/report.json b/report/report_folder/report.json index 0b875b1..6bdfc20 100644 --- a/report/report_folder/report.json +++ b/report/report_folder/report.json @@ -1,18 +1,18 @@ { "EKF_OK": false, "air_speed": 0.0, - "attitude": "Attitude:pitch=-0.06688760966062546,yaw=0.8089165091514587,roll=-0.42657241225242615", + "attitude": "Attitude:pitch=-0.013345734216272831,yaw=2.816819190979004,roll=0.018571699038147926", "battery_status": "Battery:voltage=0.0,current=None,level=None", "check_vehicle_armed": false, - "confidence": 0.5623620748519897, + "confidence": 0.5480275750160217, "firmware_version": "APM:UnknownVehicleType11-4.0.0", "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", "gps": "GPSInfo:fix=1,num_sat=0", "ground_speed": 0.0, - "heading": 46, - "label": "Egg carton", - "last_heartbeat": 0.1956399999999121, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=0.0", + "heading": 161, + "label": "Paper straw", + "last_heartbeat": 0.014498732999982167, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=0.45", "range_finder_distance": "None", "range_finder_voltage": "None", "system_status": "CRITICAL", diff --git a/report/report_folder/reports.json b/report/report_folder/reports.json index adba6a1..4a6eb53 100644 --- a/report/report_folder/reports.json +++ b/report/report_folder/reports.json @@ -382,6 +382,604 @@ "vehicle_is_armable": false, "vehicle_mode_name": "MANUAL", "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.011720940470695496,yaw=-2.691927671432495,roll=0.02516011707484722", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6233267784118652, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 205, + "label": "Plastified paper bag", + "last_heartbeat": 0.4513490780000211, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=3.09", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "HOLD", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.017221353948116302,yaw=-2.6880340576171875,roll=0.02412303164601326", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.8484107851982117, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 205, + "label": "Carded blister pack", + "last_heartbeat": 0.49970943899984377, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=2.59", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.017535418272018433,yaw=-2.682232141494751,roll=0.02506384253501892", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.9025440812110901, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 206, + "label": "Carded blister pack", + "last_heartbeat": 0.9765662840000005, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=2.84", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.013507163152098656,yaw=-2.699464797973633,roll=0.032972127199172974", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.7768799066543579, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 205, + "label": "Tissues", + "last_heartbeat": 0.07120154800009004, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=2.4", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.014546588063240051,yaw=-2.7026543617248535,roll=0.03452213481068611", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6090551018714905, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 205, + "label": "Plastic bottle cap", + "last_heartbeat": 0.08426600600000711, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=2.67", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.0023166825994849205,yaw=-2.7255067825317383,roll=0.04753636568784714", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.7308673858642578, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 203, + "label": "Plastified paper bag", + "last_heartbeat": 0.9308011690000058, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=2.37", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.001522311009466648,yaw=-2.724100112915039,roll=0.04830246418714523", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.639407217502594, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 203, + "label": "Plastified paper bag", + "last_heartbeat": 0.06578741799989984, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=1.97", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=-0.006178590003401041,yaw=-2.734241485595703,roll=0.05553458258509636", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.545289933681488, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 203, + "label": "Tissues", + "last_heartbeat": 0.9213393700001689, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=2.8", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.09895947575569153,yaw=-2.8563711643218994,roll=-0.03333592042326927", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6184415221214294, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 196, + "label": "Broken glass", + "last_heartbeat": 0.9445924540000306, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=3.0", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.09880923479795456,yaw=-2.8584089279174805,roll=-0.03788881003856659", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5609496831893921, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 196, + "label": "Spread tub", + "last_heartbeat": 0.20779678500002774, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=3.25", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.09830862283706665,yaw=-2.857605218887329,roll=-0.03894437104463577", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5146123766899109, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 196, + "label": "Disposable plastic cup", + "last_heartbeat": 0.39948584700005085, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=3.28", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.08901780843734741,yaw=-2.879223346710205,roll=-0.03568514809012413", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6122862100601196, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 195, + "label": "Carded blister pack", + "last_heartbeat": 0.9131540979997226, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.38", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.11036232858896255,yaw=3.0507771968841553,roll=0.09607145190238953", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.817825198173523, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 174, + "label": "Spread tub", + "last_heartbeat": 0.6851423230000364, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.18", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.031789928674697876,yaw=-2.52939772605896,roll=0.010927568189799786", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5057023167610168, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 215, + "label": "Crisp packet", + "last_heartbeat": 0.39529037799999855, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.95", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.030726207420229912,yaw=-2.5291688442230225,roll=0.011235682293772697", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.7137885689735413, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 215, + "label": "Broken glass", + "last_heartbeat": 0.09994538699999111, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.62", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.032340094447135925,yaw=-2.5291972160339355,roll=0.010941646993160248", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5565459728240967, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 215, + "label": "Crisp packet", + "last_heartbeat": 0.43918579600000385, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.58", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.03162189945578575,yaw=-2.528460741043091,roll=0.010744147002696991", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6089277863502502, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 215, + "label": "Carded blister pack", + "last_heartbeat": 0.33337623099998837, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=5.06", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.030344994738698006,yaw=-2.531757354736328,roll=0.011866731569170952", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6337704062461853, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 214, + "label": "Produce bag", + "last_heartbeat": 0.5924038890000247, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.8", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.021685877814888954,yaw=-2.576737642288208,roll=0.03922276198863983", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.510886013507843, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 212, + "label": "Crisp packet", + "last_heartbeat": 0.387161047999939, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.21", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.021333904936909676,yaw=-2.5751540660858154,roll=0.03939945623278618", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5126315951347351, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 212, + "label": "Drink can", + "last_heartbeat": 0.35668073699991965, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.62", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.022167686372995377,yaw=-2.5750272274017334,roll=0.038983624428510666", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5082154273986816, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 212, + "label": "Tissues", + "last_heartbeat": 0.2797554009999885, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.43", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.022055204957723618,yaw=-2.5754761695861816,roll=0.03863729164004326", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6818053722381592, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 212, + "label": "Glass bottle", + "last_heartbeat": 0.5872588710000173, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.33", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.021176500245928764,yaw=-2.576674461364746,roll=0.0393514446914196", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6461251378059387, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 212, + "label": "Glass bottle", + "last_heartbeat": 0.8723373020000054, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.9", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.02113579772412777,yaw=-2.5758206844329834,roll=0.03883090615272522", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6111947298049927, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 212, + "label": "Crisp packet", + "last_heartbeat": 0.42284541800017905, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.73", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.1569267213344574,yaw=1.739096760749817,roll=0.059471968561410904", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.7094597816467285, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 99, + "label": "Plastic bottle cap", + "last_heartbeat": 0.5886059800000112, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-0.25", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "HOLD", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=-0.013345734216272831,yaw=2.816819190979004,roll=0.018571699038147926", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5480275750160217, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 161, + "label": "Paper straw", + "last_heartbeat": 0.014498732999982167, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=0.45", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" } ] } \ No newline at end of file diff --git a/report/thing_speak.py b/report/thing_speak.py index 6e94f25..ae1d2a7 100644 --- a/report/thing_speak.py +++ b/report/thing_speak.py @@ -28,7 +28,7 @@ def show_thingspeak(self): gps_location = re.findall(r"[-+]?\d*\.\d+|\d+", location_string) label_data = str(self.label.get_label()) - confidence_data = str(self.confidence.get_confidence()) + confidence_data = str(self.confidence.get_confidence()*100) lat = gps_location[0] lon = gps_location[1] battery_status_data = str(self.battery_status.get_battery()) From cf0ed330e968516ac20b74b7bfb8a98bba92bed9 Mon Sep 17 00:00:00 2001 From: Fernando Julio Cendra Date: Thu, 9 Jul 2020 22:53:29 +0800 Subject: [PATCH 22/41] Adding asyncio module --- main.py | 160 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 86 insertions(+), 74 deletions(-) diff --git a/main.py b/main.py index 2e277a0..b421708 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ import time import argparse import logging +import asyncio from serial import serialutil from imutils.video import FPS import cv2 @@ -11,78 +12,89 @@ from report import pixhawk from report import thing_speak -report_path = 'report/report_folder/report.json' -reports_path = 'report/report_folder/reports.json' - -parser = argparse.ArgumentParser(description="Clearbot AI and PController") -parser.add_argument('-v', '--video_out', type=bool, default=False, help="Show the camera video output") -parser.add_argument('--debug', type=bool, default=False, help="Switch to debug mode") -args = parser.parse_args() - -# Added the logging package instead of printing data randomly -if args.debug: - logging.getLogger().setLevel(logging.DEBUG) -else: - logging.getLogger().setLevel(logging.INFO) - -logging.info("accessing video stream...") -vs = cv2.VideoCapture(0) -detector = yolo.Detector("model", use_gpu=True) - -reports = reports.Reports() - - -fps = FPS().start() - -while True: - (grabbed, frame) = vs.read() - if not grabbed: - break - result = detector.detect(frame) - for box in result: - bbox = box["bbox"] - x = bbox["x"] - y = bbox["y"] - w = bbox["width"] - h = bbox["height"] - cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2) - - logging.debug(result) - - for r in result: - # This loop is iterating over all YOLO results - # TODO: Optimise this section so that each frame is sent only once. - try: - pixhawk_init = pixhawk.Pixhawk() - pixhawk_data = pixhawk_init.get_data() - logging.debug(pixhawk_data) - - # post to thingspeak.com - visualize = thing_speak.Thing_speak(r, pixhawk_data) - visualize.show_thingspeak() - - # saved to reports.json - get_report = report.Report(r, pixhawk_data) - get_report.create_report() - get_report.print_report() - get_report.write_report(report_path) - reports.combine(reports_path) - - except serialutil.SerialException as e: - # @utkarsh867: 9th July, 2020 - # I added this exception handler so that the code does not crash when it does not find a serial connection - # to the Pixhawk - logging.error(e) - - if args.video_out: - cv2.imshow("Clearbot", frame) - # If this is not there, frame will not actually show: I did not dig into the explanation - if cv2.waitKey(1) & 0xFF == ord('q'): +async def writeData(pixhawk, thing_speak, report): + try: + pixhawk_init = pixhawk.Pixhawk() + pixhawk_data = pixhawk_init.get_data() + logging.debug(pixhawk_data) + + # post to thingspeak.com + visualize = thing_speak.Thing_speak(r, pixhawk_data) + visualize.show_thingspeak() + + # saved to reports.json + get_report = report.Report(r, pixhawk_data) + get_report.create_report() + get_report.print_report() + get_report.write_report(report_path) + reports.combine(reports_path) + return 0 + + except serialutil.SerialException as e: + # @utkarsh867: 9th July, 2020 + # I added this exception handler so that the code does not crash when it does not find a serial connection + # to the Pixhawk + logging.error(e) + return -1 + +async def main(args): + report_path = 'report/report_folder/report.json' + reports_path = 'report/report_folder/reports.json' + + logging.info("accessing video stream...") + vs = cv2.VideoCapture(0) + detector = yolo.Detector("model", use_gpu=True) + reports = reports.Reports() + fps = FPS().start() + + while True: + (grabbed, frame) = vs.read() + if not grabbed: break - - fps.update() - -fps.stop() -logging.info("approx. FPS: {:.2f}".format(fps.fps())) -vs.release() -cv2.destroyAllWindows() + result = detector.detect(frame) + for box in result: + bbox = box["bbox"] + x = bbox["x"] + y = bbox["y"] + w = bbox["width"] + h = bbox["height"] + cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2) + + logging.debug(result) + + for r in result: + # This loop is iterating over all YOLO results + # TODO: Optimise this section so that each frame is sent only once. + task1 = asyncio.create_task( + writeData(pixhawk, thing_speak, report) + ) + + val = await task1 + print(val) + + if args.video_out: + cv2.imshow("Clearbot", frame) + # If this is not there, frame will not actually show: I did not dig into the explanation + if cv2.waitKey(1) & 0xFF == ord('q'): + break + + fps.update() + + fps.stop() + logging.info("approx. FPS: {:.2f}".format(fps.fps())) + vs.release() + cv2.destroyAllWindows() + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Clearbot AI and PController") + parser.add_argument('-v', '--video_out', type=bool, default=False, help="Show the camera video output") + parser.add_argument('--debug', type=bool, default=False, help="Switch to debug mode") + args = parser.parse_args() + + # Added the logging package instead of printing data randomly + if args.debug: + logging.getLogger().setLevel(logging.DEBUG) + else: + logging.getLogger().setLevel(logging.INFO) + + asyncio.run(main(args)) From 627447c3c0044ee101e392d2621c8965aff6ea92 Mon Sep 17 00:00:00 2001 From: Fernando Julio Cendra Date: Sun, 12 Jul 2020 23:58:00 +0800 Subject: [PATCH 23/41] Implemented multiprocessing module (have not tested yet on jetson) --- main.py | 85 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/main.py b/main.py index b421708..1e53270 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,11 @@ import time import argparse import logging -import asyncio +import multiprocessing from serial import serialutil from imutils.video import FPS import cv2 +from queue import Queue from detector import yolo from report import report @@ -12,34 +13,42 @@ from report import pixhawk from report import thing_speak -async def writeData(pixhawk, thing_speak, report): - try: - pixhawk_init = pixhawk.Pixhawk() - pixhawk_data = pixhawk_init.get_data() - logging.debug(pixhawk_data) - - # post to thingspeak.com - visualize = thing_speak.Thing_speak(r, pixhawk_data) - visualize.show_thingspeak() - - # saved to reports.json - get_report = report.Report(r, pixhawk_data) - get_report.create_report() - get_report.print_report() - get_report.write_report(report_path) - reports.combine(reports_path) - return 0 - - except serialutil.SerialException as e: - # @utkarsh867: 9th July, 2020 - # I added this exception handler so that the code does not crash when it does not find a serial connection - # to the Pixhawk - logging.error(e) - return -1 - -async def main(args): - report_path = 'report/report_folder/report.json' - reports_path = 'report/report_folder/reports.json' +report_path = 'report/report_folder/report.json' +reports_path = 'report/report_folder/reports.json' +q = Queue(maxsize=0) + +def writeData(): + while True: + while True: + if (q.empty == False): + break + + try: + yolo_data = q.get() + pixhawk_init = pixhawk.Pixhawk() + pixhawk_data = pixhawk_init.get_data() + logging.debug(pixhawk_data) + + # post to thingspeak.com + visualize = thing_speak.Thing_speak(yolo_data, pixhawk_data) + visualize.show_thingspeak() + + # saved to reports.json + get_report = report.Report(yolo_data, pixhawk_data) + get_report.create_report() + get_report.print_report() + get_report.write_report(report_path) + reports.combine(reports_path) + return 0 + + except serialutil.SerialException as e: + # @utkarsh867: 9th July, 2020 + # I added this exception handler so that the code does not crash when it does not find a serial connection + # to the Pixhawk + logging.error(e) + return -1 + +def main(args): logging.info("accessing video stream...") vs = cv2.VideoCapture(0) @@ -63,14 +72,9 @@ async def main(args): logging.debug(result) for r in result: + q.put(r) # This loop is iterating over all YOLO results # TODO: Optimise this section so that each frame is sent only once. - task1 = asyncio.create_task( - writeData(pixhawk, thing_speak, report) - ) - - val = await task1 - print(val) if args.video_out: cv2.imshow("Clearbot", frame) @@ -97,4 +101,13 @@ async def main(args): else: logging.getLogger().setLevel(logging.INFO) - asyncio.run(main(args)) + # Set multiprocessing + p1 = multiprocessing.Process(target=main) + p2 = multiprocessing.Process(target=writeData) + + # Start Multiprocessing + p1.start() + p2.start() + + p1.join() + p2.join() \ No newline at end of file From 1b71f6beb679aee30fb7a60ee7b6f48177e305f6 Mon Sep 17 00:00:00 2001 From: Fernando Julio Cendra Date: Mon, 13 Jul 2020 00:21:13 +0800 Subject: [PATCH 24/41] Hide channel id and apikey for thinkspeak --- report/thing_speak.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/report/thing_speak.py b/report/thing_speak.py index ae1d2a7..c25a3c5 100644 --- a/report/thing_speak.py +++ b/report/thing_speak.py @@ -1,12 +1,13 @@ +import os import paho.mqtt.publish as publish from report.clearbot_attributes import * import time import re -channelID = "1092630" -apiKey = "FGN0JQQLW5D88TJ1" +CHANNEL_ID = os.environ.get("CHANNEL_ID") +API_KEY = os.environ.get("API_KEY") -topic = "channels/"+ channelID +"/publish/"+ apiKey +topic = "channels/"+ CHANNEL_ID +"/publish/"+ API_KEY mqttHost = "mqtt.thingspeak.com" tTransport = "tcp" tPort = 1883 From d8fd1c58a43f41c2a952cb1a0a0b0c15a4f3f2fb Mon Sep 17 00:00:00 2001 From: fcendra Date: Mon, 13 Jul 2020 13:22:53 +0800 Subject: [PATCH 25/41] set config.py into .gitignore --- .gitignore | 3 ++- main.py | 45 ++++++++++++++++++++++++++++--------------- report/thing_speak.py | 6 ++---- testing.py | 32 ++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 21 deletions(-) create mode 100644 testing.py diff --git a/.gitignore b/.gitignore index 42f978b..2065c23 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ .venv/ .idea/ __pycache__/ -.DS_Store \ No newline at end of file +.DS_Store +config.py \ No newline at end of file diff --git a/main.py b/main.py index b421708..fddb2bc 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,7 @@ import time import argparse import logging -import asyncio +import multiprocessing from serial import serialutil from imutils.video import FPS import cv2 @@ -12,18 +12,27 @@ from report import pixhawk from report import thing_speak -async def writeData(pixhawk, thing_speak, report): +report_path = 'report/report_folder/report.json' +reports_path = 'report/report_folder/reports.json' + +def writeData(conn): + while True: + msg = conn.recv() + if msg != None: + break + print("Received the message") try: + reports = reports.Reports() pixhawk_init = pixhawk.Pixhawk() pixhawk_data = pixhawk_init.get_data() logging.debug(pixhawk_data) # post to thingspeak.com - visualize = thing_speak.Thing_speak(r, pixhawk_data) + visualize = thing_speak.Thing_speak(msg, pixhawk_data) visualize.show_thingspeak() # saved to reports.json - get_report = report.Report(r, pixhawk_data) + get_report = report.Report(msg, pixhawk_data) get_report.create_report() get_report.print_report() get_report.write_report(report_path) @@ -37,14 +46,10 @@ async def writeData(pixhawk, thing_speak, report): logging.error(e) return -1 -async def main(args): - report_path = 'report/report_folder/report.json' - reports_path = 'report/report_folder/reports.json' - +def main12(conn,args): logging.info("accessing video stream...") vs = cv2.VideoCapture(0) detector = yolo.Detector("model", use_gpu=True) - reports = reports.Reports() fps = FPS().start() while True: @@ -65,12 +70,9 @@ async def main(args): for r in result: # This loop is iterating over all YOLO results # TODO: Optimise this section so that each frame is sent only once. - task1 = asyncio.create_task( - writeData(pixhawk, thing_speak, report) - ) - - val = await task1 - print(val) + conn.send(r) + print("Sent the message to writeData()") + conn.close() if args.video_out: cv2.imshow("Clearbot", frame) @@ -97,4 +99,15 @@ async def main(args): else: logging.getLogger().setLevel(logging.INFO) - asyncio.run(main(args)) + # Multiprocessing process + parent_conn, child_conn = multiprocessing.Pipe() + + p1 = multiprocessing.Process(target=main12, args=(parent_conn, args)) + p2 = multiprocessing.Process(target=writeData, args=(child_conn,)) + + p1.start() + p2.start() + + p1.join() + p2.join() + diff --git a/report/thing_speak.py b/report/thing_speak.py index ae1d2a7..c68a848 100644 --- a/report/thing_speak.py +++ b/report/thing_speak.py @@ -2,11 +2,9 @@ from report.clearbot_attributes import * import time import re +import config -channelID = "1092630" -apiKey = "FGN0JQQLW5D88TJ1" - -topic = "channels/"+ channelID +"/publish/"+ apiKey +topic = "channels/"+ config.CHANNEL_ID +"/publish/"+ config.API_KEY mqttHost = "mqtt.thingspeak.com" tTransport = "tcp" tPort = 1883 diff --git a/testing.py b/testing.py new file mode 100644 index 0000000..711148a --- /dev/null +++ b/testing.py @@ -0,0 +1,32 @@ +from dronekit import connect, VehicleMode, LocationGlobalRelative + + +connection_port="/dev/ttyTHS1" + +baud=57600 +vehicle = connect(connection_port, wait_ready=True, baud=baud) +vehicle.mode = VehicleMode("MANUAL") + + +# print('Autopilot Firmware version: %s' % vehicle.version) +# print('Autopilot capabilities (supports ftp): %s' % vehicle.capabilities.ftp) +print('Global Location: %s' % vehicle.location.global_frame) +# print('Global Location (relative altitude): %s' % vehicle.location.global_relative_frame) +# print('Local Location: %s' % vehicle.location.local_frame) +# print('Attitude: %s' % vehicle.attitude) +# print('Velocity: %s' % vehicle.velocity) +# print('GPS: %s' % vehicle.gps_0) +# print('Groundspeed: %s' % vehicle.groundspeed) +# print('Airspeed: %s' % vehicle.airspeed) +# print('Gimbal status: %s' % vehicle.gimbal) +# print('Battery: %s' % vehicle.battery) +# print('EKF OK?: %s' % vehicle.ekf_ok) +# print('Last Heartbeat: %s' % vehicle.last_heartbeat) +# print('Rangefinder: %s' % vehicle.rangefinder) +# print('Rangefinder distance: %s' % vehicle.rangefinder.distance) +# print('Rangefinder voltage: %s' % vehicle.rangefinder.voltage) +# print('Heading: %s' % vehicle.heading) +# print('Is Armable?: %s' % vehicle.is_armable) +# print('System status: %s' % vehicle.system_status.state) +# print('Mode: %s' % vehicle.mode.name) +# print('Armed: %s' % vehicle.armed) From 3cb3496016c3783ffdbb9389c9d080a41fdd849e Mon Sep 17 00:00:00 2001 From: fcendra Date: Mon, 13 Jul 2020 13:30:05 +0800 Subject: [PATCH 26/41] add conifg.py into .gitignore --- report/thing_speak.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/report/thing_speak.py b/report/thing_speak.py index aaeede7..a94984e 100644 --- a/report/thing_speak.py +++ b/report/thing_speak.py @@ -5,10 +5,8 @@ import re import config -CHANNEL_ID = os.environ.get("CHANNEL_ID") -API_KEY = os.environ.get("API_KEY") -topic = "channels/"+ CHANNEL_ID +"/publish/"+ API_KEY +topic = "channels/"+ config.CHANNEL_ID +"/publish/"+ config.API_KEY mqttHost = "mqtt.thingspeak.com" tTransport = "tcp" tPort = 1883 From 0b306ce656d702544750baefd024341b679bc4ae Mon Sep 17 00:00:00 2001 From: fcendra Date: Mon, 13 Jul 2020 14:21:18 +0800 Subject: [PATCH 27/41] set up multiprocess moduleinto main.py --- main.py | 6 +++++- report/thing_speak.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index f50786d..a9e9351 100644 --- a/main.py +++ b/main.py @@ -18,6 +18,7 @@ q = Queue(maxsize=0) def writeData(): + print("THinkspeak is starting") while True: while True: if (q.empty == False): @@ -48,7 +49,9 @@ def writeData(): logging.error(e) return -1 -def main(args): +#def main(args): +def main(): + print("Yolo is starting") logging.info("accessing video stream...") vs = cv2.VideoCapture(0) @@ -92,6 +95,7 @@ def main(args): parser = argparse.ArgumentParser(description="Clearbot AI and PController") parser.add_argument('-v', '--video_out', type=bool, default=False, help="Show the camera video output") parser.add_argument('--debug', type=bool, default=False, help="Switch to debug mode") + global args args = parser.parse_args() # Added the logging package instead of printing data randomly diff --git a/report/thing_speak.py b/report/thing_speak.py index a94984e..c0689b6 100644 --- a/report/thing_speak.py +++ b/report/thing_speak.py @@ -3,7 +3,7 @@ from report.clearbot_attributes import * import time import re -import config +from report import config topic = "channels/"+ config.CHANNEL_ID +"/publish/"+ config.API_KEY From 108d0f1ecf6154e6dfd8c8182aaae04024bd40ad Mon Sep 17 00:00:00 2001 From: utkarsh867 Date: Mon, 13 Jul 2020 20:50:48 +0530 Subject: [PATCH 28/41] Adds tiny weights to the project --- detector/model/clearbot-tiny.cfg | 281 +++++++++++++++++++++++++++ detector/model/clearbot-tiny.weights | 3 + report/main.py | 2 +- 3 files changed, 285 insertions(+), 1 deletion(-) create mode 100644 detector/model/clearbot-tiny.cfg create mode 100644 detector/model/clearbot-tiny.weights diff --git a/detector/model/clearbot-tiny.cfg b/detector/model/clearbot-tiny.cfg new file mode 100644 index 0000000..5a6b22b --- /dev/null +++ b/detector/model/clearbot-tiny.cfg @@ -0,0 +1,281 @@ +[net] +# Testing +# batch=1 +# subdivisions=1 +# Training +batch=64 +subdivisions=16 +width=416 +height=416 +channels=3 +momentum=0.9 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.00261 +burn_in=1000 +max_batches = 128000 +policy=steps +steps=102400,115200 +scales=.1,.1 + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1 +groups=2 +group_id=1 + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers = -1,-2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[route] +layers = -6,-1 + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1 +groups=2 +group_id=1 + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers = -1,-2 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[route] +layers = -6,-1 + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1 +groups=2 +group_id=1 + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers = -1,-2 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[route] +layers = -6,-1 + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +################################## + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=207 +activation=linear + + + +[yolo] +mask = 3,4,5 +anchors = 9, 7, 30, 25, 61, 51, 95, 95, 191,120, 234,242 +classes=64 +num=6 +jitter=.3 +scale_x_y = 1.05 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +ignore_thresh = .7 +truth_thresh = 1 +random=0 +resize=1.5 +nms_kind=greedynms +beta_nms=0.6 + +[route] +layers = -4 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[upsample] +stride=2 + +[route] +layers = -1, 23 + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=207 +activation=linear + +[yolo] +mask = 1,2,3 +anchors = 9, 7, 30, 25, 61, 51, 95, 95, 191,120, 234,242 +classes=64 +num=6 +jitter=.3 +scale_x_y = 1.05 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +ignore_thresh = .7 +truth_thresh = 1 +random=0 +resize=1.5 +nms_kind=greedynms +beta_nms=0.6 diff --git a/detector/model/clearbot-tiny.weights b/detector/model/clearbot-tiny.weights new file mode 100644 index 0000000..ff99f98 --- /dev/null +++ b/detector/model/clearbot-tiny.weights @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:eb0d0dfce42caaa9e6a171adcd2ffc2a26139276fc32416a5ac5ac30d522662f +size 43914873 diff --git a/report/main.py b/report/main.py index 538cfe7..9e403ac 100644 --- a/report/main.py +++ b/report/main.py @@ -11,7 +11,7 @@ print("[INFO] accessing video stream...") vs = cv2.VideoCapture(0) -detector = yolo.Detector("model", use_gpu=True, weights_file="clearbot_26_06_20.weights") +detector = yolo.Detector("model", use_gpu=True, weights_file="clearbot.weights") reports = Reports() previous = 0 From 125479b57765d0eb84485ef7de2a3bbd9d0cc7c2 Mon Sep 17 00:00:00 2001 From: utkarsh867 Date: Tue, 14 Jul 2020 00:08:38 +0530 Subject: [PATCH 29/41] Major code refactoring --- detector/detector.py | 123 ++++++++ detector/yolo.py | 129 --------- main.py | 34 +-- report/attributes.py | 166 +++++++++++ report/clearbot_attributes/Air_speed.py | 7 - report/clearbot_attributes/Attitude.py | 7 - report/clearbot_attributes/Battery_status.py | 7 - .../Check_vehicle_armed.py | 6 - report/clearbot_attributes/Confidence.py | 7 - report/clearbot_attributes/Confidence.pyc | Bin 655 -> 0 bytes report/clearbot_attributes/Ekf_ok.py | 6 - .../clearbot_attributes/Firmware_version.py | 8 - report/clearbot_attributes/Gimbal_status.py | 7 - report/clearbot_attributes/Gps.py | 7 - report/clearbot_attributes/Ground_speed.py | 7 - report/clearbot_attributes/Heading.py | 6 - report/clearbot_attributes/Label.py | 6 - report/clearbot_attributes/Label.pyc | Bin 625 -> 0 bytes report/clearbot_attributes/Last_heartbeat.py | 6 - report/clearbot_attributes/Location.py | 6 - report/clearbot_attributes/Location.pyc | Bin 981 -> 0 bytes .../Range_finder_distance.py | 6 - .../Range_finder_voltage.py | 6 - report/clearbot_attributes/System_status.py | 6 - .../Vehicle_capabilities.py | 7 - .../clearbot_attributes/Vehicle_is_armable.py | 6 - .../clearbot_attributes/Vehicle_mode_name.py | 6 - report/clearbot_attributes/Velocity.py | 7 - report/clearbot_attributes/__init__.py | 4 - report/main.py | 36 --- report/pixhawk.py | 266 +++++++++--------- report/report.py | 110 ++++---- report/{thing_speak.py => thingspeak.py} | 24 +- 33 files changed, 506 insertions(+), 523 deletions(-) create mode 100644 detector/detector.py delete mode 100644 detector/yolo.py create mode 100644 report/attributes.py delete mode 100644 report/clearbot_attributes/Air_speed.py delete mode 100644 report/clearbot_attributes/Attitude.py delete mode 100644 report/clearbot_attributes/Battery_status.py delete mode 100644 report/clearbot_attributes/Check_vehicle_armed.py delete mode 100644 report/clearbot_attributes/Confidence.py delete mode 100644 report/clearbot_attributes/Confidence.pyc delete mode 100644 report/clearbot_attributes/Ekf_ok.py delete mode 100644 report/clearbot_attributes/Firmware_version.py delete mode 100644 report/clearbot_attributes/Gimbal_status.py delete mode 100644 report/clearbot_attributes/Gps.py delete mode 100644 report/clearbot_attributes/Ground_speed.py delete mode 100644 report/clearbot_attributes/Heading.py delete mode 100644 report/clearbot_attributes/Label.py delete mode 100644 report/clearbot_attributes/Label.pyc delete mode 100644 report/clearbot_attributes/Last_heartbeat.py delete mode 100644 report/clearbot_attributes/Location.py delete mode 100644 report/clearbot_attributes/Location.pyc delete mode 100644 report/clearbot_attributes/Range_finder_distance.py delete mode 100644 report/clearbot_attributes/Range_finder_voltage.py delete mode 100644 report/clearbot_attributes/System_status.py delete mode 100644 report/clearbot_attributes/Vehicle_capabilities.py delete mode 100644 report/clearbot_attributes/Vehicle_is_armable.py delete mode 100644 report/clearbot_attributes/Vehicle_mode_name.py delete mode 100644 report/clearbot_attributes/Velocity.py delete mode 100644 report/clearbot_attributes/__init__.py delete mode 100644 report/main.py rename report/{thing_speak.py => thingspeak.py} (68%) diff --git a/detector/detector.py b/detector/detector.py new file mode 100644 index 0000000..cc5d850 --- /dev/null +++ b/detector/detector.py @@ -0,0 +1,123 @@ +import numpy as np +import cv2 +import os +import functools, operator + +import logging + + +class Detector: + weights_file = None + config_file = None + names_file = None + + confidence_threshold = 0 + nms_threshold = 0 + LABELS = [] + + net = None + ln = None + + def __init__(self, model_path="model", use_gpu=False, confidence_thres=0.5, nms_thres=0.3, + weights_file="clearbot.weights", config_file="clearbot.cfg", names_file="clearbot.names"): + + self.confidence_threshold = confidence_thres + self.nms_threshold = nms_thres + + self.weights_file = os.path.sep.join([os.path.dirname(os.path.realpath(__file__)), model_path, weights_file]) + self.config_file = os.path.sep.join([os.path.dirname(os.path.realpath(__file__)), model_path, config_file]) + self.names_file = os.path.sep.join([os.path.dirname(os.path.realpath(__file__)), model_path, names_file]) + logging.debug("Finished initialising model file paths") + + try: + self.LABELS = open(self.names_file).read().strip().split("\n") + logging.debug(f"Loaded labels from the names file: \n{self.LABELS}") + except Exception as e: + logging.error(e) + + try: + logging.debug("Loading Darknet model") + self.net = cv2.dnn.readNetFromDarknet(self.config_file, self.weights_file) + logging.debug("Finished loading Darknet model") + except Exception as e: + logging.error(e) + + if use_gpu: + logging.info("Will try to use GPU backend") + self.net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA) + self.net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA) + else: + logging.info("Using CPU only") + + self.ln = self.net.getLayerNames() + + unconnected_layers = functools.reduce(operator.iconcat, self.net.getUnconnectedOutLayers(), []) + logging.debug(f"Indexes of unconnected layers: {unconnected_layers}") + self.ln = [self.ln[i - 1] for i in unconnected_layers] + logging.debug(f"Output layers for YOLO are: {self.ln}") + + def detect(self, frame): + """ + Detect the objects in the frame + :param frame: Frame that has been captured from the OpenCV video stream + :return: dict object with the objects and the bounding boxes + """ + (H, W) = frame.shape[:2] + blob = cv2.dnn.blobFromImage(frame, 1 / 255.0, (416, 416), swapRB=True, crop=False) + + self.net.setInput(blob) + layer_outputs = self.net.forward(self.ln) + + boxes = [] + confidences = [] + class_ids = [] + + for output in layer_outputs: + for detection in output: + scores = detection[5:] + class_id = np.argmax(scores) + confidence = scores[class_id] + + if confidence > self.confidence_threshold: + box = detection[0:4] * np.array([W, H, W, H]) + (centerX, centerY, width, height) = box.astype("int") + + x = int(centerX - (width / 2)) + y = int(centerY - (width / 2)) + + # Adding int(width) and int(height) is really important for some reason. + # Removing it gives an error in NMSBoxes() call + # Shall figure out soon and write a justification here. + boxes.append([x, y, int(width), int(height)]) + confidences.append(float(confidence)) + class_ids.append(class_id) + + logging.debug((boxes, confidences, self.confidence_threshold, self.nms_threshold)) + indexes = cv2.dnn.NMSBoxes(boxes, confidences, self.confidence_threshold, self.nms_threshold) + logging.debug(f"Indexes: {indexes}") + if len(indexes) > 0: + indexes = indexes.flatten() + return map(lambda idx: self.detected_to_result(boxes[idx], confidences[idx], class_ids[idx]), indexes) + + def detected_to_result(self, box, confidence, class_id): + (x, y) = (box[0], box[1]) + (w, h) = (box[2], box[3]) + + label = self.LABELS[class_id] + + return { + "label": label, + "confidence": confidence, + "bbox": { + "x": x, + "y": y, + "width": w, + "height": h + } + } + + +if __name__ == "__main__": + logging.getLogger().setLevel(logging.DEBUG) + + detector = Detector() diff --git a/detector/yolo.py b/detector/yolo.py deleted file mode 100644 index 145619d..0000000 --- a/detector/yolo.py +++ /dev/null @@ -1,129 +0,0 @@ -import numpy as np -import cv2 -import os - - -class Detector: - net = None - confidence_threshold = 0 - nms_threshold = 0 - LABELS = None - ln = None - - def __init__(self, model_path, use_gpu=False, confidence_thres=0.5, nms_thres=0.3, weights_file="clearbot_26_06_20.weights", - config_file="clearbot.cfg", names_file="clearbot.names"): - """ - Initialise a instance for YOLOv4 object detection. - :param model_path: The path of the model relative to the python script - :param use_gpu: Whether to use GPU CUDA or not. - :param confidence_thres: The confidence threshold of the results (0 to 1). - :param nms_thres: The NMS threshold of the results - """ - self.confidence_threshold = confidence_thres - self.nms_threshold = nms_thres - - labels_path = os.path.sep.join([os.path.dirname(os.path.realpath(__file__)), model_path, names_file]) - self.LABELS = open(labels_path).read().strip().split("\n") - - weights_path = os.path.sep.join([os.path.dirname(os.path.realpath(__file__)), model_path, weights_file]) - config_path = os.path.sep.join([os.path.dirname(os.path.realpath(__file__)), model_path, config_file]) - print("[INFO] loading YOLO from disk...") - self.net = cv2.dnn.readNetFromDarknet(config_path, weights_path) - - if use_gpu: - # set CUDA as the preferable backend and target - print("[INFO] setting preferable backend and target to CUDA...") - self.net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA) - self.net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA) - - # determine only the *output* layer names that we need from YOLO - self.ln = self.net.getLayerNames() - self.ln = [self.ln[i[0] - 1] for i in self.net.getUnconnectedOutLayers()] - - def detect(self, frame): - """ - Detect the objects in the frame - :param frame: Frame that has been captured from the OpenCV video stream - :return: dict object with the objects and the bounding boxes - """ - - # construct a blob from the input frame and then perform a forward - # pass of the YOLO object detector, giving us our bounding boxes - # and associated probabilities - (H, W) = frame.shape[:2] - blob = cv2.dnn.blobFromImage( - frame, 1 / 255.0, (416, 416), swapRB=True, crop=False - ) - self.net.setInput(blob) - layer_outputs = self.net.forward(self.ln) - - boxes = [] - confidences = [] - class_ids = [] - - for output in layer_outputs: - # loop over each of the detections - for detection in output: - # extract the class ID and confidence (i.e., probability) - # of the current object detection - scores = detection[5:] - class_id = np.argmax(scores) - confidence = scores[class_id] - - # filter out weak predictions by ensuring the detected - # probability is greater than the minimum probability - if confidence > self.confidence_threshold: - # scale the bounding box coordinates back relative to - # the size of the image, keeping in mind that YOLO - # actually returns the center (x, y)-coordinates of - # the bounding box followed by the boxes' width and - # height - box = detection[0:4] * np.array([W, H, W, H]) - (centerX, centerY, width, height) = box.astype("int") - - # use the center (x, y)-coordinates to derive the top - # and and left corner of the bounding box - x = int(centerX - (width / 2)) - y = int(centerY - (height / 2)) - - # update our list of bounding box coordinates, - # confidences, and class IDs - boxes.append([x, y, int(width), int(height)]) - confidences.append(float(confidence)) - class_ids.append(class_id) - - # Gives the indexes of the boxes that we should use - idxs = cv2.dnn.NMSBoxes(boxes, confidences, self.confidence_threshold, self.nms_threshold) - result = [] - - # Extract the results from the detector - if len(idxs) > 0: - # loop over the indexes we are keeping - for i in idxs.flatten(): - # extract the bounding box coordinates - (x, y) = (boxes[i][0], boxes[i][1]) - (w, h) = (boxes[i][2], boxes[i][3]) - class_id = class_ids[i] - label = self.LABELS[class_id] - confidence = confidences[i] - result.append({ - "label": label, - "confidence": confidence, - "bbox": { - "x": x, - "y": y, - "width": w, - "height": h - } - }) - return result - -# Sample code for using object detection -# print("[INFO] accessing video stream...") -# vs = cv2.VideoCapture(0) -# detector = Detector("model", use_gpu=True, weights_file="clearbot_26_06_20.weights") -# while True: -# (grabbed, frame) = vs.read() -# if not grabbed: -# break -# result = detector.detect(frame) diff --git a/main.py b/main.py index a9e9351..429ee98 100644 --- a/main.py +++ b/main.py @@ -7,21 +7,22 @@ import cv2 from queue import Queue -from detector import yolo +from detector import detector as dt from report import report from report import reports from report import pixhawk -from report import thing_speak +from report import thingspeak report_path = 'report/report_folder/report.json' reports_path = 'report/report_folder/reports.json' q = Queue(maxsize=0) + def writeData(): - print("THinkspeak is starting") while True: while True: if (q.empty == False): + logging.debug("Message queue is empty") break try: @@ -31,7 +32,8 @@ def writeData(): logging.debug(pixhawk_data) # post to thingspeak.com - visualize = thing_speak.Thing_speak(yolo_data, pixhawk_data) + logging.debug(f"Sending data to ThingSpeak:\n{yolo_data}\n{pixhawk_data}") + visualize = thingspeak.ThingSpeak(yolo_data, pixhawk_data) visualize.show_thingspeak() # saved to reports.json @@ -41,7 +43,7 @@ def writeData(): get_report.write_report(report_path) reports.combine(reports_path) return 0 - + except serialutil.SerialException as e: # @utkarsh867: 9th July, 2020 # I added this exception handler so that the code does not crash when it does not find a serial connection @@ -49,13 +51,13 @@ def writeData(): logging.error(e) return -1 -#def main(args): -def main(): + +def main(params): print("Yolo is starting") logging.info("accessing video stream...") vs = cv2.VideoCapture(0) - detector = yolo.Detector("model", use_gpu=True) + detector = dt.Detector("model", use_gpu=True) fps = FPS().start() while True: @@ -75,37 +77,37 @@ def main(): for r in result: q.put(r) - # This loop is iterating over all YOLO results - # TODO: Optimise this section so that each frame is sent only once. + # This loop is iterating over all YOLO results + # TODO: Optimise this section so that each frame is sent only once. - if args.video_out: + if params.video_out: cv2.imshow("Clearbot", frame) # If this is not there, frame will not actually show: I did not dig into the explanation if cv2.waitKey(1) & 0xFF == ord('q'): break fps.update() - + fps.stop() logging.info("approx. FPS: {:.2f}".format(fps.fps())) vs.release() cv2.destroyAllWindows() + if __name__ == "__main__": parser = argparse.ArgumentParser(description="Clearbot AI and PController") parser.add_argument('-v', '--video_out', type=bool, default=False, help="Show the camera video output") parser.add_argument('--debug', type=bool, default=False, help="Switch to debug mode") - global args args = parser.parse_args() # Added the logging package instead of printing data randomly if args.debug: - logging.getLogger().setLevel(logging.DEBUG) + logging.getLogger('root').setLevel(logging.DEBUG) else: - logging.getLogger().setLevel(logging.INFO) + logging.getLogger('root').setLevel(logging.INFO) # Set multiprocessing - p1 = multiprocessing.Process(target=main) + p1 = multiprocessing.Process(target=main, args=(args,)) p2 = multiprocessing.Process(target=writeData) # Start Multiprocessing diff --git a/report/attributes.py b/report/attributes.py new file mode 100644 index 0000000..16ff98c --- /dev/null +++ b/report/attributes.py @@ -0,0 +1,166 @@ +class AirSpeed: + def __init__(self, y): + self.y = y[7] + + def get_air_speed(self): + return self.y + + +class Altitude: + def __init__(self, y): + self.y = y[3] + + def get_altitude(self): + return self.y + + +class BatteryStatus: + def __init__(self, y): + self.y = y[9] + + def get_battery_status(self): + return self.y + + +class CheckVehicleArmed: + def __init__(self, y): + self.y = y[18] + + def get_armed_status(self): + return self.y + + +class Confidence: + def __init__(self, y): + self.y = y["confidence"] + + def get_confidence(self): + return self.y + + +class EkfOK: + def __init__(self, y): + self.y = y[10] + + def get_ekf_status(self): + return self.y + + +class FirmwareVersion: + def __init__(self, y): + self.y = y[0] + + def __version__(self): + return self.y + + +class GimbalStatus: + def __init__(self, y): + self.y = y[8] + + def get_gimbal_status(self): + return self.y + + +class GPS: + def __init__(self, y): + self.y = y[5] + + def get_gps(self): + return self.y + + +class GroundSpeed: + def __init__(self, y): + self.y = y[6] + + def get_ground_speed(self): + return self.y + + +class Heading: + def __init__(self, y): + self.y = y[14] + + def get_heading(self): + return self.y + + +class Label: + def __init__(self, x): + self.x = x["label"] + + def get_label(self): + return self.x + + +class LastHeartbeat: + def __init__(self, y): + self.y = y[11] + + def get_last_heartbeat(self): + return self.y + + +class Location: + def __init__(self, z): + self.z = z[2] + + def get_coordinates(self): + return self.z + + +class RangeFinderDistance: + def __init__(self, y): + self.y = y[12] + + def get_distance(self): + return self.y + + +class RangeFinderVoltage: + def __init__(self, y): + self.y = y[13] + + def get_voltage(self): + return self.y + + +class SystemStatus: + def __init__(self, y): + self.y = y[16] + + def get_system_status(self): + return self.y + + +class VehicleCapabilities: + def __init__(self, y): + self.y = y[1] + + def get_capabilities(self): + return self.y + + +class VehicleArmable: + def __init__(self, y): + self.y = y[15] + + def get_armable(self): + return self.y + + +class VehicleModeName: + def __init__(self, y): + self.y = y[17] + + def get_mode_name(self): + return self.y + + +class Velocity: + def __init__(self, y): + self.y = y[4] + + def get_velocity(self): + return self.y diff --git a/report/clearbot_attributes/Air_speed.py b/report/clearbot_attributes/Air_speed.py deleted file mode 100644 index 453813b..0000000 --- a/report/clearbot_attributes/Air_speed.py +++ /dev/null @@ -1,7 +0,0 @@ -class Air_speed: - def __init__(self, y): - self.y = y[7] - - def get_air_speed(self): - return self.y - \ No newline at end of file diff --git a/report/clearbot_attributes/Attitude.py b/report/clearbot_attributes/Attitude.py deleted file mode 100644 index 79f3a5f..0000000 --- a/report/clearbot_attributes/Attitude.py +++ /dev/null @@ -1,7 +0,0 @@ -class Attitude: - def __init__(self, y): - self.y = y[3] - - def get_attitude(self): - return self.y - \ No newline at end of file diff --git a/report/clearbot_attributes/Battery_status.py b/report/clearbot_attributes/Battery_status.py deleted file mode 100644 index b3533a4..0000000 --- a/report/clearbot_attributes/Battery_status.py +++ /dev/null @@ -1,7 +0,0 @@ -class Battery_status: - def __init__(self, y): - self.y = y[9] - - def get_battery(self): - return self.y - \ No newline at end of file diff --git a/report/clearbot_attributes/Check_vehicle_armed.py b/report/clearbot_attributes/Check_vehicle_armed.py deleted file mode 100644 index b9e6919..0000000 --- a/report/clearbot_attributes/Check_vehicle_armed.py +++ /dev/null @@ -1,6 +0,0 @@ -class Check_vehicle_armed: - def __init__(self, y): - self.y = y[18] - - def get_check(self): - return self.y \ No newline at end of file diff --git a/report/clearbot_attributes/Confidence.py b/report/clearbot_attributes/Confidence.py deleted file mode 100644 index 9c80331..0000000 --- a/report/clearbot_attributes/Confidence.py +++ /dev/null @@ -1,7 +0,0 @@ -class Confidence: - def __init__(self, y): - self.y = y["confidence"] - - def get_confidence(self): - return self.y - \ No newline at end of file diff --git a/report/clearbot_attributes/Confidence.pyc b/report/clearbot_attributes/Confidence.pyc deleted file mode 100644 index f03e7a77347a5edfe2c877637eee206a6a693222..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 655 zcmbu6zfQw25XR3je=C(0i6_WH{Q?Lfx_3w>GGG6@T6qj(k)hK+X-(awI{@$#PS&cvl$B+qzHE*^bEocmp3zh~RPwtuGk8~heug}5_or*Hh2&aG!ucS`U8__G#U5&h;sysk19s+Kgg>~Otfyy-^ zoB=FREm#5Ex)?=jNxCWvv|EOK+%Rbd*a_MZnKZd7S#O>&^6@1RBM%SOEj8ClM25ge z_27G}T4$SK;iE$IuJxT&gWdWes^s^4`y5a3voY(#8nF}?4e98xWjYTm@p=ydwk7Bu+j cwt45@qErBcx2HjmlQLl7GXsEQX-Kle%yBv_V7p?ohwRpZ)HR9kb_ar1S96IKiJF+LbM}~{or0-Z!8a-e^jr@O-m=K4r15*DW3dlp>;b{kL`^7eb})N;gu1sVD~ z3onBgWJ@eo(Jw4;ir3`lwDtf1 diff --git a/report/clearbot_attributes/Range_finder_distance.py b/report/clearbot_attributes/Range_finder_distance.py deleted file mode 100644 index 7c32b82..0000000 --- a/report/clearbot_attributes/Range_finder_distance.py +++ /dev/null @@ -1,6 +0,0 @@ -class Range_finder_distance: - def __init__(self, y): - self.y = y[12] - - def get_distance(self): - return self.y \ No newline at end of file diff --git a/report/clearbot_attributes/Range_finder_voltage.py b/report/clearbot_attributes/Range_finder_voltage.py deleted file mode 100644 index 00a0cf5..0000000 --- a/report/clearbot_attributes/Range_finder_voltage.py +++ /dev/null @@ -1,6 +0,0 @@ -class Range_finder_voltage: - def __init__(self, y): - self.y = y[13] - - def get_voltage(self): - return self.y \ No newline at end of file diff --git a/report/clearbot_attributes/System_status.py b/report/clearbot_attributes/System_status.py deleted file mode 100644 index c3b4698..0000000 --- a/report/clearbot_attributes/System_status.py +++ /dev/null @@ -1,6 +0,0 @@ -class System_status: - def __init__(self, y): - self.y = y[16] - - def get_system_status(self): - return self.y \ No newline at end of file diff --git a/report/clearbot_attributes/Vehicle_capabilities.py b/report/clearbot_attributes/Vehicle_capabilities.py deleted file mode 100644 index 5386c93..0000000 --- a/report/clearbot_attributes/Vehicle_capabilities.py +++ /dev/null @@ -1,7 +0,0 @@ -class Vehicle_capabilities: - def __init__(self, y): - self.y = y[1] - - def get_capabilities(self): - return self.y - \ No newline at end of file diff --git a/report/clearbot_attributes/Vehicle_is_armable.py b/report/clearbot_attributes/Vehicle_is_armable.py deleted file mode 100644 index ed78573..0000000 --- a/report/clearbot_attributes/Vehicle_is_armable.py +++ /dev/null @@ -1,6 +0,0 @@ -class Vehicle_is_armable: - def __init__(self, y): - self.y = y[15] - - def get_armable(self): - return self.y \ No newline at end of file diff --git a/report/clearbot_attributes/Vehicle_mode_name.py b/report/clearbot_attributes/Vehicle_mode_name.py deleted file mode 100644 index 2564984..0000000 --- a/report/clearbot_attributes/Vehicle_mode_name.py +++ /dev/null @@ -1,6 +0,0 @@ -class Vehicle_mode_name: - def __init__(self, y): - self.y = y[17] - - def get_name(self): - return self.y \ No newline at end of file diff --git a/report/clearbot_attributes/Velocity.py b/report/clearbot_attributes/Velocity.py deleted file mode 100644 index 8f715ad..0000000 --- a/report/clearbot_attributes/Velocity.py +++ /dev/null @@ -1,7 +0,0 @@ -class Velocity: - def __init__(self, y): - self.y = y[4] - - def get_velocity(self): - return self.y - \ No newline at end of file diff --git a/report/clearbot_attributes/__init__.py b/report/clearbot_attributes/__init__.py deleted file mode 100644 index 1cb91d4..0000000 --- a/report/clearbot_attributes/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from os.path import dirname, basename, isfile, join -import glob -modules = glob.glob(join(dirname(__file__), "*.py")) -__all__ = [ basename(f)[:-3] for f in modules if isfile(f) and not f.endswith('__init__.py')] \ No newline at end of file diff --git a/report/main.py b/report/main.py deleted file mode 100644 index 9e403ac..0000000 --- a/report/main.py +++ /dev/null @@ -1,36 +0,0 @@ -import time -import cv2 -from detector import yolo - -from .pixhawk import Pixhawk -from .report import Report -from .reports import Reports - -report_path = 'report_folder/report.json' -reports_path = 'report_folder/reports.json' - -print("[INFO] accessing video stream...") -vs = cv2.VideoCapture(0) -detector = yolo.Detector("model", use_gpu=True, weights_file="clearbot.weights") - -reports = Reports() -previous = 0 - -while True: - (grabbed, frame) = vs.read() - if not grabbed: - break - result = detector.detect(frame) - current = len(result) - if (current > 0 and current > previous): - result_object = result[current - 1] - pixhawk = Pixhawk() - yolo_result = result_object - pixhawk_location = str(pixhawk.do_capture_global_location()) - report = Report(yolo_result, pixhawk_location) - report.create_report() - report.print_report() - report.write_report(report_path) - reports.combine(reports_path) - previous = current - time.sleep(5) diff --git a/report/pixhawk.py b/report/pixhawk.py index c2e0800..a4543c6 100644 --- a/report/pixhawk.py +++ b/report/pixhawk.py @@ -1,143 +1,143 @@ from dronekit import connect, VehicleMode, LocationGlobalRelative + class Pixhawk: - vehicle = None - - def __init__(self, connection_port="/dev/ttyTHS1", baud=57600): - - self.vehicle = connect(connection_port, wait_ready=True, baud=baud) - self.vehicle.mode = VehicleMode("MANUAL") - self.result = [] - - def firmware_version(self): - return self.vehicle.version - - def vehicle_capabilities(self): - return self.vehicle.capabilities.ftp - - def do_capture_global_location(self): - return self.vehicle.location.global_frame - - def do_capture_relative_global_location(self): - return self.vehicle.location.global_relative_frame - - def do_capture_altitude(self): - return self.vehicle.altitude - - def do_capture_velocity(self): - return self.vehicle.velocity - - def do_capture_gps(self): - return self.vehicle.gps_0 - - def do_capture_ground_speed(self): - return self.vehicle.groundspeed - - def do_capture_air_speed(self): - return self.vehicle.airspeed - - def gimbal_status(self): - return self.vehicle.gimbal - - def battery_status(self): - return self.vehicle.battery - - def EKF_OK(self): - return self.vehicle.ekf_ok - - def last_heartbeat(self): - return self.vehicle.last_heartbeat - - def range_finder(self): - return self.vehicle.rangefinder - - def range_finder_distance(self): - return self.vehicle.rangefinder.distance - - def range_finder_voltage(self): - return self.vehicle.rangefinder.voltage - - def heading(self): - return self.vehicle.heading - - def vehicle_is_armable(self): - return self.vehicle.is_armable - - def system_status(self): - return self.vehicle.system_status.state - - def vehicle_mode_name(self): - return self.vehicle.mode.name - - def check_vehicle_armed(self): - return self.vehicle.armed - - def get_data(self): - # self.result.append + vehicle = None + + def __init__(self, connection_port="/dev/ttyTHS1", baud=57600): + self.vehicle = connect(connection_port, wait_ready=True, baud=baud) + self.vehicle.mode = VehicleMode("MANUAL") + self.result = [] + + def firmware_version(self): + return self.vehicle.version + + def vehicle_capabilities(self): + return self.vehicle.capabilities.ftp + + def do_capture_global_location(self): + return self.vehicle.location.global_frame + + def do_capture_relative_global_location(self): + return self.vehicle.location.global_relative_frame + + def do_capture_altitude(self): + return self.vehicle.altitude + + def do_capture_velocity(self): + return self.vehicle.velocity + + def do_capture_gps(self): + return self.vehicle.gps_0 + + def do_capture_ground_speed(self): + return self.vehicle.groundspeed + + def do_capture_air_speed(self): + return self.vehicle.airspeed + + def gimbal_status(self): + return self.vehicle.gimbal + + def battery_status(self): + return self.vehicle.battery + + def EKF_OK(self): + return self.vehicle.ekf_ok + + def last_heartbeat(self): + return self.vehicle.last_heartbeat + + def range_finder(self): + return self.vehicle.rangefinder + + def range_finder_distance(self): + return self.vehicle.rangefinder.distance + + def range_finder_voltage(self): + return self.vehicle.rangefinder.voltage + + def heading(self): + return self.vehicle.heading + + def vehicle_is_armable(self): + return self.vehicle.is_armable + + def system_status(self): + return self.vehicle.system_status.state + + def vehicle_mode_name(self): + return self.vehicle.mode.name + + def check_vehicle_armed(self): + return self.vehicle.armed + + def get_data(self): + # self.result.append # "firmware_version" : self.vehicle.version, # "vehicle_capabilities" : self.vehicle.capabilities.ftp, # "location" :self.vehicle.location.global_frame, - # "altitude" : self.vehicle.attitude, - # "velocity" : self.vehicle.velocity, - # "gps" : self.vehicle.gps_0, - # "ground_speed" : self.vehicle.groundspeed, - # "air_speed" : self.vehicle.airspeed, - # "gimbal_status" : self.vehicle.gimbal, - # "battery_status" : self.vehicle.battery, - # "EKF_OK" : self.vehicle.ekf_ok, - # "last_heartbeat" : self.vehicle.last_heartbeat, - # "range_finder_distance" : self.vehicle.rangefinder.distance, - # "range_finder_voltage" : self.vehicle.rangefinder.voltage, - # "heading" : self.vehicle.heading, - # "vehicle_is_armable" : self.vehicle.is_armable, - # "system_status" : self.vehicle.system_status.state, - # "vehicle_mode_name" : self.vehicle.mode.name, - # "check_vehicle_armed" : self.vehicle.armed + # "altitude" : self.vehicle.attitude, + # "velocity" : self.vehicle.velocity, + # "gps" : self.vehicle.gps_0, + # "ground_speed" : self.vehicle.groundspeed, + # "air_speed" : self.vehicle.airspeed, + # "gimbal_status" : self.vehicle.gimbal, + # "battery_status" : self.vehicle.battery, + # "EKF_OK" : self.vehicle.ekf_ok, + # "last_heartbeat" : self.vehicle.last_heartbeat, + # "range_finder_distance" : self.vehicle.rangefinder.distance, + # "range_finder_voltage" : self.vehicle.rangefinder.voltage, + # "heading" : self.vehicle.heading, + # "vehicle_is_armable" : self.vehicle.is_armable, + # "system_status" : self.vehicle.system_status.state, + # "vehicle_mode_name" : self.vehicle.mode.name, + # "check_vehicle_armed" : self.vehicle.armed # }) - self.result=[ + self.result = [ str(self.vehicle.version), str(self.vehicle.capabilities.ftp), str(self.vehicle.location.global_frame), - str(self.vehicle.attitude), - str(self.vehicle.velocity), - str(self.vehicle.gps_0), - self.vehicle.groundspeed, - self.vehicle.airspeed, - str(self.vehicle.gimbal), - str(self.vehicle.battery), - self.vehicle.ekf_ok, - self.vehicle.last_heartbeat, - str(self.vehicle.rangefinder.distance), - str(self.vehicle.rangefinder.voltage), - self.vehicle.heading, - self.vehicle.is_armable, - self.vehicle.system_status.state, - self.vehicle.mode.name, - self.vehicle.armed - ] - #self.result = result - return self.result - - def debug(self): - print('Autopilot Firmware version: %s' % self.vehicle.version) - print('Autopilot capabilities (supports ftp): %s' % self.vehicle.capabilities.ftp) - print('Global Location: %s' % self.vehicle.location.global_frame) - print('Global Location (relative altitude): %s' % self.vehicle.location.global_relative_frame) - print('Local Location: %s' % self.vehicle.location.local_frame) - print('Attitude: %s' % self.vehicle.attitude) - print('Velocity: %s' % self.vehicle.velocity) - print('GPS: %s' % self.vehicle.gps_0) - print('Groundspeed: %s' % self.vehicle.groundspeed) - print('Airspeed: %s' % self.vehicle.airspeed) - print('Gimbal status: %s' % self.vehicle.gimbal) - print('Battery: %s' % self.vehicle.battery) - print('EKF OK?: %s' % self.vehicle.ekf_ok) - print('Last Heartbeat: %s' % self.vehicle.last_heartbeat) - print('Rangefinder: %s' % self.vehicle.rangefinder) - print('Rangefinder distance: %s' % self.vehicle.rangefinder.distance) - print('Rangefinder voltage: %s' % self.vehicle.rangefinder.voltage) - print('Heading: %s' % self.vehicle.heading) - print('Is Armable?: %s' % self.vehicle.is_armable) - print('System status: %s' % self.vehicle.system_status.state) - print('Mode: %s' % self.vehicle.mode.name) - print('Armed: %s' % self.vehicle.armed) + str(self.vehicle.attitude), + str(self.vehicle.velocity), + str(self.vehicle.gps_0), + self.vehicle.groundspeed, + self.vehicle.airspeed, + str(self.vehicle.gimbal), + str(self.vehicle.battery), + self.vehicle.ekf_ok, + self.vehicle.last_heartbeat, + str(self.vehicle.rangefinder.distance), + str(self.vehicle.rangefinder.voltage), + self.vehicle.heading, + self.vehicle.is_armable, + self.vehicle.system_status.state, + self.vehicle.mode.name, + self.vehicle.armed + ] + # self.result = result + return self.result + + def debug(self): + print('Autopilot Firmware version: %s' % self.vehicle.version) + print('Autopilot capabilities (supports ftp): %s' % self.vehicle.capabilities.ftp) + print('Global Location: %s' % self.vehicle.location.global_frame) + print('Global Location (relative altitude): %s' % self.vehicle.location.global_relative_frame) + print('Local Location: %s' % self.vehicle.location.local_frame) + print('Attitude: %s' % self.vehicle.attitude) + print('Velocity: %s' % self.vehicle.velocity) + print('GPS: %s' % self.vehicle.gps_0) + print('Groundspeed: %s' % self.vehicle.groundspeed) + print('Airspeed: %s' % self.vehicle.airspeed) + print('Gimbal status: %s' % self.vehicle.gimbal) + print('Battery: %s' % self.vehicle.battery) + print('EKF OK?: %s' % self.vehicle.ekf_ok) + print('Last Heartbeat: %s' % self.vehicle.last_heartbeat) + print('Rangefinder: %s' % self.vehicle.rangefinder) + print('Rangefinder distance: %s' % self.vehicle.rangefinder.distance) + print('Rangefinder voltage: %s' % self.vehicle.rangefinder.voltage) + print('Heading: %s' % self.vehicle.heading) + print('Is Armable?: %s' % self.vehicle.is_armable) + print('System status: %s' % self.vehicle.system_status.state) + print('Mode: %s' % self.vehicle.mode.name) + print('Armed: %s' % self.vehicle.armed) diff --git a/report/report.py b/report/report.py index ecf0e70..09b2390 100644 --- a/report/report.py +++ b/report/report.py @@ -1,62 +1,62 @@ import json -from report.clearbot_attributes import * +from report.attributes import * -class Report: - def __init__(self, yolo, pixhawk): - self.label = Label.Label(yolo) - self.confidence = Confidence.Confidence(yolo) - self.firmware_version = Firmware_version.Firmware_version(pixhawk) - self.vehicle_capabilities = Vehicle_capabilities.Vehicle_capabilities(pixhawk) - self.location = Location.Location(pixhawk) - self.attitude = Attitude.Attitude(pixhawk) - self.velocity = Velocity.Velocity(pixhawk) - self.gps = Gps.Gps(pixhawk) - self.ground_speed = Ground_speed.Ground_speed(pixhawk) - self.air_speed = Air_speed.Air_speed(pixhawk) - self.gimbal_status = Gimbal_status.Gimbal_status(pixhawk) - self.battery_status = Battery_status.Battery_status(pixhawk) - self.ekf_ok = Ekf_ok.Ekf_ok(pixhawk) - self.last_heartbeat = Last_heartbeat.Last_heartbeat(pixhawk) - self.range_finder_distance = Range_finder_distance.Range_finder_distance(pixhawk) - self.range_finder_voltage = Range_finder_voltage.Range_finder_voltage(pixhawk) - self.heading = Heading.Heading(pixhawk) - self.vehicle_is_armable = Vehicle_is_armable.Vehicle_is_armable(pixhawk) - self.system_status = System_status.System_status(pixhawk) - self.vehicle_mode_name = Vehicle_mode_name.Vehicle_mode_name(pixhawk) - self.check_vehicle_armed = Check_vehicle_armed.Check_vehicle_armed(pixhawk) - self.report = {} - def create_report(self): - report = { - "label": self.label.get_label(), - "confidence": self.confidence.get_confidence(), - "firmware_version" : self.firmware_version.get_version(), - "vehicle_capabilities" : self.vehicle_capabilities.get_capabilities(), - "location" :self.location.get_coordinate(), - "attitude" : self.attitude.get_attitude(), - "velocity" : self.velocity.get_velocity(), - "gps" : self.gps.get_gps(), - "ground_speed" : self.ground_speed.get_speed(), - "air_speed" : self.air_speed.get_air_speed(), - "gimbal_status" : self.gimbal_status.get_status(), - "battery_status" : self.battery_status.get_battery(), - "EKF_OK" : self.ekf_ok.get_ekf(), - "last_heartbeat" : self.last_heartbeat.get_last_heartbeat(), - "range_finder_distance" : self.range_finder_distance.get_distance(), - "range_finder_voltage" : self.range_finder_voltage.get_voltage(), - "heading" : self.heading.get_heading(), - "vehicle_is_armable" : self.vehicle_is_armable.get_armable(), - "system_status" : self.system_status.get_system_status(), - "vehicle_mode_name" : self.vehicle_mode_name.get_name(), - "check_vehicle_armed" : self.check_vehicle_armed.get_check() - } - self.report = report +class Report: + def __init__(self, yolo, pixhawk): + self.label = Label(yolo) + self.confidence = Confidence(yolo) + self.firmware_version = FirmwareVersion(pixhawk) + self.vehicle_capabilities = VehicleCapabilities(pixhawk) + self.location = Location(pixhawk) + self.attitude = Altitude(pixhawk) + self.velocity = Velocity(pixhawk) + self.gps = GPS(pixhawk) + self.ground_speed = GroundSpeed(pixhawk) + self.air_speed = AirSpeed(pixhawk) + self.gimbal_status = GimbalStatus(pixhawk) + self.battery_status = BatteryStatus(pixhawk) + self.ekf_ok = EkfOK(pixhawk) + self.last_heartbeat = LastHeartbeat(pixhawk) + self.range_finder_distance = RangeFinderDistance(pixhawk) + self.range_finder_voltage = RangeFinderVoltage(pixhawk) + self.heading = Heading(pixhawk) + self.vehicle_is_armable = VehicleArmable(pixhawk) + self.system_status = SystemStatus(pixhawk) + self.vehicle_mode_name = VehicleModeName(pixhawk) + self.check_vehicle_armed = CheckVehicleArmed(pixhawk) + self.report = {} - def print_report(self): - print(self.report) + def create_report(self): + report = { + "label": self.label.get_label(), + "confidence": self.confidence.get_confidence(), + "firmware_version": self.firmware_version.__version__(), + "vehicle_capabilities": self.vehicle_capabilities.get_capabilities(), + "location": self.location.get_coordinates(), + "attitude": self.attitude.get_altitude(), + "velocity": self.velocity.get_velocity(), + "gps": self.gps.get_gps(), + "ground_speed": self.ground_speed.get_ground_speed(), + "air_speed": self.air_speed.get_air_speed(), + "gimbal_status": self.gimbal_status.get_gimbal_status(), + "battery_status": self.battery_status.get_battery_status(), + "EKF_OK": self.ekf_ok.get_ekf_status(), + "last_heartbeat": self.last_heartbeat.get_last_heartbeat(), + "range_finder_distance": self.range_finder_distance.get_distance(), + "range_finder_voltage": self.range_finder_voltage.get_voltage(), + "heading": self.heading.get_heading(), + "vehicle_is_armable": self.vehicle_is_armable.get_armable(), + "system_status": self.system_status.get_system_status(), + "vehicle_mode_name": self.vehicle_mode_name.get_mode_name(), + "check_vehicle_armed": self.check_vehicle_armed.get_armed_status() + } + self.report = report - def write_report(self, path): - with open(path, 'w') as file_stream: - json.dump(self.report, file_stream, indent=4, sort_keys= True) + def print_report(self): + print(self.report) + def write_report(self, path): + with open(path, 'w') as file_stream: + json.dump(self.report, file_stream, indent=4, sort_keys=True) diff --git a/report/thing_speak.py b/report/thingspeak.py similarity index 68% rename from report/thing_speak.py rename to report/thingspeak.py index c0689b6..1c11b54 100644 --- a/report/thing_speak.py +++ b/report/thingspeak.py @@ -1,30 +1,28 @@ import os import paho.mqtt.publish as publish -from report.clearbot_attributes import * -import time +from report.attributes import Label, Confidence, Location, BatteryStatus, SystemStatus import re -from report import config -topic = "channels/"+ config.CHANNEL_ID +"/publish/"+ config.API_KEY +# topic = "channels/"+ config.CHANNEL_ID +"/publish/"+ config.API_KEY +topic = "channels/publish" mqttHost = "mqtt.thingspeak.com" tTransport = "tcp" tPort = 1883 tTLS = None -class Thing_speak: +class ThingSpeak: + def __init__(self, yolo, pixhawk): + self.label = Label(yolo) + self.confidence = Confidence(yolo) + self.location = Location(pixhawk) + self.battery_status = BatteryStatus(pixhawk) + self.system_status = SystemStatus(pixhawk) - def __init__(self,yolo, pixhawk): - self.label = Label.Label(yolo) - self.confidence = Confidence.Confidence(yolo) - self.location = Location.Location(pixhawk) - self.battery_status = Battery_status.Battery_status(pixhawk) - self.system_status = System_status.System_status(pixhawk) - def show_thingspeak(self): #get gps_location from string variable and stored it in a list - location_string = self.location.get_coordinate() + location_string = self.location.get_coordinates() gps_location = re.findall(r"[-+]?\d*\.\d+|\d+", location_string) label_data = str(self.label.get_label()) From 9a3299bd423b1e120a3acefea4980ae3e679a14e Mon Sep 17 00:00:00 2001 From: utkarsh867 Date: Tue, 14 Jul 2020 10:51:19 +0530 Subject: [PATCH 30/41] Refactoring, Adds string parsing for payload --- main.py | 14 ++++------ pixhawk/__init__.py | 0 {report => pixhawk}/pixhawk.py | 46 --------------------------------- report/attributes.py | 2 +- report/pixhawk.pyc | Bin 4459 -> 0 bytes report/thingspeak.py | 38 +++++++++++++++++---------- 6 files changed, 31 insertions(+), 69 deletions(-) create mode 100644 pixhawk/__init__.py rename {report => pixhawk}/pixhawk.py (63%) delete mode 100644 report/pixhawk.pyc diff --git a/main.py b/main.py index 429ee98..04d0870 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,3 @@ -import time import argparse import logging import multiprocessing @@ -8,10 +7,9 @@ from queue import Queue from detector import detector as dt -from report import report +from report import report, thingspeak from report import reports -from report import pixhawk -from report import thingspeak +from pixhawk import pixhawk report_path = 'report/report_folder/report.json' reports_path = 'report/report_folder/reports.json' @@ -27,13 +25,11 @@ def writeData(): try: yolo_data = q.get() - pixhawk_init = pixhawk.Pixhawk() - pixhawk_data = pixhawk_init.get_data() - logging.debug(pixhawk_data) + pixhawk_instance = pixhawk.Pixhawk() + logging.debug("Created a pixhawk instance") # post to thingspeak.com - logging.debug(f"Sending data to ThingSpeak:\n{yolo_data}\n{pixhawk_data}") - visualize = thingspeak.ThingSpeak(yolo_data, pixhawk_data) + visualize = thingspeak.ThingSpeak(yolo_data, pixhawk_instance) visualize.show_thingspeak() # saved to reports.json diff --git a/pixhawk/__init__.py b/pixhawk/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/report/pixhawk.py b/pixhawk/pixhawk.py similarity index 63% rename from report/pixhawk.py rename to pixhawk/pixhawk.py index a4543c6..bd45227 100644 --- a/report/pixhawk.py +++ b/pixhawk/pixhawk.py @@ -72,52 +72,6 @@ def vehicle_mode_name(self): def check_vehicle_armed(self): return self.vehicle.armed - def get_data(self): - # self.result.append - # "firmware_version" : self.vehicle.version, - # "vehicle_capabilities" : self.vehicle.capabilities.ftp, - # "location" :self.vehicle.location.global_frame, - # "altitude" : self.vehicle.attitude, - # "velocity" : self.vehicle.velocity, - # "gps" : self.vehicle.gps_0, - # "ground_speed" : self.vehicle.groundspeed, - # "air_speed" : self.vehicle.airspeed, - # "gimbal_status" : self.vehicle.gimbal, - # "battery_status" : self.vehicle.battery, - # "EKF_OK" : self.vehicle.ekf_ok, - # "last_heartbeat" : self.vehicle.last_heartbeat, - # "range_finder_distance" : self.vehicle.rangefinder.distance, - # "range_finder_voltage" : self.vehicle.rangefinder.voltage, - # "heading" : self.vehicle.heading, - # "vehicle_is_armable" : self.vehicle.is_armable, - # "system_status" : self.vehicle.system_status.state, - # "vehicle_mode_name" : self.vehicle.mode.name, - # "check_vehicle_armed" : self.vehicle.armed - # }) - self.result = [ - str(self.vehicle.version), - str(self.vehicle.capabilities.ftp), - str(self.vehicle.location.global_frame), - str(self.vehicle.attitude), - str(self.vehicle.velocity), - str(self.vehicle.gps_0), - self.vehicle.groundspeed, - self.vehicle.airspeed, - str(self.vehicle.gimbal), - str(self.vehicle.battery), - self.vehicle.ekf_ok, - self.vehicle.last_heartbeat, - str(self.vehicle.rangefinder.distance), - str(self.vehicle.rangefinder.voltage), - self.vehicle.heading, - self.vehicle.is_armable, - self.vehicle.system_status.state, - self.vehicle.mode.name, - self.vehicle.armed - ] - # self.result = result - return self.result - def debug(self): print('Autopilot Firmware version: %s' % self.vehicle.version) print('Autopilot capabilities (supports ftp): %s' % self.vehicle.capabilities.ftp) diff --git a/report/attributes.py b/report/attributes.py index 16ff98c..b27f756 100644 --- a/report/attributes.py +++ b/report/attributes.py @@ -24,7 +24,7 @@ def get_battery_status(self): class CheckVehicleArmed: def __init__(self, y): - self.y = y[18] + self.y = def get_armed_status(self): return self.y diff --git a/report/pixhawk.pyc b/report/pixhawk.pyc deleted file mode 100644 index 15f50404fe038b6c051c2c0d0ed12b026c81305e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4459 zcmb_fTaOzx6h4#eeY^MVQXxPiuAwS~f{>6v6$`Xm(RPu%iT*-L>GW+$sTdu-1ffBw#~k5B#gwUuA8KYr{`@mt{kpYoIc#9|zh zCei^#L~%f^fZ`gpY82P0Rj1(FWRHR%&^0=^Z{|qX>1jYg63}-hAk7`~WaddPkY41G zT5Ew!jr0=UG7BUZF$!gg^fKvdq*v%?qNhaPx46AZM~yWGVgKY`qt2RJWYI~J#B`in zW&In|x1Gp5O0{u&+L2>-~p*Sp)l|uTD?S{1EW)XZ+;9 zvM>bh*%eF=)6WipQYU5}il-h5lRf8qnDTkAEP{RvF~^HuVP==SvI5pIv|13~Vh^nP zo;7#_L+hm1ys|-h-7A} zQ{Z(&rnoRaof1nb30=TV4zX0&%!+MZ9ro8QV?UeVnMJ%XYZ3n(){|fX`6_bO4Rs}4 z?_9<^H4PX1E6LBpH!|!i>&8{Y!ZY}$re7|LZ=OHw4RZNj72ps~7Xx*Whh=dgCH1m& znCN_9jIIJ5V(cP1Z(Vxxh|<#TRW_>(BR2B|jBI)W@XfLSks5n8<`iB9g}6gZtVvGs zZkWGa78mwRTRCU4O11?euP|32yHyq$7&9kbnVwX^7_8lWa8G{qpjj3W))uMU$v!7z z*EY&k08Aj{-!BUZyE9Ws&vb2~O;!OOpE$iqIkEZSENruH5aM3?*5eL55#nt3}T$wt3(>dYd#Miip9;3fJ2iL&Wz#kaW^xb4-Ay}^ex4*;5v_7o;u~`)Kf~}B1B`JI%iO4Zetn-oc sI2#&&2N%d}0=dM`f3+oeFMKlL{SIc%L3lj~gL*I@tk-YUHiG5aUzwwj-v9sr diff --git a/report/thingspeak.py b/report/thingspeak.py index 1c11b54..3a66b06 100644 --- a/report/thingspeak.py +++ b/report/thingspeak.py @@ -2,7 +2,7 @@ import paho.mqtt.publish as publish from report.attributes import Label, Confidence, Location, BatteryStatus, SystemStatus import re - +import logging # topic = "channels/"+ config.CHANNEL_ID +"/publish/"+ config.API_KEY topic = "channels/publish" @@ -16,12 +16,15 @@ class ThingSpeak: def __init__(self, yolo, pixhawk): self.label = Label(yolo) self.confidence = Confidence(yolo) - self.location = Location(pixhawk) - self.battery_status = BatteryStatus(pixhawk) - self.system_status = SystemStatus(pixhawk) + self.location = pixhawk.do_capture_global_location() + self.battery_status = pixhawk.battery_status() + self.system_status = pixhawk.system_status() + + def create_payload_string(self, payload): + return "&".join(map(lambda x: f"{x[0]}={x[1]}", payload.items())) - def show_thingspeak(self): - #get gps_location from string variable and stored it in a list + def send_to_thingspeak(self): + # get gps_location from string variable and stored it in a list location_string = self.location.get_coordinates() gps_location = re.findall(r"[-+]?\d*\.\d+|\d+", location_string) @@ -29,17 +32,26 @@ def show_thingspeak(self): confidence_data = str(self.confidence.get_confidence()*100) lat = gps_location[0] lon = gps_location[1] - battery_status_data = str(self.battery_status.get_battery()) + battery_status_data = str(self.battery_status.get_battery_status()) system_status_data = str(self.system_status.get_system_status()) - #payload - tPayload = "field1=" + lat + "&field2=" + lon + "&field3=" + confidence_data + "&field4=" + system_status_data + "&field5=" + battery_status_data + "&field6=" + label_data + # payload + payload = { + "field1": lat, + "field2": lon, + "field3": confidence_data, + "field4": system_status_data, + "field5": battery_status_data, + "field6": label_data + } + + payload_string = self.create_payload_string(payload) print("[INFO] Data prepared to be uploaded") try: - #publish the data - publish.single(topic, payload = tPayload, hostname = mqttHost, port = tPort, tls = tTLS, transport = tTransport) + # publish the data + publish.single(topic, payload=payload_string, hostname = mqttHost, port = tPort, tls = tTLS, transport = tTransport) print("[INFO] Data sent successfully") - except: - print("[INFO] Failure in sending data") \ No newline at end of file + except Exception as e: + logging.error(e) From b2e3d0b048bd0c1a4790e0779330f3cfbada318b Mon Sep 17 00:00:00 2001 From: utkarsh867 Date: Tue, 14 Jul 2020 11:27:34 +0530 Subject: [PATCH 31/41] Refactoring Report functionality code --- main.py | 12 +- pixhawk/pixhawk.py | 4 +- report/attributes.py | 166 --- report/report.py | 98 +- report/report_folder/report.json | 23 - report/report_folder/reports.json | 1968 ++++++++++++++--------------- report/reports.py | 31 - report/thingspeak.py | 85 +- 8 files changed, 1083 insertions(+), 1304 deletions(-) delete mode 100644 report/attributes.py delete mode 100644 report/report_folder/report.json delete mode 100644 report/reports.py diff --git a/main.py b/main.py index 04d0870..1562be7 100644 --- a/main.py +++ b/main.py @@ -4,14 +4,12 @@ from serial import serialutil from imutils.video import FPS import cv2 -from queue import Queue +from multiprocessing import Queue from detector import detector as dt from report import report, thingspeak -from report import reports from pixhawk import pixhawk -report_path = 'report/report_folder/report.json' reports_path = 'report/report_folder/reports.json' q = Queue(maxsize=0) @@ -30,14 +28,14 @@ def writeData(): # post to thingspeak.com visualize = thingspeak.ThingSpeak(yolo_data, pixhawk_instance) - visualize.show_thingspeak() + visualize.send_to_thingspeak() # saved to reports.json - get_report = report.Report(yolo_data, pixhawk_data) + get_report = report.Report(yolo_data, pixhawk) get_report.create_report() get_report.print_report() - get_report.write_report(report_path) - reports.combine(reports_path) + get_report.write_report(reports_path) + # We put it to indicate no error return 0 except serialutil.SerialException as e: diff --git a/pixhawk/pixhawk.py b/pixhawk/pixhawk.py index bd45227..e82bb28 100644 --- a/pixhawk/pixhawk.py +++ b/pixhawk/pixhawk.py @@ -21,8 +21,8 @@ def do_capture_global_location(self): def do_capture_relative_global_location(self): return self.vehicle.location.global_relative_frame - def do_capture_altitude(self): - return self.vehicle.altitude + def do_capture_attitude(self): + return self.vehicle.attitude def do_capture_velocity(self): return self.vehicle.velocity diff --git a/report/attributes.py b/report/attributes.py deleted file mode 100644 index b27f756..0000000 --- a/report/attributes.py +++ /dev/null @@ -1,166 +0,0 @@ -class AirSpeed: - def __init__(self, y): - self.y = y[7] - - def get_air_speed(self): - return self.y - - -class Altitude: - def __init__(self, y): - self.y = y[3] - - def get_altitude(self): - return self.y - - -class BatteryStatus: - def __init__(self, y): - self.y = y[9] - - def get_battery_status(self): - return self.y - - -class CheckVehicleArmed: - def __init__(self, y): - self.y = - - def get_armed_status(self): - return self.y - - -class Confidence: - def __init__(self, y): - self.y = y["confidence"] - - def get_confidence(self): - return self.y - - -class EkfOK: - def __init__(self, y): - self.y = y[10] - - def get_ekf_status(self): - return self.y - - -class FirmwareVersion: - def __init__(self, y): - self.y = y[0] - - def __version__(self): - return self.y - - -class GimbalStatus: - def __init__(self, y): - self.y = y[8] - - def get_gimbal_status(self): - return self.y - - -class GPS: - def __init__(self, y): - self.y = y[5] - - def get_gps(self): - return self.y - - -class GroundSpeed: - def __init__(self, y): - self.y = y[6] - - def get_ground_speed(self): - return self.y - - -class Heading: - def __init__(self, y): - self.y = y[14] - - def get_heading(self): - return self.y - - -class Label: - def __init__(self, x): - self.x = x["label"] - - def get_label(self): - return self.x - - -class LastHeartbeat: - def __init__(self, y): - self.y = y[11] - - def get_last_heartbeat(self): - return self.y - - -class Location: - def __init__(self, z): - self.z = z[2] - - def get_coordinates(self): - return self.z - - -class RangeFinderDistance: - def __init__(self, y): - self.y = y[12] - - def get_distance(self): - return self.y - - -class RangeFinderVoltage: - def __init__(self, y): - self.y = y[13] - - def get_voltage(self): - return self.y - - -class SystemStatus: - def __init__(self, y): - self.y = y[16] - - def get_system_status(self): - return self.y - - -class VehicleCapabilities: - def __init__(self, y): - self.y = y[1] - - def get_capabilities(self): - return self.y - - -class VehicleArmable: - def __init__(self, y): - self.y = y[15] - - def get_armable(self): - return self.y - - -class VehicleModeName: - def __init__(self, y): - self.y = y[17] - - def get_mode_name(self): - return self.y - - -class Velocity: - def __init__(self, y): - self.y = y[4] - - def get_velocity(self): - return self.y diff --git a/report/report.py b/report/report.py index 09b2390..59dd3a6 100644 --- a/report/report.py +++ b/report/report.py @@ -1,62 +1,66 @@ import json -from report.attributes import * - class Report: def __init__(self, yolo, pixhawk): - self.label = Label(yolo) - self.confidence = Confidence(yolo) - self.firmware_version = FirmwareVersion(pixhawk) - self.vehicle_capabilities = VehicleCapabilities(pixhawk) - self.location = Location(pixhawk) - self.attitude = Altitude(pixhawk) - self.velocity = Velocity(pixhawk) - self.gps = GPS(pixhawk) - self.ground_speed = GroundSpeed(pixhawk) - self.air_speed = AirSpeed(pixhawk) - self.gimbal_status = GimbalStatus(pixhawk) - self.battery_status = BatteryStatus(pixhawk) - self.ekf_ok = EkfOK(pixhawk) - self.last_heartbeat = LastHeartbeat(pixhawk) - self.range_finder_distance = RangeFinderDistance(pixhawk) - self.range_finder_voltage = RangeFinderVoltage(pixhawk) - self.heading = Heading(pixhawk) - self.vehicle_is_armable = VehicleArmable(pixhawk) - self.system_status = SystemStatus(pixhawk) - self.vehicle_mode_name = VehicleModeName(pixhawk) - self.check_vehicle_armed = CheckVehicleArmed(pixhawk) + self.label = yolo["label"] + self.confidence = yolo["confidence"] + self.firmware_version = pixhawk.firmware_version() + self.vehicle_capabilities = pixhawk.vehicle_capabilities() + self.location = pixhawk.do_capture_global_location() + self.attitude = pixhawk.do_capture_attitude() + self.velocity = pixhawk.do_capture_velocity() + self.gps = pixhawk.do_capture_gps() + self.ground_speed = pixhawk.do_capture_ground_speed() + self.air_speed = pixhawk.do_capture_air_speed() + self.gimbal_status = pixhawk.gimbal_status() + self.battery_status = pixhawk.battery_status() + self.ekf_ok = pixhawk.EKF_OK() + self.last_heartbeat = pixhawk.last_heartbeat() + self.range_finder_distance = pixhawk.range_finder_distance() + self.range_finder_voltage = pixhawk.range_finder_voltage() + self.heading = pixhawk.heading() + self.vehicle_is_armable = pixhawk.vehicle_is_armable() + self.system_status = pixhawk.system_status() + self.vehicle_mode_name = pixhawk.vehicle_mode_name() + self.check_vehicle_armed = pixhawk.check_vehicle_armed() self.report = {} def create_report(self): - report = { - "label": self.label.get_label(), - "confidence": self.confidence.get_confidence(), - "firmware_version": self.firmware_version.__version__(), - "vehicle_capabilities": self.vehicle_capabilities.get_capabilities(), - "location": self.location.get_coordinates(), - "attitude": self.attitude.get_altitude(), - "velocity": self.velocity.get_velocity(), - "gps": self.gps.get_gps(), - "ground_speed": self.ground_speed.get_ground_speed(), - "air_speed": self.air_speed.get_air_speed(), - "gimbal_status": self.gimbal_status.get_gimbal_status(), - "battery_status": self.battery_status.get_battery_status(), - "EKF_OK": self.ekf_ok.get_ekf_status(), - "last_heartbeat": self.last_heartbeat.get_last_heartbeat(), - "range_finder_distance": self.range_finder_distance.get_distance(), - "range_finder_voltage": self.range_finder_voltage.get_voltage(), - "heading": self.heading.get_heading(), - "vehicle_is_armable": self.vehicle_is_armable.get_armable(), - "system_status": self.system_status.get_system_status(), - "vehicle_mode_name": self.vehicle_mode_name.get_mode_name(), - "check_vehicle_armed": self.check_vehicle_armed.get_armed_status() + self.report = { + "label": self.label, + "confidence": self.confidence, + "firmware_version": self.firmware_version, + "vehicle_capabilities": self.vehicle_capabilities, + "location": self.location, + "attitude": self.attitude, + "velocity": self.velocity, + "gps": self.gps, + "ground_speed": self.ground_speed, + "air_speed": self.air_speed, + "gimbal_status": self.gimbal_status, + "battery_status": self.battery_status, + "EKF_OK": self.ekf_ok, + "last_heartbeat": self.last_heartbeat, + "range_finder_distance": self.range_finder_distance, + "range_finder_voltage": self.range_finder_voltage, + "heading": self.heading, + "vehicle_is_armable": self.vehicle_is_armable, + "system_status": self.system_status, + "vehicle_mode_name": self.vehicle_mode_name, + "check_vehicle_armed": self.check_vehicle_armed } - self.report = report def print_report(self): print(self.report) + def read_report_json(self, path): + with open(path, 'r') as f: + data = json.load(f) + return data + def write_report(self, path): + currentJSONDump = self.read_report_json(path) + currentJSONDump.append(self.report) with open(path, 'w') as file_stream: - json.dump(self.report, file_stream, indent=4, sort_keys=True) + json.dump(currentJSONDump, file_stream, indent=2, sort_keys=True) diff --git a/report/report_folder/report.json b/report/report_folder/report.json deleted file mode 100644 index 6bdfc20..0000000 --- a/report/report_folder/report.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=-0.013345734216272831,yaw=2.816819190979004,roll=0.018571699038147926", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.5480275750160217, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 161, - "label": "Paper straw", - "last_heartbeat": 0.014498732999982167, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=0.45", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" -} \ No newline at end of file diff --git a/report/report_folder/reports.json b/report/report_folder/reports.json index 4a6eb53..1719fc6 100644 --- a/report/report_folder/reports.json +++ b/report/report_folder/reports.json @@ -1,985 +1,983 @@ -{ - "Clearbot": [ - { - "confidence": 97, - "label": "litter", - "location": "hello" - }, - { - "confidence": 97, - "label": "litter", - "location": "hello" - }, - { - "confidence": 97, - "label": "litter", - "location": "hello" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.01909925416111946,yaw=2.4231948852539062,roll=-0.4838428497314453", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.5103110074996948, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 138, - "label": "Single-use carrier bag", - "last_heartbeat": 0.528749322999829, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-2.06", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.008913249708712101,yaw=2.566417694091797,roll=-0.4564279317855835", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.944784939289093, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 147, - "label": "Clear plastic bottle", - "last_heartbeat": 0.7555133850000857, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-2.19", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.008600435219705105,yaw=2.637603759765625,roll=-0.468279629945755", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.8287092447280884, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 151, - "label": "Clear plastic bottle", - "last_heartbeat": 0.7411906769993948, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-1.88", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.002421633806079626,yaw=2.63266658782959,roll=-0.33760201930999756", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.7057521343231201, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 150, - "label": "Single-use carrier bag", - "last_heartbeat": 0.45644921800067095, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-1.71", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.0019324326422065496,yaw=2.634483814239502,roll=-0.3371628522872925", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.6058073043823242, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 150, - "label": "Single-use carrier bag", - "last_heartbeat": 0.6393409370002701, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-1.92", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.004327771253883839,yaw=2.628669261932373,roll=-0.3355568051338196", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.6313447952270508, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 150, - "label": "Single-use carrier bag", - "last_heartbeat": 0.12869474000035552, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-2.05", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.004637624602764845,yaw=2.655484676361084,roll=-0.38725385069847107", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.5052488446235657, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 152, - "label": "Plastified paper bag", - "last_heartbeat": 0.8054212500001086, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-2.3", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.004376034252345562,yaw=2.653416395187378,roll=-0.38649651408195496", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.6701147556304932, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 152, - "label": "Plastified paper bag", - "last_heartbeat": 0.9475373960003708, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-1.5", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.0039167385548353195,yaw=2.6539077758789062,roll=-0.38680440187454224", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.8561442494392395, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 152, - "label": "Crisp packet", - "last_heartbeat": 0.689201406000393, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-1.46", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.0024878692347556353,yaw=2.6573050022125244,roll=-0.3856864869594574", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.674862802028656, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 152, - "label": "Tissues", - "last_heartbeat": 0.17121276000034413, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-1.95", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=-0.07103683799505234,yaw=0.7741695046424866,roll=-0.41734689474105835", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.5699434280395508, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 44, - "label": "Paper straw", - "last_heartbeat": 0.21931572999983473, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-0.45", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=-0.069066122174263,yaw=0.7767916917800903,roll=-0.4175513684749603", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.5248982310295105, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 44, - "label": "Glass bottle", - "last_heartbeat": 0.06126848900021287, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-0.22", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=-0.07107638567686081,yaw=0.7734728455543518,roll=-0.4168369174003601", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.7648918628692627, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 44, - "label": "Spread tub", - "last_heartbeat": 0.17502203099957114, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-0.51", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=-0.06390124559402466,yaw=0.7821321487426758,roll=-0.42286205291748047", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.516333818435669, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 44, - "label": "Squeezable tube", - "last_heartbeat": 0.17359416599902033, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-0.36", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=-0.06786604225635529,yaw=0.8050878047943115,roll=-0.4275035560131073", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.5929812788963318, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 46, - "label": "Broken glass", - "last_heartbeat": 0.29605604100106575, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-0.33", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=-0.06688760966062546,yaw=0.8089165091514587,roll=-0.42657241225242615", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.5623620748519897, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 46, - "label": "Egg carton", - "last_heartbeat": 0.1956399999999121, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=0.0", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.011720940470695496,yaw=-2.691927671432495,roll=0.02516011707484722", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.6233267784118652, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 205, - "label": "Plastified paper bag", - "last_heartbeat": 0.4513490780000211, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=3.09", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "HOLD", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.017221353948116302,yaw=-2.6880340576171875,roll=0.02412303164601326", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.8484107851982117, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 205, - "label": "Carded blister pack", - "last_heartbeat": 0.49970943899984377, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=2.59", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.017535418272018433,yaw=-2.682232141494751,roll=0.02506384253501892", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.9025440812110901, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 206, - "label": "Carded blister pack", - "last_heartbeat": 0.9765662840000005, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=2.84", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.013507163152098656,yaw=-2.699464797973633,roll=0.032972127199172974", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.7768799066543579, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 205, - "label": "Tissues", - "last_heartbeat": 0.07120154800009004, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=2.4", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.014546588063240051,yaw=-2.7026543617248535,roll=0.03452213481068611", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.6090551018714905, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 205, - "label": "Plastic bottle cap", - "last_heartbeat": 0.08426600600000711, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=2.67", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.0023166825994849205,yaw=-2.7255067825317383,roll=0.04753636568784714", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.7308673858642578, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 203, - "label": "Plastified paper bag", - "last_heartbeat": 0.9308011690000058, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=2.37", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.001522311009466648,yaw=-2.724100112915039,roll=0.04830246418714523", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.639407217502594, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 203, - "label": "Plastified paper bag", - "last_heartbeat": 0.06578741799989984, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=1.97", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=-0.006178590003401041,yaw=-2.734241485595703,roll=0.05553458258509636", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.545289933681488, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 203, - "label": "Tissues", - "last_heartbeat": 0.9213393700001689, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=2.8", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.09895947575569153,yaw=-2.8563711643218994,roll=-0.03333592042326927", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.6184415221214294, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 196, - "label": "Broken glass", - "last_heartbeat": 0.9445924540000306, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=3.0", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.09880923479795456,yaw=-2.8584089279174805,roll=-0.03788881003856659", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.5609496831893921, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 196, - "label": "Spread tub", - "last_heartbeat": 0.20779678500002774, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=3.25", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.09830862283706665,yaw=-2.857605218887329,roll=-0.03894437104463577", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.5146123766899109, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 196, - "label": "Disposable plastic cup", - "last_heartbeat": 0.39948584700005085, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=3.28", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.08901780843734741,yaw=-2.879223346710205,roll=-0.03568514809012413", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.6122862100601196, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 195, - "label": "Carded blister pack", - "last_heartbeat": 0.9131540979997226, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.38", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.11036232858896255,yaw=3.0507771968841553,roll=0.09607145190238953", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.817825198173523, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 174, - "label": "Spread tub", - "last_heartbeat": 0.6851423230000364, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.18", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.031789928674697876,yaw=-2.52939772605896,roll=0.010927568189799786", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.5057023167610168, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 215, - "label": "Crisp packet", - "last_heartbeat": 0.39529037799999855, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.95", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.030726207420229912,yaw=-2.5291688442230225,roll=0.011235682293772697", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.7137885689735413, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 215, - "label": "Broken glass", - "last_heartbeat": 0.09994538699999111, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.62", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.032340094447135925,yaw=-2.5291972160339355,roll=0.010941646993160248", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.5565459728240967, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 215, - "label": "Crisp packet", - "last_heartbeat": 0.43918579600000385, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.58", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.03162189945578575,yaw=-2.528460741043091,roll=0.010744147002696991", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.6089277863502502, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 215, - "label": "Carded blister pack", - "last_heartbeat": 0.33337623099998837, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=5.06", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.030344994738698006,yaw=-2.531757354736328,roll=0.011866731569170952", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.6337704062461853, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 214, - "label": "Produce bag", - "last_heartbeat": 0.5924038890000247, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.8", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.021685877814888954,yaw=-2.576737642288208,roll=0.03922276198863983", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.510886013507843, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 212, - "label": "Crisp packet", - "last_heartbeat": 0.387161047999939, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.21", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.021333904936909676,yaw=-2.5751540660858154,roll=0.03939945623278618", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.5126315951347351, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 212, - "label": "Drink can", - "last_heartbeat": 0.35668073699991965, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.62", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.022167686372995377,yaw=-2.5750272274017334,roll=0.038983624428510666", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.5082154273986816, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 212, - "label": "Tissues", - "last_heartbeat": 0.2797554009999885, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.43", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.022055204957723618,yaw=-2.5754761695861816,roll=0.03863729164004326", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.6818053722381592, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 212, - "label": "Glass bottle", - "last_heartbeat": 0.5872588710000173, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.33", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.021176500245928764,yaw=-2.576674461364746,roll=0.0393514446914196", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.6461251378059387, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 212, - "label": "Glass bottle", - "last_heartbeat": 0.8723373020000054, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.9", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.02113579772412777,yaw=-2.5758206844329834,roll=0.03883090615272522", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.6111947298049927, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 212, - "label": "Crisp packet", - "last_heartbeat": 0.42284541800017905, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.73", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=0.1569267213344574,yaw=1.739096760749817,roll=0.059471968561410904", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.7094597816467285, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 99, - "label": "Plastic bottle cap", - "last_heartbeat": 0.5886059800000112, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-0.25", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "HOLD", - "velocity": "[0.0, 0.0, 0.0]" - }, - { - "EKF_OK": false, - "air_speed": 0.0, - "attitude": "Attitude:pitch=-0.013345734216272831,yaw=2.816819190979004,roll=0.018571699038147926", - "battery_status": "Battery:voltage=0.0,current=None,level=None", - "check_vehicle_armed": false, - "confidence": 0.5480275750160217, - "firmware_version": "APM:UnknownVehicleType11-4.0.0", - "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", - "gps": "GPSInfo:fix=1,num_sat=0", - "ground_speed": 0.0, - "heading": 161, - "label": "Paper straw", - "last_heartbeat": 0.014498732999982167, - "location": "LocationGlobal:lat=0.0,lon=0.0,alt=0.45", - "range_finder_distance": "None", - "range_finder_voltage": "None", - "system_status": "CRITICAL", - "vehicle_capabilities": "True", - "vehicle_is_armable": false, - "vehicle_mode_name": "MANUAL", - "velocity": "[0.0, 0.0, 0.0]" - } - ] -} \ No newline at end of file +[ + { + "confidence": 97, + "label": "litter", + "location": "hello" + }, + { + "confidence": 97, + "label": "litter", + "location": "hello" + }, + { + "confidence": 97, + "label": "litter", + "location": "hello" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.01909925416111946,yaw=2.4231948852539062,roll=-0.4838428497314453", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5103110074996948, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 138, + "label": "Single-use carrier bag", + "last_heartbeat": 0.528749322999829, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-2.06", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.008913249708712101,yaw=2.566417694091797,roll=-0.4564279317855835", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.944784939289093, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 147, + "label": "Clear plastic bottle", + "last_heartbeat": 0.7555133850000857, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-2.19", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.008600435219705105,yaw=2.637603759765625,roll=-0.468279629945755", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.8287092447280884, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 151, + "label": "Clear plastic bottle", + "last_heartbeat": 0.7411906769993948, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-1.88", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.002421633806079626,yaw=2.63266658782959,roll=-0.33760201930999756", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.7057521343231201, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 150, + "label": "Single-use carrier bag", + "last_heartbeat": 0.45644921800067095, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-1.71", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.0019324326422065496,yaw=2.634483814239502,roll=-0.3371628522872925", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6058073043823242, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 150, + "label": "Single-use carrier bag", + "last_heartbeat": 0.6393409370002701, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-1.92", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.004327771253883839,yaw=2.628669261932373,roll=-0.3355568051338196", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6313447952270508, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 150, + "label": "Single-use carrier bag", + "last_heartbeat": 0.12869474000035552, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-2.05", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.004637624602764845,yaw=2.655484676361084,roll=-0.38725385069847107", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5052488446235657, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 152, + "label": "Plastified paper bag", + "last_heartbeat": 0.8054212500001086, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-2.3", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.004376034252345562,yaw=2.653416395187378,roll=-0.38649651408195496", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6701147556304932, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 152, + "label": "Plastified paper bag", + "last_heartbeat": 0.9475373960003708, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-1.5", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.0039167385548353195,yaw=2.6539077758789062,roll=-0.38680440187454224", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.8561442494392395, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 152, + "label": "Crisp packet", + "last_heartbeat": 0.689201406000393, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-1.46", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.0024878692347556353,yaw=2.6573050022125244,roll=-0.3856864869594574", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.674862802028656, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 152, + "label": "Tissues", + "last_heartbeat": 0.17121276000034413, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-1.95", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=-0.07103683799505234,yaw=0.7741695046424866,roll=-0.41734689474105835", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5699434280395508, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 44, + "label": "Paper straw", + "last_heartbeat": 0.21931572999983473, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-0.45", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=-0.069066122174263,yaw=0.7767916917800903,roll=-0.4175513684749603", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5248982310295105, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 44, + "label": "Glass bottle", + "last_heartbeat": 0.06126848900021287, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-0.22", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=-0.07107638567686081,yaw=0.7734728455543518,roll=-0.4168369174003601", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.7648918628692627, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 44, + "label": "Spread tub", + "last_heartbeat": 0.17502203099957114, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-0.51", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=-0.06390124559402466,yaw=0.7821321487426758,roll=-0.42286205291748047", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.516333818435669, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 44, + "label": "Squeezable tube", + "last_heartbeat": 0.17359416599902033, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-0.36", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=-0.06786604225635529,yaw=0.8050878047943115,roll=-0.4275035560131073", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5929812788963318, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 46, + "label": "Broken glass", + "last_heartbeat": 0.29605604100106575, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-0.33", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=-0.06688760966062546,yaw=0.8089165091514587,roll=-0.42657241225242615", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5623620748519897, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 46, + "label": "Egg carton", + "last_heartbeat": 0.1956399999999121, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=0.0", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.011720940470695496,yaw=-2.691927671432495,roll=0.02516011707484722", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6233267784118652, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 205, + "label": "Plastified paper bag", + "last_heartbeat": 0.4513490780000211, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=3.09", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "HOLD", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.017221353948116302,yaw=-2.6880340576171875,roll=0.02412303164601326", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.8484107851982117, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 205, + "label": "Carded blister pack", + "last_heartbeat": 0.49970943899984377, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=2.59", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.017535418272018433,yaw=-2.682232141494751,roll=0.02506384253501892", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.9025440812110901, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 206, + "label": "Carded blister pack", + "last_heartbeat": 0.9765662840000005, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=2.84", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.013507163152098656,yaw=-2.699464797973633,roll=0.032972127199172974", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.7768799066543579, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 205, + "label": "Tissues", + "last_heartbeat": 0.07120154800009004, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=2.4", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.014546588063240051,yaw=-2.7026543617248535,roll=0.03452213481068611", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6090551018714905, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 205, + "label": "Plastic bottle cap", + "last_heartbeat": 0.08426600600000711, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=2.67", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.0023166825994849205,yaw=-2.7255067825317383,roll=0.04753636568784714", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.7308673858642578, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 203, + "label": "Plastified paper bag", + "last_heartbeat": 0.9308011690000058, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=2.37", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.001522311009466648,yaw=-2.724100112915039,roll=0.04830246418714523", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.639407217502594, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 203, + "label": "Plastified paper bag", + "last_heartbeat": 0.06578741799989984, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=1.97", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=-0.006178590003401041,yaw=-2.734241485595703,roll=0.05553458258509636", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.545289933681488, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 203, + "label": "Tissues", + "last_heartbeat": 0.9213393700001689, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=2.8", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.09895947575569153,yaw=-2.8563711643218994,roll=-0.03333592042326927", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6184415221214294, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 196, + "label": "Broken glass", + "last_heartbeat": 0.9445924540000306, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=3.0", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.09880923479795456,yaw=-2.8584089279174805,roll=-0.03788881003856659", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5609496831893921, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 196, + "label": "Spread tub", + "last_heartbeat": 0.20779678500002774, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=3.25", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.09830862283706665,yaw=-2.857605218887329,roll=-0.03894437104463577", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5146123766899109, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 196, + "label": "Disposable plastic cup", + "last_heartbeat": 0.39948584700005085, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=3.28", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.08901780843734741,yaw=-2.879223346710205,roll=-0.03568514809012413", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6122862100601196, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 195, + "label": "Carded blister pack", + "last_heartbeat": 0.9131540979997226, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.38", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.11036232858896255,yaw=3.0507771968841553,roll=0.09607145190238953", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.817825198173523, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 174, + "label": "Spread tub", + "last_heartbeat": 0.6851423230000364, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.18", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.031789928674697876,yaw=-2.52939772605896,roll=0.010927568189799786", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5057023167610168, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 215, + "label": "Crisp packet", + "last_heartbeat": 0.39529037799999855, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.95", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.030726207420229912,yaw=-2.5291688442230225,roll=0.011235682293772697", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.7137885689735413, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 215, + "label": "Broken glass", + "last_heartbeat": 0.09994538699999111, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.62", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.032340094447135925,yaw=-2.5291972160339355,roll=0.010941646993160248", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5565459728240967, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 215, + "label": "Crisp packet", + "last_heartbeat": 0.43918579600000385, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.58", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.03162189945578575,yaw=-2.528460741043091,roll=0.010744147002696991", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6089277863502502, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 215, + "label": "Carded blister pack", + "last_heartbeat": 0.33337623099998837, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=5.06", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.030344994738698006,yaw=-2.531757354736328,roll=0.011866731569170952", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6337704062461853, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 214, + "label": "Produce bag", + "last_heartbeat": 0.5924038890000247, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.8", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.021685877814888954,yaw=-2.576737642288208,roll=0.03922276198863983", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.510886013507843, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 212, + "label": "Crisp packet", + "last_heartbeat": 0.387161047999939, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.21", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.021333904936909676,yaw=-2.5751540660858154,roll=0.03939945623278618", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5126315951347351, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 212, + "label": "Drink can", + "last_heartbeat": 0.35668073699991965, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.62", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.022167686372995377,yaw=-2.5750272274017334,roll=0.038983624428510666", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5082154273986816, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 212, + "label": "Tissues", + "last_heartbeat": 0.2797554009999885, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.43", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.022055204957723618,yaw=-2.5754761695861816,roll=0.03863729164004326", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6818053722381592, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 212, + "label": "Glass bottle", + "last_heartbeat": 0.5872588710000173, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.33", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.021176500245928764,yaw=-2.576674461364746,roll=0.0393514446914196", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6461251378059387, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 212, + "label": "Glass bottle", + "last_heartbeat": 0.8723373020000054, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.9", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.02113579772412777,yaw=-2.5758206844329834,roll=0.03883090615272522", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.6111947298049927, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 212, + "label": "Crisp packet", + "last_heartbeat": 0.42284541800017905, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=4.73", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=0.1569267213344574,yaw=1.739096760749817,roll=0.059471968561410904", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.7094597816467285, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 99, + "label": "Plastic bottle cap", + "last_heartbeat": 0.5886059800000112, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=-0.25", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "HOLD", + "velocity": "[0.0, 0.0, 0.0]" + }, + { + "EKF_OK": false, + "air_speed": 0.0, + "attitude": "Attitude:pitch=-0.013345734216272831,yaw=2.816819190979004,roll=0.018571699038147926", + "battery_status": "Battery:voltage=0.0,current=None,level=None", + "check_vehicle_armed": false, + "confidence": 0.5480275750160217, + "firmware_version": "APM:UnknownVehicleType11-4.0.0", + "gimbal_status": "Gimbal: pitch=0.0, roll=0.0, yaw=0.0", + "gps": "GPSInfo:fix=1,num_sat=0", + "ground_speed": 0.0, + "heading": 161, + "label": "Paper straw", + "last_heartbeat": 0.014498732999982167, + "location": "LocationGlobal:lat=0.0,lon=0.0,alt=0.45", + "range_finder_distance": "None", + "range_finder_voltage": "None", + "system_status": "CRITICAL", + "vehicle_capabilities": "True", + "vehicle_is_armable": false, + "vehicle_mode_name": "MANUAL", + "velocity": "[0.0, 0.0, 0.0]" + } +] diff --git a/report/reports.py b/report/reports.py deleted file mode 100644 index 1a098f1..0000000 --- a/report/reports.py +++ /dev/null @@ -1,31 +0,0 @@ -from pathlib import Path -import json - -data_folder = Path("report/report_folder/") -file_to_open = data_folder / "report.json" - -class Reports: - - def __init__(self): - self.json_object= {} - self.reports_array= [] - - def combine(self, path): - with open(file_to_open, 'r') as open_file: - self.json_object= json.load(open_file) - - with open(path, 'r') as file_stream: - reports_json = json.load(file_stream) - - if(reports_json.get("Clearbot") != None): - self.reports_array = reports_json["Clearbot"] - self.reports_array.append(self.json_object) - else: - self.reports_array = [self.json_object] - - with open(path, 'w') as write_file: - json.dump({ 'Clearbot': self.reports_array }, write_file, indent=4, sort_keys=True) - - - - \ No newline at end of file diff --git a/report/thingspeak.py b/report/thingspeak.py index 3a66b06..802d765 100644 --- a/report/thingspeak.py +++ b/report/thingspeak.py @@ -1,6 +1,5 @@ import os import paho.mqtt.publish as publish -from report.attributes import Label, Confidence, Location, BatteryStatus, SystemStatus import re import logging @@ -13,45 +12,45 @@ class ThingSpeak: - def __init__(self, yolo, pixhawk): - self.label = Label(yolo) - self.confidence = Confidence(yolo) - self.location = pixhawk.do_capture_global_location() - self.battery_status = pixhawk.battery_status() - self.system_status = pixhawk.system_status() - - def create_payload_string(self, payload): - return "&".join(map(lambda x: f"{x[0]}={x[1]}", payload.items())) - - def send_to_thingspeak(self): - # get gps_location from string variable and stored it in a list - location_string = self.location.get_coordinates() - gps_location = re.findall(r"[-+]?\d*\.\d+|\d+", location_string) - - label_data = str(self.label.get_label()) - confidence_data = str(self.confidence.get_confidence()*100) - lat = gps_location[0] - lon = gps_location[1] - battery_status_data = str(self.battery_status.get_battery_status()) - system_status_data = str(self.system_status.get_system_status()) - - # payload - payload = { - "field1": lat, - "field2": lon, - "field3": confidence_data, - "field4": system_status_data, - "field5": battery_status_data, - "field6": label_data - } - - payload_string = self.create_payload_string(payload) - - print("[INFO] Data prepared to be uploaded") - - try: - # publish the data - publish.single(topic, payload=payload_string, hostname = mqttHost, port = tPort, tls = tTLS, transport = tTransport) - print("[INFO] Data sent successfully") - except Exception as e: - logging.error(e) + def __init__(self, yolo, pixhawk): + self.label = yolo["label"] + self.confidence = yolo["confidence"] + self.location = pixhawk.do_capture_global_location() + self.battery_status = pixhawk.battery_status() + self.system_status = pixhawk.system_status() + + def create_payload_string(self, payload): + return "&".join(map(lambda x: f"{x[0]}={x[1]}", payload.items())) + + def send_to_thingspeak(self): + # get gps_location from string variable and stored it in a list + location_string = self.location.get_coordinates() + gps_location = re.findall(r"[-+]?\d*\.\d+|\d+", location_string) + + label_data = str(self.label.get_label()) + confidence_data = str(self.confidence.get_confidence() * 100) + lat = gps_location[0] + lon = gps_location[1] + battery_status_data = str(self.battery_status.get_battery_status()) + system_status_data = str(self.system_status.get_system_status()) + + # payload + payload = { + "field1": lat, + "field2": lon, + "field3": confidence_data, + "field4": system_status_data, + "field5": battery_status_data, + "field6": label_data + } + + payload_string = self.create_payload_string(payload) + + print("[INFO] Data prepared to be uploaded") + + try: + # publish the data + publish.single(topic, payload=payload_string, hostname=mqttHost, port=tPort, tls=tTLS, transport=tTransport) + print("[INFO] Data sent successfully") + except Exception as e: + logging.error(e) From 2e005f96fed3008f79aa8a195925932de4755d0e Mon Sep 17 00:00:00 2001 From: utkarsh867 Date: Tue, 14 Jul 2020 12:44:26 +0530 Subject: [PATCH 32/41] Fixes a bug with pixhawk instance --- main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 1562be7..89baa7b 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,11 @@ import argparse import logging import multiprocessing +from multiprocessing import Queue from serial import serialutil -from imutils.video import FPS + import cv2 -from multiprocessing import Queue +from imutils.video import FPS from detector import detector as dt from report import report, thingspeak @@ -31,7 +32,7 @@ def writeData(): visualize.send_to_thingspeak() # saved to reports.json - get_report = report.Report(yolo_data, pixhawk) + get_report = report.Report(yolo_data, pixhawk_instance) get_report.create_report() get_report.print_report() get_report.write_report(reports_path) From 400695edbddafa3f92d06b83aa1e122b394d18aa Mon Sep 17 00:00:00 2001 From: fcendra Date: Tue, 14 Jul 2020 16:12:08 +0800 Subject: [PATCH 33/41] Optimized pixhawk somehow --- pixhawk/pixhawk.py | 2 +- testing.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pixhawk/pixhawk.py b/pixhawk/pixhawk.py index e82bb28..67ddf8d 100644 --- a/pixhawk/pixhawk.py +++ b/pixhawk/pixhawk.py @@ -5,7 +5,7 @@ class Pixhawk: vehicle = None def __init__(self, connection_port="/dev/ttyTHS1", baud=57600): - self.vehicle = connect(connection_port, wait_ready=True, baud=baud) + self.vehicle = connect(connection_port, wait_ready=False, baud=baud) self.vehicle.mode = VehicleMode("MANUAL") self.result = [] diff --git a/testing.py b/testing.py index 711148a..c9b84ea 100644 --- a/testing.py +++ b/testing.py @@ -1,13 +1,13 @@ from dronekit import connect, VehicleMode, LocationGlobalRelative - +print("stage 1 done") connection_port="/dev/ttyTHS1" baud=57600 -vehicle = connect(connection_port, wait_ready=True, baud=baud) +vehicle = connect(connection_port, wait_ready=False, baud=baud) vehicle.mode = VehicleMode("MANUAL") - +print("stage 2 done") # print('Autopilot Firmware version: %s' % vehicle.version) # print('Autopilot capabilities (supports ftp): %s' % vehicle.capabilities.ftp) print('Global Location: %s' % vehicle.location.global_frame) From 1caedc41b03a21a12f5ba07461374f52b9457bb5 Mon Sep 17 00:00:00 2001 From: fcendra Date: Wed, 15 Jul 2020 11:55:12 +0800 Subject: [PATCH 34/41] Migrated to environment variables for ThinkSpeak API keys --- report/thingspeak.py | 6 ++++-- testing.py | 44 ++++++++++++++++++++++---------------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/report/thingspeak.py b/report/thingspeak.py index 802d765..5413f02 100644 --- a/report/thingspeak.py +++ b/report/thingspeak.py @@ -3,8 +3,10 @@ import re import logging -# topic = "channels/"+ config.CHANNEL_ID +"/publish/"+ config.API_KEY -topic = "channels/publish" + +channel_ID = os.environ['CHANNEL_ID'] +api_key = os.environ['API_KEY'] +topic = "channels/"+channel_ID+"/publish/"+api_key mqttHost = "mqtt.thingspeak.com" tTransport = "tcp" tPort = 1883 diff --git a/testing.py b/testing.py index c9b84ea..11acb72 100644 --- a/testing.py +++ b/testing.py @@ -4,29 +4,29 @@ connection_port="/dev/ttyTHS1" baud=57600 -vehicle = connect(connection_port, wait_ready=False, baud=baud) +vehicle = connect(connection_port, wait_ready=None, baud=baud) vehicle.mode = VehicleMode("MANUAL") print("stage 2 done") -# print('Autopilot Firmware version: %s' % vehicle.version) -# print('Autopilot capabilities (supports ftp): %s' % vehicle.capabilities.ftp) +print('Autopilot Firmware version: %s' % vehicle.version) +#print('Autopilot capabilities (supports ftp): %s' % vehicle.capabilities.ftp) print('Global Location: %s' % vehicle.location.global_frame) -# print('Global Location (relative altitude): %s' % vehicle.location.global_relative_frame) -# print('Local Location: %s' % vehicle.location.local_frame) -# print('Attitude: %s' % vehicle.attitude) -# print('Velocity: %s' % vehicle.velocity) -# print('GPS: %s' % vehicle.gps_0) -# print('Groundspeed: %s' % vehicle.groundspeed) -# print('Airspeed: %s' % vehicle.airspeed) -# print('Gimbal status: %s' % vehicle.gimbal) -# print('Battery: %s' % vehicle.battery) -# print('EKF OK?: %s' % vehicle.ekf_ok) -# print('Last Heartbeat: %s' % vehicle.last_heartbeat) -# print('Rangefinder: %s' % vehicle.rangefinder) -# print('Rangefinder distance: %s' % vehicle.rangefinder.distance) -# print('Rangefinder voltage: %s' % vehicle.rangefinder.voltage) -# print('Heading: %s' % vehicle.heading) -# print('Is Armable?: %s' % vehicle.is_armable) -# print('System status: %s' % vehicle.system_status.state) -# print('Mode: %s' % vehicle.mode.name) -# print('Armed: %s' % vehicle.armed) +print('Global Location (relative altitude): %s' % vehicle.location.global_relative_frame) +print('Local Location: %s' % vehicle.location.local_frame) +print('Attitude: %s' % vehicle.attitude) +print('Velocity: %s' % vehicle.velocity) +print('GPS: %s' % vehicle.gps_0) +print('Groundspeed: %s' % vehicle.groundspeed) +print('Airspeed: %s' % vehicle.airspeed) +print('Gimbal status: %s' % vehicle.gimbal) +print('Battery: %s' % vehicle.battery) +print('EKF OK?: %s' % vehicle.ekf_ok) +print('Last Heartbeat: %s' % vehicle.last_heartbeat) +print('Rangefinder: %s' % vehicle.rangefinder) +print('Rangefinder distance: %s' % vehicle.rangefinder.distance) +print('Rangefinder voltage: %s' % vehicle.rangefinder.voltage) +print('Heading: %s' % vehicle.heading) +print('Is Armable?: %s' % vehicle.is_armable) +print('System status: %s' % vehicle.system_status.state) +print('Mode: %s' % vehicle.mode.name) +print('Armed: %s' % vehicle.armed) From 1db16f6cf63d9d2ad1560fe5a11d7a20c32b858b Mon Sep 17 00:00:00 2001 From: utkarsh867 Date: Wed, 15 Jul 2020 12:53:57 +0530 Subject: [PATCH 35/41] Removes unused import in pixhawk --- pixhawk/pixhawk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pixhawk/pixhawk.py b/pixhawk/pixhawk.py index 67ddf8d..967e7a4 100644 --- a/pixhawk/pixhawk.py +++ b/pixhawk/pixhawk.py @@ -1,4 +1,4 @@ -from dronekit import connect, VehicleMode, LocationGlobalRelative +from dronekit import connect, VehicleMode class Pixhawk: From 661e0e4279338a83a5311b4e9a55644b1376b943 Mon Sep 17 00:00:00 2001 From: utkarsh867 Date: Wed, 15 Jul 2020 13:10:07 +0530 Subject: [PATCH 36/41] Adds exception handling code for vehicle connection --- main.py | 42 ++++++++++++++++++------------------------ pixhawk/pixhawk.py | 10 +++++++--- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/main.py b/main.py index 89baa7b..368d960 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,6 @@ import logging import multiprocessing from multiprocessing import Queue -from serial import serialutil import cv2 from imutils.video import FPS @@ -16,35 +15,30 @@ def writeData(): + logging.info("Starting connection to Pixhawk") + try: + pixhawk_instance = pixhawk.Pixhawk() + logging.info("Connected to Pixhawk") + except Exception as e: + return -1 + while True: while True: if (q.empty == False): logging.debug("Message queue is empty") break - try: - yolo_data = q.get() - pixhawk_instance = pixhawk.Pixhawk() - logging.debug("Created a pixhawk instance") - - # post to thingspeak.com - visualize = thingspeak.ThingSpeak(yolo_data, pixhawk_instance) - visualize.send_to_thingspeak() - - # saved to reports.json - get_report = report.Report(yolo_data, pixhawk_instance) - get_report.create_report() - get_report.print_report() - get_report.write_report(reports_path) - # We put it to indicate no error - return 0 - - except serialutil.SerialException as e: - # @utkarsh867: 9th July, 2020 - # I added this exception handler so that the code does not crash when it does not find a serial connection - # to the Pixhawk - logging.error(e) - return -1 + yolo_data = q.get() + + # post to thingspeak.com + visualize = thingspeak.ThingSpeak(yolo_data, pixhawk_instance) + visualize.send_to_thingspeak() + + # saved to reports.json + get_report = report.Report(yolo_data, pixhawk_instance) + get_report.create_report() + get_report.print_report() + get_report.write_report(reports_path) def main(params): diff --git a/pixhawk/pixhawk.py b/pixhawk/pixhawk.py index 967e7a4..bc86a53 100644 --- a/pixhawk/pixhawk.py +++ b/pixhawk/pixhawk.py @@ -1,13 +1,17 @@ from dronekit import connect, VehicleMode +import logging +from serial import serialutil class Pixhawk: vehicle = None def __init__(self, connection_port="/dev/ttyTHS1", baud=57600): - self.vehicle = connect(connection_port, wait_ready=False, baud=baud) - self.vehicle.mode = VehicleMode("MANUAL") - self.result = [] + try: + self.vehicle = connect(connection_port, wait_ready=True, baud=baud) + self.vehicle.mode = VehicleMode("MANUAL") + except serialutil.SerialException as e: + logging.error(e) def firmware_version(self): return self.vehicle.version From f2bc14d0d323c969abd5c7c1f6a593b2a7bec856 Mon Sep 17 00:00:00 2001 From: utkarsh867 Date: Wed, 15 Jul 2020 13:31:50 +0530 Subject: [PATCH 37/41] Adds heading for Pixhawk documentation --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 6efba54..93ddf69 100644 --- a/README.md +++ b/README.md @@ -70,3 +70,6 @@ cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D OPENCV_ENABLE_NONFREE=ON \ -D OPENCV_EXTRA_MODULES_PATH=/home/`whoami`/opencv_contrib/modules .. ``` + + +### Setup on the Jetson Nano board for Pixhawk From 9ffb8878ba8395c31bc15ead254391a9d28bafd4 Mon Sep 17 00:00:00 2001 From: utkarsh867 Date: Wed, 15 Jul 2020 19:01:07 +0530 Subject: [PATCH 38/41] Updates the tiny-YOLO model after mid-training --- detector/model/clearbot-tiny.cfg | 70 ++++++++++++++++++++---- detector/model/clearbot-tiny.weights | 4 +- detector/model/clearbot_26_06_20.weights | 3 - 3 files changed, 62 insertions(+), 15 deletions(-) mode change 100644 => 100755 detector/model/clearbot-tiny.weights delete mode 100755 detector/model/clearbot_26_06_20.weights diff --git a/detector/model/clearbot-tiny.cfg b/detector/model/clearbot-tiny.cfg index 5a6b22b..d352bf6 100644 --- a/detector/model/clearbot-tiny.cfg +++ b/detector/model/clearbot-tiny.cfg @@ -1,12 +1,12 @@ [net] # Testing -# batch=1 -# subdivisions=1 +#batch=1 +#subdivisions=1 # Training batch=64 subdivisions=16 -width=416 -height=416 +width=608 +height=608 channels=3 momentum=0.9 decay=0.0005 @@ -215,10 +215,10 @@ activation=linear [yolo] -mask = 3,4,5 -anchors = 9, 7, 30, 25, 61, 51, 95, 95, 191,120, 234,242 +mask = 6,7,8 +anchors = 11, 9, 32, 22, 48, 48, 107, 54, 63,105, 153,108, 159,239, 310,173, 368,362 classes=64 -num=6 +num=9 jitter=.3 scale_x_y = 1.05 cls_normalizer=1.0 @@ -264,10 +264,60 @@ filters=207 activation=linear [yolo] -mask = 1,2,3 -anchors = 9, 7, 30, 25, 61, 51, 95, 95, 191,120, 234,242 +mask = 3,4,5 +anchors = 11, 9, 32, 22, 48, 48, 107, 54, 63,105, 153,108, 159,239, 310,173, 368,362 +classes=64 +num=9 +jitter=.3 +scale_x_y = 1.05 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +ignore_thresh = .7 +truth_thresh = 1 +random=0 +resize=1.5 +nms_kind=greedynms +beta_nms=0.6 + + +[route] +layers = -3 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[upsample] +stride=2 + +[route] +layers = -1, 15 + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=207 +activation=linear + +[yolo] +mask = 0,1,2 +anchors = 11, 9, 32, 22, 48, 48, 107, 54, 63,105, 153,108, 159,239, 310,173, 368,362 classes=64 -num=6 +num=9 jitter=.3 scale_x_y = 1.05 cls_normalizer=1.0 diff --git a/detector/model/clearbot-tiny.weights b/detector/model/clearbot-tiny.weights old mode 100644 new mode 100755 index ff99f98..f627b9f --- a/detector/model/clearbot-tiny.weights +++ b/detector/model/clearbot-tiny.weights @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:eb0d0dfce42caaa9e6a171adcd2ffc2a26139276fc32416a5ac5ac30d522662f -size 43914873 +oid sha256:af301cbdbd919cd4e84839fdc49ab049d8a239cc08339f83e3277fdc59e790e6 +size 25163592 diff --git a/detector/model/clearbot_26_06_20.weights b/detector/model/clearbot_26_06_20.weights deleted file mode 100755 index d9f6c7f..0000000 --- a/detector/model/clearbot_26_06_20.weights +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:d32f01f148ed1c663150721dd4833319cd87c38536c9c3cda57dee50a5bbf592 -size 257373000 From 9101eb2576d792d036dfb91b12faa9a05e324f6d Mon Sep 17 00:00:00 2001 From: utkarsh867 Date: Wed, 15 Jul 2020 23:37:42 +0530 Subject: [PATCH 39/41] refactors pixhawk instance as pixhawk --- main.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 368d960..c6ce829 100644 --- a/main.py +++ b/main.py @@ -8,7 +8,7 @@ from detector import detector as dt from report import report, thingspeak -from pixhawk import pixhawk +from pixhawk import pixhawk as px reports_path = 'report/report_folder/reports.json' q = Queue(maxsize=0) @@ -17,7 +17,7 @@ def writeData(): logging.info("Starting connection to Pixhawk") try: - pixhawk_instance = pixhawk.Pixhawk() + pixhawk = px.Pixhawk() logging.info("Connected to Pixhawk") except Exception as e: return -1 @@ -31,11 +31,11 @@ def writeData(): yolo_data = q.get() # post to thingspeak.com - visualize = thingspeak.ThingSpeak(yolo_data, pixhawk_instance) + visualize = thingspeak.ThingSpeak(yolo_data, pixhawk) visualize.send_to_thingspeak() # saved to reports.json - get_report = report.Report(yolo_data, pixhawk_instance) + get_report = report.Report(yolo_data, pixhawk) get_report.create_report() get_report.print_report() get_report.write_report(reports_path) @@ -46,7 +46,7 @@ def main(params): logging.info("accessing video stream...") vs = cv2.VideoCapture(0) - detector = dt.Detector("model", use_gpu=True) + detector = dt.Detector("model", use_gpu=True, weights_file="clearbot-tiny.weights", config_file="clearbot-tiny.cfg", confidence_thres=0.1) fps = FPS().start() while True: From 3cb53746a9303ede415dea5789d83841f5e02561 Mon Sep 17 00:00:00 2001 From: Fernando Julio Cendra Date: Thu, 16 Jul 2020 01:05:55 +0800 Subject: [PATCH 40/41] updated README for setup on the Jetson Nano board for pixhawk --- README.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 93ddf69..a564c9e 100644 --- a/README.md +++ b/README.md @@ -72,4 +72,29 @@ cmake -D CMAKE_BUILD_TYPE=RELEASE \ ``` -### Setup on the Jetson Nano board for Pixhawk +#### Setup on the Jetson Nano board for Pixhawk + +we are using [DroneKit-Python API](https://dronekit-python.readthedocs.io/en/latest/about/overview.html) as an Onboard app between Jetson Nano and Pixhawk. + +Make sure your linux userid has the permission to use your tty port device + +connection port = `dev/ttyTHS1` + +Assume our userid is `user` +```bash +sudo usermod -a -G dialout user +``` + +In `pixhawk.py` script, this is the line code to establish Dronekit connectivity to the connected device. We must set [wait_ready=True](https://dronekit-python.readthedocs.io/en/latest/guide/connecting_vehicle.html) to waits until some vehicle parameters and attributes are populated. + +```python +def __init__(self, connection_port="/dev/ttyTHS1", baud=57600): + try: + self.vehicle = connect(connection_port, wait_ready=True, baud=baud) + self.vehicle.mode = VehicleMode("MANUAL") + except serialutil.SerialException as e: + logging.error(e) +```` + + +You can check the Dronekit attributes listed [here](https://dronekit-python.readthedocs.io/en/latest/guide/vehicle_state_and_parameters.html) From aabdffa9e3f257b56e779d7d5e3f93ff15d87285 Mon Sep 17 00:00:00 2001 From: Fernando Julio Cendra Date: Thu, 16 Jul 2020 11:43:12 +0800 Subject: [PATCH 41/41] Added Dronekit Pixhawk Connection in README --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a564c9e..bc7ae6d 100644 --- a/README.md +++ b/README.md @@ -84,8 +84,15 @@ Assume our userid is `user` ```bash sudo usermod -a -G dialout user ``` +let's try running `testing.py` to get a brief introduction with `Dronekit` ( in `botmlcode/` directory ) -In `pixhawk.py` script, this is the line code to establish Dronekit connectivity to the connected device. We must set [wait_ready=True](https://dronekit-python.readthedocs.io/en/latest/guide/connecting_vehicle.html) to waits until some vehicle parameters and attributes are populated. +```bash +python testing.py +``` +we are aware that we need to wait for around `10 seconds` or more to get the above's print statement be executed. At first, we though this was an issue( listed below ) +* Note ( 14th July, 2020): Optimise Pixhawk integration to the Jetson #5 [Track the issue here](https://github.com/clearbothk/botmlcode/issues/5) + +In `pixhawk.py` script, below is the line code to establish Dronekit connectivity to the connected device. it is recommended to set [wait_ready=True](https://dronekit-python.readthedocs.io/en/latest/guide/connecting_vehicle.html) to waits until some vehicle parameters and attributes are populated so that it is initialized successfully. ```python def __init__(self, connection_port="/dev/ttyTHS1", baud=57600): @@ -95,6 +102,8 @@ def __init__(self, connection_port="/dev/ttyTHS1", baud=57600): except serialutil.SerialException as e: logging.error(e) ```` +Thus we need to first initialize the `dronekit.connect()` and make it as a constructor rather than repeatedly run the scripts so that we do not need to re run the script for everytime the [Dronekit attributes functions](https://dronekit-python.readthedocs.io/en/latest/guide/vehicle_state_and_parameters.html) + get called. + -You can check the Dronekit attributes listed [here](https://dronekit-python.readthedocs.io/en/latest/guide/vehicle_state_and_parameters.html)