2022-12-10 15:15:21 +00:00
|
|
|
import cv2
|
|
|
|
from kuukar.kuukar import kuukar
|
2022-12-10 13:49:21 +00:00
|
|
|
from LaneDetectionModule import getLaneCurve
|
2022-12-10 15:15:21 +00:00
|
|
|
from utils import initializeTrackbars
|
2022-12-10 13:49:21 +00:00
|
|
|
import WebcamModule
|
2022-12-12 09:10:23 +00:00
|
|
|
from threading import Thread
|
|
|
|
global speed, sen, car, delay
|
|
|
|
from time import perf_counter
|
|
|
|
sen = 1
|
|
|
|
speed = 0
|
|
|
|
delay = 0.15
|
2022-12-10 15:15:21 +00:00
|
|
|
car = kuukar()
|
2022-12-12 09:10:23 +00:00
|
|
|
|
2022-12-10 13:49:21 +00:00
|
|
|
##################################################
|
|
|
|
############### MAIN ROBOT LANE ##################
|
|
|
|
##################################################
|
|
|
|
def main():
|
2022-12-12 09:10:23 +00:00
|
|
|
global speed, sen, car, delay
|
|
|
|
while True:
|
|
|
|
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)
|
2022-12-10 15:15:21 +00:00
|
|
|
|
2022-12-10 13:49:21 +00:00
|
|
|
if __name__ == '__main__':
|
2022-12-12 09:10:23 +00:00
|
|
|
initialTrackBarVals = [107, 134, 89, 221]
|
2022-12-10 15:15:21 +00:00
|
|
|
initializeTrackbars(initialTrackBarVals)
|
2022-12-12 09:10:23 +00:00
|
|
|
Thread(target=main).start()
|
2022-12-10 13:49:21 +00:00
|
|
|
while True:
|
2022-12-12 09:10:23 +00:00
|
|
|
speed = float(input("speed: "))
|
|
|
|
sen = float(input("sen: "))
|
|
|
|
delay = float(input("delay: "))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|