This commit is contained in:
Siwat Sirichai 2022-12-12 16:10:23 +07:00
parent db0de37387
commit 8e31b4c159
3 changed files with 43 additions and 35 deletions

View File

@ -3,40 +3,47 @@ from kuukar.kuukar import kuukar
from LaneDetectionModule import getLaneCurve from LaneDetectionModule import getLaneCurve
from utils import initializeTrackbars from utils import initializeTrackbars
import WebcamModule 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() car = kuukar()
################################################## ##################################################
############### MAIN ROBOT LANE ################## ############### MAIN ROBOT LANE ##################
################################################## ##################################################
def main(): def main():
global speed, sen, car, delay
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)
while True: 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: "))

View File

@ -10,8 +10,8 @@ class cv:
def __init__(self, lcd: lcd, leds: leds) -> None: def __init__(self, lcd: lcd, leds: leds) -> None:
self.lcd = lcd self.lcd = lcd
self.leds = leds self.leds = leds
self.camera = cv2.VideoCapture(0) #self.camera = cv2.VideoCapture(0)
threading.Thread(target=self._cv_loop).start() #threading.Thread(target=self._cv_loop).start()
def _cv_loop(self): def _cv_loop(self):
while True: while True:
@ -31,3 +31,4 @@ class cv:
gray_img=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) gray_img=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
found_stopsigns=stopsign_cascade.detectMultiScale(gray_img,1.1,5) found_stopsigns=stopsign_cascade.detectMultiScale(gray_img,1.1,5)
return found_stopsigns return found_stopsigns

View File

@ -132,8 +132,8 @@ class motion:
self.motor_write(MOTOR_FL_F, MOTOR_FL_R, abs(leftSpeed)) 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_FR_F, MOTOR_FR_R, abs(rightSpeed))
self.motor_write(MOTOR_RL_F, MOTOR_RL_R, speed) #self.motor_write(MOTOR_RL_F, MOTOR_RL_R, speed)
self.motor_write(MOTOR_RR_F, MOTOR_RR_R, speed) #self.motor_write(MOTOR_RR_F, MOTOR_RR_R, speed)
time.sleep(t) time.sleep(t)