This commit is contained in:
parent
db0de37387
commit
8e31b4c159
|
@ -3,22 +3,23 @@ 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
|
||||||
|
while True:
|
||||||
|
stt = perf_counter()
|
||||||
img = WebcamModule.getImg()
|
img = WebcamModule.getImg()
|
||||||
curveVal= getLaneCurve(img,2)
|
curveVal= getLaneCurve(img,2)
|
||||||
|
|
||||||
sen = 0.8 # SENSITIVITY
|
|
||||||
maxVAl= 1.0 # MAX SPEED
|
maxVAl= 1.0 # MAX SPEED
|
||||||
if curveVal>maxVAl:curveVal = maxVAl
|
if curveVal>maxVAl:curveVal = maxVAl
|
||||||
if curveVal<-maxVAl: curveVal =-maxVAl
|
if curveVal<-maxVAl: curveVal =-maxVAl
|
||||||
|
@ -28,15 +29,21 @@ def main():
|
||||||
if curveVal<0.05: curveVal=0
|
if curveVal<0.05: curveVal=0
|
||||||
else:
|
else:
|
||||||
if curveVal>-0.08: curveVal=0
|
if curveVal>-0.08: curveVal=0
|
||||||
car.motion.skt_drive(0.4,-curveVal*sen,0.05)
|
car.motion.skt_drive(speed,-curveVal*sen,delay)
|
||||||
turn_value = -curveVal*sen
|
turn_value = -curveVal*sen
|
||||||
print("Curve Value : " + str(curveVal) + " Turn Value : "+ str(round(turn_value,2))
|
#print("Curve Value : " + str(curveVal) + " Turn Value : "+ str(round(turn_value,2)))
|
||||||
|
#print(f"looptime: {perf_counter()-stt}s")
|
||||||
cv2.waitKey(1)
|
cv2.waitKey(1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
initialTrackBarVals = [70, 124, 4, 195]
|
initialTrackBarVals = [107, 134, 89, 221]
|
||||||
initializeTrackbars(initialTrackBarVals)
|
initializeTrackbars(initialTrackBarVals)
|
||||||
|
Thread(target=main).start()
|
||||||
while True:
|
while True:
|
||||||
main()
|
speed = float(input("speed: "))
|
||||||
|
sen = float(input("sen: "))
|
||||||
|
delay = float(input("delay: "))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue