Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # import library yang dibutuhkan
- from picamera.array import PiRGBArray
- from picamera import PiCamera
- from signal import pause
- from subprocess import check_call
- from datetime import date, timedelta
- import time
- import cv2
- import sys
- import RPi.GPIO as GPIO
- import numpy as np
- import astral
- import datetime
- import os
- import math
- # membuat variabel variabel penting
- global cerah, luas, minimum, cerahi, luasi
- lock_x = False
- lock_y = True
- lockknn = False
- lockkri = False
- invkri = True
- invknn = True
- jamlog = float(time.strftime("%H.%M"))
- rad2 = 7
- rad3 = 7
- hitungcari = 0
- ctxskg = int(160)
- start_time = time.time()
- wait = time.time()
- waitx = time.time()
- wait3 = time.time()
- waitclean = time.time()
- scanning = False
- step1 = True
- step2 = False
- step2b = False
- step2c = False
- step3 = False
- font = cv2.FONT_HERSHEY_SIMPLEX
- bottomLeftCornerOfText = (5,235)
- atasnya = (5,220)
- atasnyalagi = (5,205)
- polatas = (5,20)
- fontScale = 0.4
- fontColor = (255,175,220)
- lineType = 1
- teksstring2 = str("bootup")
- centre_x = 160
- centre_y = 120
- ignore = False
- cerahinv = False
- #memulai kamera
- camera = PiCamera()
- camera.resolution = (320, 240)
- camera.iso = 0
- camera.exposure_mode = 'auto'
- camera.framerate = 60
- rawCapture = PiRGBArray(camera, size=(320, 240))
- time.sleep(0.1) #'pemanasan' kamera
- #set lokasi ke semarang & perhitungan matahari
- semarang = astral.Location(
- info=("Semarang",
- "Indonesia",
- -6.966667, 110.416664,
- "Asia/Jakarta",
- 40)
- )
- semarang.solar_depression = "civil"
- matahari = semarang.sun()
- #menggunakan BCM sebagai referensi GPIO
- GPIO.setmode(GPIO.BCM)
- #mengatur GPIO untuk keluaran
- Mot1F =24
- Mot1R =25
- Mot2F =23
- Mot2R =18
- kipas =27
- GPIO.setup(Mot1F, GPIO.OUT)
- GPIO.setup(Mot1R, GPIO.OUT)
- GPIO.setup(Mot2F, GPIO.OUT)
- GPIO.setup(Mot2R, GPIO.OUT)
- GPIO.setup(kipas, GPIO.OUT)
- #mengatur GPIO masukan
- GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- GPIO.setup(7, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- GPIO.setup(8, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- #membuat fungsi-fungsi yang diperlukan
- #fungsi motor dengan pwm software menggunakan frekuensi 60Hz
- def motor1forward(dur, cycle):
- print("forwarding motor 1")
- pm1f = GPIO.PWM(Mot1F, 60)
- pm1f.start(cycle)
- time.sleep(dur)
- pm1f.stop
- del dur, cycle, pm1f
- def motor1reverse(dur, cycle):
- print("backwarding motor 1")
- pm1r = GPIO.PWM(Mot1R, 60)
- pm1r.start(cycle)
- time.sleep(dur)
- pm1r.stop
- del dur, cycle, pm1r
- def motorsafe(): # fungsi untuk mengamankan motor
- GPIO.output(Mot1F, GPIO.LOW)
- time.sleep(0.001)
- GPIO.output(Mot1R, GPIO.LOW)
- time.sleep(0.001)
- GPIO.output(Mot2F, GPIO.LOW)
- time.sleep(0.001)
- GPIO.output(Mot2R, GPIO.LOW)
- time.sleep(0.001)
- def CPUtemp(): #membaca suhu CPU
- res = os.popen('vcgencmd measure_temp').readline()
- return(res.replace("temp=","").replace("'C\n",""))
- #mengambil gambar dari kamera ke vairabel 'frame' dalam bentuk array
- for frame in camera.capture_continuous(rawCapture,
- format="bgr",
- use_video_port=False):
- #inisialisasi limit switch
- Lim1 =GPIO.input(16) #bawah
- Lim2 =GPIO.input(12) #atas
- Lim3 =GPIO.input(8) #kiri
- Lim4 =GPIO.input(7) #kanan
- tomboloff =GPIO.input(17)
- if tomboloff == False:
- mulaipencet = time.time()
- time.sleep(0.05)
- lps = None
- lps = GPIO.wait_for_edge(17, GPIO.RISING)
- if lps is not None:
- time.sleep(0.01)
- global waktupencet
- waktupencet = time.time() - mulaipencet
- if waktupencet > 9 :
- GPIO.output(kipas, GPIO.LOW)
- cv2.destroyAllWindows()
- for i in range (1,5):
- cv2.waitKey(1)
- del camera
- check_call(['/sbin/poweroff'])
- if 10 > waktupencet > 4 :
- GPIO.output(kipas, GPIO.LOW)
- cv2.destroyAllWindows()
- for i in range (1,5):
- cv2.waitKey(1)
- del camera
- check_call(['/sbin/reboot'])
- if 5 > waktupencet > 1 :
- print("memulai pemicu runtutan pemindaian")
- teksstring2 = str("memulai runtutan pemindaian")
- scanning = True
- mulaiscan = True
- rise = str( matahari['sunrise'].time())
- noon = str( matahari['noon'].time())
- sunset = str( matahari['sunset'].time())
- #memuat waktu terbit, siang & tenggelam matahari dalam variabel
- jmtbt, mntbt, dttbt = rise.split(':')
- jmsiang, mnsiang, dtsiang = noon.split(':')
- jmtgm, mntgm, dttgm = sunset.split(':')
- terbit = float(jmtbt + "." + mntbt)
- siang = float(jmsiang+"."+mnsiang)
- tenggelam = float( jmtgm + "." + mntgm)
- jamskrg = float(time.strftime("%H.%M"))
- suhu = float(CPUtemp())
- puncakonmin = ((int(jmsiang) * 60) + int(mnsiang))
- mulailock = puncakonmin - 15
- selesailock = puncakonmin + 15
- jamonminute = ((int(time.strftime("%H")) * 60) + int(time.strftime("%M")))
- print(mulailock, puncakonmin, selesailock, jamonminute)
- #menyalakan dan mematikan kipas
- if suhu > 60:
- GPIO.output(kipas, GPIO.HIGH)
- if suhu < 45:
- GPIO.output(kipas, GPIO.LOW)
- #mengubah tangkapan gambar jadi grayscale dan mencari titik paling terang
- gray = cv2.cvtColor(frame.array, cv2.COLOR_BGR2GRAY)
- gray = cv2.GaussianBlur(gray, (rad3,rad3), 0)
- (minVal, maxVal, minLoc, maxLoc)=cv2.minMaxLoc(gray)
- image = frame.array
- teksstring1 = str("min:"+str(minVal)+
- " |max:"+str(maxVal)+
- " |%.2f" %jamskrg+
- " |"+"%.1f" %suhu+"'C"+
- " |R:"+str(rad2)+"/"+str(rad3))
- teksstring3 = str(str(maxLoc))
- teksstring4 = str("terbit:"+"%.2f" %terbit+
- " | puncak:"+"%.2f" %siang+
- " | tenggelam:"+"%.2f" %tenggelam)
- #menandai titik paling terang
- cv2.circle(image, maxLoc, rad2, (0, 250, 150), 1)
- cv2.circle(image, maxLoc, 3, (50, 200, 50), 1)
- #menambahkan teks informasi
- cv2.putText(image,teksstring1, bottomLeftCornerOfText,
- font, fontScale, fontColor, lineType)
- cv2.putText(image,teksstring2, atasnya,
- font, fontScale, fontColor, lineType)
- cv2.putText(image,teksstring3, atasnyalagi,
- font, fontScale, fontColor, lineType)
- cv2.putText(image,teksstring4, polatas,
- font, fontScale, fontColor, lineType)
- #menampilkan tangkapan kamera
- cv2.imshow("Bismillah", image)
- #auto radius, menyesuaikan deviasi gaussian blur & radius deteksi
- retval, thresholded = cv2.threshold(gray, ((80/100)*maxVal),
- maxVal, cv2.THRESH_BINARY)
- im2, contours, hierarchy = cv2.findContours(thresholded,
- cv2.RETR_LIST,
- cv2.CHAIN_APPROX_SIMPLE)
- for idx, contour in enumerate(contours):
- global area
- area = cv2.contourArea(contour)
- if maxVal < 10 :
- rad2 = 5
- if ((time.time()-start_time)>1) and (maxVal != 0):
- start_time =time.time()
- rad1 =math.sqrt(area/(math.pi))
- rad2 =int(round((125/100)*rad1))
- if rad2 < 7 :
- rad2 = 7
- if rad2 %2 == 0:
- rad3 = rad2 -1
- if rad2 %2 != 0:
- rad3 = rad2
- # mencegah false detection karena nois
- if rad3 < 71:
- minimum = 33
- if rad3 > 70:
- minimum = 5
- pa = int(round(120-(5)))
- pb = int(round(120+(5)))
- #menampilkan informasi
- print ("lok:", maxLoc, "| min:", int(minVal), "| max:", int(maxVal), "| waktu sekarang:", "%.2f" %jamskrg, "| suhu:", "%.2f" %suhu, "°C")
- print ("terbit:", "%.2f" %terbit, "| puncak:", "%.2f" %siang, "| tenggelam:", "%.2f" %tenggelam, "| radius :", rad2, "/", rad3)
- centre_x1, centre_y1 = (int(x) for x in maxLoc)
- centre_x = int(round((centre_x + centre_x1)/2))
- centre_y = int(round((centre_y + centre_y1)/2))
- if (pa<centre_y<pb) & (155<centre_x<165):
- teksstring2 = str("sudah tengah")
- if maxVal<minimum :
- teksstring2 = str("intensitas tidak cukup")
- if ((jamskrg)<(6.0)):
- tglskrg = str(time.strftime("%Y-%m-%d"))
- namalog = str("log"+tglskrg+"log1")
- if ((5.59)<(jamskrg)<(12)):
- tglskrg = str(time.strftime("%Y-%m-%d"))
- namalog = str("log"+tglskrg+"log2")
- if ((11.59)<(jamskrg)<(18)):
- tglskrg = str(time.strftime("%Y-%m-%d"))
- namalog = str("log"+tglskrg+"log3")
- if ((17.59)<(jamskrg)<(24)):
- tglskrg = str(time.strftime("%Y-%m-%d"))
- namalog = str("log"+tglskrg+"log4")
- if jamlog != jamskrg:
- jamlog = jamskrg
- teks1 = str("lok:"+str(maxLoc)+" | min:"+str(minVal)+" | max:"+str(maxVal)+" | waktu sekarang:"+"%.2f" %jamskrg+"| suhu:"+"%.2f" %suhu+ "°C")
- teks2 = str("terbit:"+"%.2f" %terbit+" | puncak:"+"%.2f" %siang+" | tenggelam:"+"%.2f" %tenggelam)
- if (pa<centre_y<pb) & (155<centre_x<165):
- teks1 = str("lok:"+str(maxLoc)+" sudah tengah | min:"+str(minVal)+" | max:"+str(maxVal)+" | waktu sekarang:"+"%.2f" %jamskrg+"| suhu:"+"%.2f" %suhu+"°C")
- if maxVal<minimum :
- teks1 = str("intensitas tidak cukup | min:"+str(minVal)+" | max:"+str(maxVal)+" | waktu sekarang:"+"%.2f" %jamskrg+"| suhu:"+"%.2f" %suhu+"°C")
- if (jamskrg<(terbit + 1.3)) or (jamskrg>(tenggelam-0.30)) :
- teks1 = str("sudah malam, kembali ke timur. sekarang jam"+"%.2f" %jamskrg+"| suhu:"+"%.2f" %suhu+"°C")
- if (invknn == True):
- if (invkri == True):
- teks3 = str("kanan invers, kiri invers")
- if (invkri == False):
- teks3 = str("kanan invers, kiri biasa")
- if (invknn == False):
- if (invkri == True):
- teks3 = str("kanan biasa, kiri invers")
- if (invkri == False):
- teks3 = str("kanan biasa, kiri biasa")
- logging = open(namalog+".txt", 'a')
- logging.write(teks1+"||"+teks2+"||"+teks3+"\n")
- logging.write("---------------------------------\n")
- logging.close()
- del namalog
- del tglskrg
- print("log diperbarui")
- if scanning == True:
- teksstring2 = str("scanning")
- if mulaiscan == True:
- motorsafe()
- #kembali ke nol
- if step1 == True:
- mulaiscan = False
- print("memulai runtutan scanning")
- teksstring2 = str("scanning - 1.kembali ke 0")
- if (Lim4 == True):
- print("step 1.a - kembali ke nol azimut")
- motor1forward(.250, 40)
- if (Lim4 == False):
- if (Lim2 == True):
- print("step 1.b - kembali ke nol zenit")
- GPIO.output(Mot2F, GPIO.HIGH)
- time.sleep(.025)
- if (Lim2 == False):
- print("step 1 finish")
- GPIO.output(Mot2F, GPIO.LOW)
- teksstring2 = str("scanning - 1. selesai")
- step1 = False
- step2 = True
- cerah = 0
- luas = 0
- cerahi = 0
- luasi = 0
- if step2 == True:
- print("memulai mencari")
- teksstring2 = str("scanning - 2. mencari")
- if maxVal > cerah:
- cerah = maxVal
- luas = area
- print("ditemukan titik lebih cerah,", cerah)
- teksstring2 = str("scanning - 2. lebih cerah, "+str(cerah))
- if cerah == maxVal:
- if luas < area:
- luas = area
- print("ditemukan titik area luas,", luas)
- teksstring2 = str("scanning - 2. lebih luas, "+str(luas))
- if (Lim3 == True):
- print("step 2 memulai pemindaian")
- motor1reverse(.250, 40)
- if (Lim3 == False):
- print("step 2 selesai")
- step2 = False
- step2b = True
- if step2b == True:
- if (Lim1 == True):
- print("step 2.b - scan reverse")
- teksstring2 = str("scanning - 2. mencari")
- GPIO.output(Mot2R, GPIO.HIGH)
- time.sleep(.025)
- if (Lim1 == False):
- print("step 2.b finish")
- GPIO.output(Mot2R, GPIO.LOW)
- teksstring2 = str("scanning - 1. selesai")
- step2b = False
- step2c = True
- if step2c == True:
- if maxVal > cerahi:
- cerahi = maxVal
- luasi = area
- print("ditemukan titik lebih cerah,", cerah)
- teksstring2 = str("scanning - 2. lebih cerah, "+str(cerah))
- if cerahi == maxVal:
- if luasi < area:
- luasi = area
- print("ditemukan titik area luas,", luas)
- teksstring2 = str("scanning - 2. lebih luas, "+str(luas))
- if (Lim4 == True):
- print("step 2 memulai pemindaian")
- motor1forward(.250, 40)
- if (Lim4 == False):
- print("step 2 selesai")
- hasilscan = cerah * luas
- hasilscaninv = cerahi * luasi
- if hasilscan > hasilscaninv or hasilscan == hasilscaninv:
- scaninv = False
- if cerah > (minimum -1):
- step2c = False
- step3 = True
- if cerah < minimum:
- print("tidak ada cahaya ditemukan atau cahaya kurang dari minimum")
- teksstring2 = str("scanning - gagal, cahaya kurang dari minimum")
- step2c = False
- scanning = False
- step3 = False
- step1 = True
- lock_x = False
- lock_y = True
- if cerahi > (minimun -1):
- step2c = False
- step3 = True
- scaninv = True
- if hasilscaninv > hasilscan :
- scaninv = True
- if cerahi > (minimum -1):
- step2c = False
- step3 = True
- if cerahi < minimum:
- print("tidak ada cahaya ditemukan atau cahaya kurang dari minimum")
- teksstring2 = str("scanning - gagal, cahaya kurang dari minimum")
- step2c = False
- scanning = False
- step3 = False
- step1 = True
- lock_x = False
- lock_y = True
- if cerah > (minimum -1):
- step2c = False
- step3 = True
- scaninv = False
- if step3 == True:
- if cerahinv == True :
- print("menuju ke titik paling terang,")
- teksstring2 = str("scanning - 3. menuju titik terang")
- areabawah = luasi*(77/100)
- cerahbawah = cerahi*(77/100)
- if (Lim3 == True):
- motor1reverse(.125, 40)
- if (Lim3 == False):
- print("pemindaian gagal, memindai ulang")
- teksstring2 = str("scanning - 3. gagal, mengulangi dari awal")
- scanning = True
- step3 = False
- step1 = True
- lock_x = False
- lock_y = True
- if maxVal > cerahbawah:
- if area > areabawah:
- print("pemindaian selesai")
- teksstring2 = str("scanning - selesai")
- scanning = False
- step3 = False
- step1 = True
- lock_x = False
- lock_y = True
- if cerahinv == False :
- print("menuju ke titik paling terang,")
- if (Lim2 == True):
- print("step 1.b - kembali ke nol zenit")
- GPIO.output(Mot2F, GPIO.HIGH)
- time.sleep(.025)
- if (Lim2 == False):
- GPIO.output(Mot2F, GPIO.LOW)
- teksstring2 = str("scanning - 3. menuju titik terang")
- areabawah = luas*(77/100)
- cerahbawah = cerah*(77/100)
- if (Lim3 == True):
- motor1reverse(.125, 40)
- if (Lim3 == False):
- print("pemindaian gagal, memindai ulang")
- teksstring2 = str("scanning - 3. gagal, mengulangi dari awal")
- scanning = True
- step3 = False
- step1 = True
- lock_x = False
- lock_y = True
- if maxVal > cerahbawah:
- if area > areabawah:
- print("pemindaian selesai")
- teksstring2 = str("scanning - selesai")
- scanning = False
- step3 = False
- step1 = True
- lock_x = False
- lock_y = True
- if (ignore == False) and (scanning == False):
- teksstring2 = str("mode normal - siap")
- if (jamskrg<(terbit + 2)) or (jamskrg>(tenggelam -0.15 )) :
- cv2.destroyAllWindows()
- for i in range (1,16):
- cv2.waitKey(1)
- #kembali ke timur bila belum di timur
- if (Lim4 == True):
- print("sudah malam, kembali ke timur", "| suhu:", "%.2f" %suhu, "°C")
- motor1forward(.125, 39)
- #bila sudah di timur, mode siaga sampai pukul 5.00
- if (Lim4 == False):
- if (Lim2 == True):
- print("sudah malam, kembali ke timur", "| suhu:", "%.2f" %suhu, "°C")
- GPIO.output(Mot2F, GPIO.HIGH)
- time.sleep(0.1)
- if (Lim2 == False):
- GPIO.output(Mot2F, GPIO.LOW)
- print("sudah malam, istirahat", "| suhu:", "%.2f" %suhu, "°C")
- lock_x = True
- lock_y = False
- GPIO.output(kipas, GPIO.LOW)
- tidur = float(time.strftime("%H.%M"))
- while (jamskrg<(terbit + 2)) or (jamskrg>(tenggelam -0.3)) :
- tomboloff=GPIO.input(17)
- if tomboloff == False:
- mulaipencet = time.time()
- time.sleep(0.1)
- lps = None
- lps = GPIO.wait_for_edge(17, GPIO.RISING)
- if lps is not None:
- time.sleep(0.01)
- waktupencet = time.time() - mulaipencet
- if waktupencet > 9 :
- GPIO.output(kipas, GPIO.LOW)
- cv2.destroyAllWindows()
- for i in range (1,5):
- cv2.waitKey(1)
- del camera
- check_call(['/sbin/poweroff'])
- if 10 > waktupencet > 4 :
- GPIO.output(kipas, GPIO.LOW)
- cv2.destroyAllWindows()
- for i in range (1,5):
- cv2.waitKey(1)
- del camera
- check_call(['/sbin/reboot'])
- if 5 > waktupencet > 1 :
- print("tidak dapat memulai pemindaian, belum terbit")
- rise = str( matahari['sunrise'].time())
- sunset = str( matahari['sunset'].time())
- jmtgm, mntgm, dttgm = sunset.split(':')
- jmtbt, mntbt, dttbt = rise.split(':')
- terbit = float(jmtbt + "." + mntbt)
- kerja = terbit + 2
- tenggelam = float( jmtgm + "." + mntgm )
- skrg = float(time.strftime("%H.%M"))
- suhu = float(CPUtemp())
- if skrg < 12 :
- sisa = terbit - skrg
- sker = kerja - skrg
- if skrg > 12 :
- sker = kerja + (24 - skrg)
- sisa = terbit + (24 - skrg)
- if ((skrg) < (6.0)):
- tglskrg = str(time.strftime("%Y-%m-%d"))
- namalog = str("log"+tglskrg+"log1")
- if ((5.59) < (skrg) < (12)):
- tglskrg = str(time.strftime("%Y-%m-%d"))
- namalog = str("log"+tglskrg+"log2")
- if ((11.59) < (skrg) < (18)):
- tglskrg = str(time.strftime("%Y-%m-%d"))
- namalog = str("log"+tglskrg+"log3")
- if ((17.59) < (skrg) < (24)):
- tglskrg = str(time.strftime("%Y-%m-%d"))
- namalog = str("log"+tglskrg+"log4")
- if tidur != skrg :
- tidur = skrg
- print("sudah malam, istirahat", "%.2f" %skrg, "| suhu:", "%.2f" %suhu, "°C")
- if sisa > 0:
- print("tinggal",
- "%.2f" %sisa, "lagi terbit | terbit: ",
- "%.2f" %terbit,
- "| %.2f" %sker, "lagi kerja" )
- teks2 = str("tinggal"+"%.2f" %sisa+"lagi terbit"
- +"| %.2f" %sker+
- " lagi mulai | terbit: %.2f" %terbit)
- if sisa < 0:
- print("terbit: ",
- "%.2f" %terbit,
- "| %.2f" %sker, "lagi kerja" )
- teks2 = str("%.2f" %sker+" lagi mulai | terbit: %.2f" %terbit)
- teks1 = str("sudah malam, istirahat. ini jam "+"%.2f" %skrg+
- "| suhu:"+"%.2f" %suhu+"°C")
- logging = open(namalog+".txt", 'a')
- logging.write(teks1+" || "+teks2+"\n")
- logging.write("--------------------\n")
- logging.close()
- del namalog
- del tglskrg
- print("log diperbarui")
- time.sleep(5)
- if skrg>(terbit + 2) and skrg<(tenggelam-0.3) :
- break
- if (jamskrg > (terbit + 2)) or (jamskrg<(tenggelam-0.15)):
- if(mulailock < jamonminute < selesailock):
- lock_x = False
- lock_y = True
- teksstring3 = teksstring3 + "siang, zenith locked"
- #ketika intensitas tidak cukup
- if maxVal<minimum:
- motorsafe()
- print("intensitas cahaya tidak cukup")
- teksstring2 = str("intensitas tidak cukup")
- #ketika intensitas cukup, mulai mencari
- if maxVal>(minimum -1) :
- if ((terbit +2)<jamskrg<(tenggelam -0.15)):
- if (pa<centre_y<pb) & (155<centre_x<165):
- motorsafe()
- print("posisi sudah tengah")
- if lock_x == True:
- if pa<centre_y<pb:
- motorsafe()
- print("motor2 stop")
- lock_y = True
- lock_x = False
- lockknn = False
- lockkri = False
- if (centre_y<(pa+1)):
- if (Lim1 == True):
- print("kebawah (Zenit -)")
- teksstring2 = str("kebawah (Zenit -)")
- GPIO.output(Mot2R, GPIO.HIGH)
- time.sleep(0.125)
- if (Lim1 == False):
- print("kebawah sudah maksimal")
- GPIO.output(Mot2R, GPIO.LOW)
- lock_x = False
- lock_y = True
- if ((pb-1)<centre_y):
- if (Lim2 == True):
- print("keatas (Zenit +)")
- teksstring2 = str("keatas (Zenit +)")
- GPIO.output(Mot2F, GPIO.HIGH)
- time.sleep(.125)
- if (Lim2 == False):
- print("keatas sudah maksimal")
- GPIO.output(Mot2F, GPIO.LOW)
- lock_x = False
- lock_y = True
- if(jamonminute < (selesailock +90)):
- invknn = True
- invkri = True
- if lock_y == True:
- if 155<centre_x<165:
- print("motor1 stop")
- lock_x = True
- lock_y = False
- if (centre_x<154):
- print("motor 1 kekanan")
- if lockknn == False :
- if (invknn == False):
- if (Lim4 == True):
- print("motor 1 kekanan (Azimut +)")
- teksstring2 = str("kekanan (Azimut +)")
- lockknn = False
- lockkri = False
- motor1forward(.075, 33)
- if (Lim4 == False):
- print("motor 1 maksimal")
- lock_x = True
- lock_y = False
- lockknn = True
- lockkri = False
- if(time.time()-wait3) > 5:
- invknn = not invknn
- wait3 = time.time()
- if (invknn == True):
- if (Lim3 == True):
- print("motor 1 kekanan (invers) (Azimut -)")
- teksstring2 = str("kekanan (inv) (Azimut -)")
- lockknn = False
- lockkri = False
- motor1reverse(.075, 33)
- if (Lim3 == False):
- print("motor 1 maksimal (invers)")
- lock_x = True
- lock_y = False
- lockknn = True
- lockkri = False
- if(time.time()-wait3) > 5:
- invknn = not invknn
- wait = time.time()
- if (time.time()-wait) > 1:
- wait=time.time()
- if ((ctxskg)>(centre_x)):
- invknn = not invknn
- if lockknn == True :
- print("kanan maksimal")
- lock_x = True
- lock_y = False
- lockknn = True
- lockkri = False
- if(time.time()-wait3) > 5:
- invknn = not invknn
- wait3 = time.time()
- if (166<centre_x):
- print("motor 1 kekiri")
- if lockkri == False:
- if (invkri == False):
- if (Lim3 == True):
- print("motor 1 kiri (Azimut -)")
- teksstring2 = str("kekiri (Azimut -)")
- motor1reverse(.075, 33)
- lockknn = False
- lockkri = False
- if (Lim3 == False):
- print("motor 1 maksimal")
- lock_x = True
- lock_y = False
- lockknn = False
- lockkri = True
- if(time.time()-wait3) > 5:
- invkri = not invkri
- wait3 = time.time()
- if (invkri == True):
- if (Lim4 == True):
- print("motor 1 kiri (invers)(Azimut +)")
- teksstring2 = str("kekiri(inv)(Azimut +)")
- motor1forward(.075, 33)
- lockknn = False
- lockkri = False
- if (Lim4 == False):
- print("motor 1 maksimal (invers)")
- lock_x = True
- lock_y = False
- lockknn = False
- lockkri = True
- if(time.time()-wait3) > 5:
- invkri = not invkri
- wait3 = time.time()
- if (time.time()-wait) > 1:
- wait=time.time()
- if((ctxskg)<(centre_x)):
- invkri = not invkri
- if lockkri == True :
- print("kanan maksimal")
- lock_x = True
- lock_y = False
- lockknn = False
- lockkri = True
- if(time.time()-wait3) > 5:
- invknn = not invknn
- wait3 = time.time()
- if (time.time()-waitx) > 3:
- waitx = time.time()
- del ctxskg
- ctxskg = centre_x
- # mengosongi memory stream
- rawCapture.truncate(0)
- #motorsafe()
- if (time.time()-waitclean) > 600:
- cv2.destroyAllWindows()
- for i in range (1,5):
- cv2.waitKey(1)
- waitclean = time.time()
- key = cv2.waitKey(1) & 0xFF
- if (key == ord("q")) or (key == 27):
- break
- if (key == ord("i")):
- ignore = not ignore
- if ignore == True:
- teksstring2 = str("mode manual, p:scan, a,s,d,w:gerak")
- if (key == ord("a")):
- if (Lim4 == True):
- print("motor 1 kiri (invers)(Azimut +)")
- teksstring2 = str("kekiri(inv)(Azimut +)")
- motor1forward(.075, 33)
- lockknn = False
- lockkri = False
- if (Lim4 == False):
- print("motor 1 maksimal (invers)")
- lock_x = True
- lock_y = False
- lockknn = False
- lockkri = True
- if (key == ord("s")):
- if (Lim1 == True):
- print("kebawah (Zenit -)")
- teksstring2 = str("kebawah (Zenit -)")
- GPIO.output(Mot2R, GPIO.HIGH)
- time.sleep(1)
- GPIO.output(Mot2R, GPIO.LOW)
- if (Lim1 == False):
- print("kebawah sudah maksimal")
- GPIO.output(Mot2R, GPIO.LOW)
- lock_x = False
- lock_y = True
- if (key == ord("d")):
- if (Lim3 == True):
- print("motor 1 kekanan (invers) (Azimut -)")
- teksstring2 = str("kekanan (inv) (Azimut -)")
- lockknn = False
- lockkri = False
- motor1reverse(.075, 33)
- if (Lim3 == False):
- print("motor 1 maksimal (invers)")
- lock_x = True
- lock_y = False
- lockknn = True
- lockkri = False
- if (key == ord("w")):
- if (Lim2 == True):
- print("keatas (Zenit +)")
- teksstring2 = str("keatas (Zenit +)")
- GPIO.output(Mot2F, GPIO.HIGH)
- time.sleep(1)
- GPIO.output(Mot2F, GPIO.LOW)
- if (Lim2 == False):
- print("keatas sudah maksimal")
- GPIO.output(Mot2F, GPIO.LOW)
- lock_x = False
- lock_y = True
- if (key == ord("p")):
- print("memulai pemicu runtutan pemindaian")
- scanning = True
- mulaiscan = True
- motorsafe()
- GPIO.output(kipas, GPIO.LOW)
- cv2.destroyAllWindows()
- for i in range (1,5):
- cv2.waitKey(1)
- del camera
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement