From d49285d210732efff2fa1f54afff9fffb12a898a Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Sat, 10 Dec 2022 20:49:21 +0700 Subject: [PATCH] Create Main Robot Lane Create Main Robot Lane and WebcamModule --- kuukar/MainRobotLane.py | 31 +++++++++++++++++++++++++++++++ kuukar/WebcamModule.py | 14 ++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 kuukar/MainRobotLane.py create mode 100644 kuukar/WebcamModule.py diff --git a/kuukar/MainRobotLane.py b/kuukar/MainRobotLane.py new file mode 100644 index 0000000..95347fb --- /dev/null +++ b/kuukar/MainRobotLane.py @@ -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() \ No newline at end of file diff --git a/kuukar/WebcamModule.py b/kuukar/WebcamModule.py new file mode 100644 index 0000000..0a56138 --- /dev/null +++ b/kuukar/WebcamModule.py @@ -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) \ No newline at end of file