kuukar-rpi/MainRobotLane.py

53 lines
1.5 KiB
Python
Raw Normal View History

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