From 8e31b4c15975146a3657728d91f296a7abf9dd91 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Mon, 12 Dec 2022 16:10:23 +0700 Subject: [PATCH] . --- MainRobotLane.py | 69 +++++++++++++++++++++++------------------ kuukar/kuukar_cv.py | 5 +-- kuukar/kuukar_motion.py | 4 +-- 3 files changed, 43 insertions(+), 35 deletions(-) diff --git a/MainRobotLane.py b/MainRobotLane.py index 5f79a11..e6fa26b 100644 --- a/MainRobotLane.py +++ b/MainRobotLane.py @@ -3,40 +3,47 @@ from kuukar.kuukar import kuukar from LaneDetectionModule import getLaneCurve from utils import initializeTrackbars import WebcamModule - +from threading import Thread +global speed, sen, car, delay +from time import perf_counter +sen = 1 +speed = 0 +delay = 0.15 car = kuukar() - - + ################################################## ############### MAIN ROBOT LANE ################## ################################################## - def main(): - - - - img = WebcamModule.getImg() - curveVal= getLaneCurve(img,2) - - sen = 0.8 # SENSITIVITY - maxVAl= 1.0 # 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 - car.motion.skt_drive(0.4,-curveVal*sen,0.05) - turn_value = -curveVal*sen - print("Curve Value : " + str(curveVal) + " Turn Value : "+ str(round(turn_value,2)) - cv2.waitKey(1) - - -if __name__ == '__main__': - initialTrackBarVals = [70, 124, 4, 195] - initializeTrackbars(initialTrackBarVals) - + global speed, sen, car, delay while True: - main() + stt = perf_counter() + img = WebcamModule.getImg() + curveVal= getLaneCurve(img,2) + maxVAl= 1.0 # 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 + car.motion.skt_drive(speed,-curveVal*sen,delay) + turn_value = -curveVal*sen + #print("Curve Value : " + str(curveVal) + " Turn Value : "+ str(round(turn_value,2))) + #print(f"looptime: {perf_counter()-stt}s") + cv2.waitKey(1) + +if __name__ == '__main__': + initialTrackBarVals = [107, 134, 89, 221] + initializeTrackbars(initialTrackBarVals) + Thread(target=main).start() + while True: + speed = float(input("speed: ")) + sen = float(input("sen: ")) + delay = float(input("delay: ")) + + + + diff --git a/kuukar/kuukar_cv.py b/kuukar/kuukar_cv.py index 63b6cea..1f24c36 100644 --- a/kuukar/kuukar_cv.py +++ b/kuukar/kuukar_cv.py @@ -10,8 +10,8 @@ class cv: def __init__(self, lcd: lcd, leds: leds) -> None: self.lcd = lcd self.leds = leds - self.camera = cv2.VideoCapture(0) - threading.Thread(target=self._cv_loop).start() + #self.camera = cv2.VideoCapture(0) + #threading.Thread(target=self._cv_loop).start() def _cv_loop(self): while True: @@ -31,3 +31,4 @@ class cv: gray_img=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) found_stopsigns=stopsign_cascade.detectMultiScale(gray_img,1.1,5) return found_stopsigns + diff --git a/kuukar/kuukar_motion.py b/kuukar/kuukar_motion.py index 444316a..13cbec0 100644 --- a/kuukar/kuukar_motion.py +++ b/kuukar/kuukar_motion.py @@ -132,8 +132,8 @@ class motion: self.motor_write(MOTOR_FL_F, MOTOR_FL_R, abs(leftSpeed)) self.motor_write(MOTOR_FR_F, MOTOR_FR_R, abs(rightSpeed)) - self.motor_write(MOTOR_RL_F, MOTOR_RL_R, speed) - self.motor_write(MOTOR_RR_F, MOTOR_RR_R, speed) + #self.motor_write(MOTOR_RL_F, MOTOR_RL_R, speed) + #self.motor_write(MOTOR_RR_F, MOTOR_RR_R, speed) time.sleep(t)