#Detection Frelon
frelons = frelon_cascade.detectMultiScale(zonedetection, scaleFactor=1.2, minSize=(tailleMin,tailleMin), maxSize = (tailleMax,tailleMax), minNeighbors=voisinsMini)
if((type(frelons) == tuple) or (type(frelons) == list)):
led2.off()
detection = False
(a,b,c,d) = (0+marge,0+marge+y1zonebaguette+100,largeurutile-2*marge,y2zonebaguette-200-2*marge-y1zonebaguette)
Z=hauteurbaguette
morient.stop()
else:
led2.on()
(x, y, w, h) = frelons[0]
cv2.putText(m.array, str(int(w)), (40, 200), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 2)
(a,b,c,d)=(x+a-marge,y+b-marge,w,h)
Z=(b+d/2-hauteurbaguette)
xt=int(a*80/largeurutile)
yt=int(b*32/hauteurutile)
listZ.insert(0,Z)
listZ = listZ[:5]
P=Z
I=(sum(listZ))
D=abs(listZ[0])-abs(listZ[1])
consigne = (abs(kp*P+ki*I)-kd*D)/facteurglobal
if consigne > consigneMax:
consigne = consigneMax
if consigne < consigneMin:
if consigne < 5:
consigne = 0
else:
consigne = consigneMin
#contrôle moteurs
if Z<-10:
if LS_forward.is_pressed:
morient.stop()
else:
morient.forward(consigne/100)
elif Z>10:
if LS_backward.is_pressed:
morient.stop()
else:
morient.backward(consigne/100)
elif (abs(Z)<10 and r==0):
led1.on()
Tir()
time.sleep(0.5)
r = 10
led1.off()
Rearmement()
#Detection Frelon
frelons = frelon_cascade.detectMultiScale(zonedetection, scaleFactor=1.2, minSize=(tailleMin,tailleMin), maxSize = (tailleMax,tailleMax), minNeighbors=voisinsMini)
if((type(frelons) == tuple) or (type(frelons) == list)):
led2.off()
detection = False
(a,b,c,d) = (0+marge,0+marge+y1zonebaguette+100,largeurutile-2*marge,y2zonebaguette-200-2*marge-y1zonebaguette)
Z=hauteurbaguette
morient.stop()
else:
led2.on()
(x, y, w, h) = frelons[0]
cv2.putText(m.array, str(int(w)), (40, 200), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 2)
(a,b,c,d)=(x+a-marge,y+b-marge,w,h)
Z=(b+d/2-hauteurbaguette)
xt=int(a*80/largeurutile)
yt=int(b*32/hauteurutile)
listZ.insert(0,Z)
listZ = listZ[:5]
P=Z
I=(sum(listZ))
D=abs(listZ[0])-abs(listZ[1])
consigne = (abs(kp*P+ki*I)-kd*D)/facteurglobal
if consigne > consigneMax:
consigne = consigneMax
if consigne < consigneMin:
if consigne < 5:
consigne = 0
else:
consigne = consigneMin
#contrôle moteurs
if Z<-10:
if LS_forward.is_pressed:
morient.stop()
else:
morient.forward(consigne/100)
elif Z>10:
if LS_backward.is_pressed:
morient.stop()
else:
morient.backward(consigne/100)
elif (abs(Z)<10 and r==0):
led1.on()
Tir()
time.sleep(0.5)
r = 10
led1.off()
Rearmement()