Create Main Robot Lane

Create Main Robot Lane and WebcamModule
This commit is contained in:
Siwat Sirichai 2022-12-10 20:49:21 +07:00
parent 332e5b2c5e
commit d49285d210
2 changed files with 45 additions and 0 deletions

31
kuukar/MainRobotLane.py Normal file
View File

@ -0,0 +1,31 @@
from kuukar import kuukar_motion
from LaneDetectionModule import getLaneCurve
import WebcamModule
##################################################
############### MAIN ROBOT LANE ##################
##################################################
def main():
img = WebcamModule.getImg()
curveVal= getLaneCurve(img,1)
sen = 1.3 # SENSITIVITY
maxVAl= 0.3 # MAX SPEED
if curveVal>maxVAl:curveVal = maxVAl
if curveVal<-maxVAl: curveVal =-maxVAl
#print(curveVal)
if curveVal>0:
sen =1.7
if curveVal<0.05: curveVal=0
else:
if curveVal>-0.08: curveVal=0
motor.move(0.20,-curveVal*sen,0.05)
cv2.waitKey(1)
if __name__ == '__main__':
while True:
main()

14
kuukar/WebcamModule.py Normal file
View File

@ -0,0 +1,14 @@
import cv2
cap = cv2.VideoCapture(0)
def getImg(display= False,size=[480,240]):
_, img = cap.read()
img = cv2.resize(img,(size[0],size[1]))
if display:
cv2.imshow('IMG',img)
return img
if __name__ == '__main__':
while True:
img = getImg(True)