finalize code
This commit is contained in:
parent
387bbbb215
commit
cc8b01d574
|
@ -1,3 +1,4 @@
|
||||||
|
from time import perf_counter
|
||||||
import cv2
|
import cv2
|
||||||
from kuukar.kuukar import kuukar
|
from kuukar.kuukar import kuukar
|
||||||
from LaneDetectionModule import getLaneCurve
|
from LaneDetectionModule import getLaneCurve
|
||||||
|
@ -5,7 +6,6 @@ from utils import initializeTrackbars
|
||||||
import WebcamModule
|
import WebcamModule
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
global speed, sen, car, delay
|
global speed, sen, car, delay
|
||||||
from time import perf_counter
|
|
||||||
sen = 1
|
sen = 1
|
||||||
speed = 0
|
speed = 0
|
||||||
delay = 0.15
|
delay = 0.15
|
||||||
|
@ -14,6 +14,8 @@ car = kuukar()
|
||||||
##################################################
|
##################################################
|
||||||
############### MAIN ROBOT LANE ##################
|
############### MAIN ROBOT LANE ##################
|
||||||
##################################################
|
##################################################
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global speed, sen, car, delay
|
global speed, sen, car, delay
|
||||||
while True:
|
while True:
|
||||||
|
@ -21,20 +23,25 @@ def main():
|
||||||
img = WebcamModule.getImg()
|
img = WebcamModule.getImg()
|
||||||
curveVal = getLaneCurve(img, 2)
|
curveVal = getLaneCurve(img, 2)
|
||||||
maxVAl = 1.0 # MAX SPEED
|
maxVAl = 1.0 # MAX SPEED
|
||||||
if curveVal>maxVAl:curveVal = maxVAl
|
if curveVal > maxVAl:
|
||||||
if curveVal<-maxVAl: curveVal =-maxVAl
|
curveVal = maxVAl
|
||||||
|
if curveVal < -maxVAl:
|
||||||
|
curveVal = -maxVAl
|
||||||
# print(curveVal)
|
# print(curveVal)
|
||||||
if curveVal > 0:
|
if curveVal > 0:
|
||||||
sen = 1.7
|
sen = 1.7
|
||||||
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(speed, -curveVal*sen, delay)
|
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")
|
#print(f"looptime: {perf_counter()-stt}s")
|
||||||
cv2.waitKey(1)
|
cv2.waitKey(1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
initialTrackBarVals = [107, 134, 89, 221]
|
initialTrackBarVals = [107, 134, 89, 221]
|
||||||
initializeTrackbars(initialTrackBarVals)
|
initializeTrackbars(initialTrackBarVals)
|
||||||
|
@ -43,7 +50,3 @@ if __name__ == '__main__':
|
||||||
speed = float(input("speed: "))
|
speed = float(input("speed: "))
|
||||||
sen = float(input("sen: "))
|
sen = float(input("sen: "))
|
||||||
delay = float(input("delay: "))
|
delay = float(input("delay: "))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
21
app.py
21
app.py
|
@ -1,24 +1,5 @@
|
||||||
import time
|
|
||||||
# from telemetrix_rpi_pico import telemetrix_rpi_pico
|
|
||||||
# import kuukar.kuukar_leds as kuukar_leds
|
|
||||||
# import kuukar.kuukar_collision as kuukar_collision
|
|
||||||
# import kuukar.kuukar_motion as kuukar_motion
|
|
||||||
# import kuukar.kuukar_lcd as kuukar_lcd
|
|
||||||
# import kuukar.kuukar_sensors as kuukar_sensors
|
|
||||||
# import kuukar.kuukar_environment as kuukar_environment
|
|
||||||
|
|
||||||
# from kuukar.kuukar_config import SERIAL_MCU, SERIAL_DRV
|
|
||||||
|
|
||||||
from kuukar.kuukar import kuukar
|
from kuukar.kuukar import kuukar
|
||||||
|
import time
|
||||||
# mcu = telemetrix_rpi_pico.TelemetrixRpiPico(com_port=SERIAL_MCU, sleep_tune=0.001)
|
|
||||||
# drv = telemetrix_rpi_pico.TelemetrixRpiPico(com_port=SERIAL_DRV, sleep_tune=0.001)
|
|
||||||
# sensors = kuukar_sensors.sensors(mcu)
|
|
||||||
# leds = kuukar_leds.leds(mcu)
|
|
||||||
# motion = kuukar_motion.motion(mcu, drv, leds, sensors)
|
|
||||||
# lcd = kuukar_lcd.lcd(motion, sensors)
|
|
||||||
# environment = kuukar_environment.environment(lcd, leds, sensors)
|
|
||||||
# collision = kuukar_collision.collision(mcu, lcd, leds)
|
|
||||||
|
|
||||||
car = kuukar()
|
car = kuukar()
|
||||||
while True:
|
while True:
|
||||||
|
|
|
@ -22,4 +22,4 @@ class kuukar:
|
||||||
self.lcd, self.leds, self.sensors)
|
self.lcd, self.leds, self.sensors)
|
||||||
self.collision = kuukar_collision.collision(
|
self.collision = kuukar_collision.collision(
|
||||||
self.mcu, self.lcd, self.leds)
|
self.mcu, self.lcd, self.leds)
|
||||||
self.cv = kuukar_cv.cv(self.lcd,self.leds)
|
self.cv = kuukar_cv.cv(self.lcd, self.leds, self.motion)
|
||||||
|
|
|
@ -3,13 +3,16 @@ from kuukar.kuukar_config import COLLISION_DETECTOR_PIN, COLLISION_ENABLE
|
||||||
|
|
||||||
from kuukar.kuukar_lcd import lcd
|
from kuukar.kuukar_lcd import lcd
|
||||||
from kuukar.kuukar_leds import leds
|
from kuukar.kuukar_leds import leds
|
||||||
|
|
||||||
|
|
||||||
class collision:
|
class collision:
|
||||||
def __init__(self, mcu: telemetrix_rpi_pico.TelemetrixRpiPico, lcd: lcd, leds: leds) -> None:
|
def __init__(self, mcu: telemetrix_rpi_pico.TelemetrixRpiPico, lcd: lcd, leds: leds) -> None:
|
||||||
self.mcu = mcu
|
self.mcu = mcu
|
||||||
self.lcd = lcd
|
self.lcd = lcd
|
||||||
self.leds = leds
|
self.leds = leds
|
||||||
if COLLISION_ENABLE:
|
if COLLISION_ENABLE:
|
||||||
self.mcu.set_pin_mode_digital_input(COLLISION_DETECTOR_PIN, self.collision_handle)
|
self.mcu.set_pin_mode_digital_input(
|
||||||
|
COLLISION_DETECTOR_PIN, self.collision_handle)
|
||||||
|
|
||||||
def collision_handle(self, data):
|
def collision_handle(self, data):
|
||||||
val = data[2]
|
val = data[2]
|
||||||
|
|
|
@ -31,4 +31,3 @@ REVERSE_LEDS = [11, 10, 9]
|
||||||
LIGHT_SENSOR_PIN = 0
|
LIGHT_SENSOR_PIN = 0
|
||||||
|
|
||||||
DHT22_PIN = 3
|
DHT22_PIN = 3
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,25 @@
|
||||||
from kuukar.kuukar_lcd import lcd
|
from kuukar.kuukar_lcd import lcd
|
||||||
from kuukar.kuukar_leds import leds
|
from kuukar.kuukar_leds import leds
|
||||||
|
from kuukar.kuukar_motion import motion
|
||||||
import threading
|
import threading
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import cv2
|
import cv2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cv:
|
class cv:
|
||||||
def __init__(self, lcd: lcd, leds: leds) -> None:
|
def __init__(self, lcd: lcd, leds: leds, motion: motion) -> None:
|
||||||
|
self.motion = motion
|
||||||
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:
|
||||||
img = self.capture_image()
|
img = self.capture_image()
|
||||||
##stop_sign = self.detect_sign(img)
|
stop_signs = self.detect_sign(img)
|
||||||
|
if len(stop_signs) >= 1: # Stop Sign Found~!
|
||||||
|
self.motion.stop()
|
||||||
|
|
||||||
def get_road_curve(self, frame):
|
def get_road_curve(self, frame):
|
||||||
pass
|
pass
|
||||||
|
@ -31,4 +34,3 @@ 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
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ from kuukar.kuukar_sensors import sensors
|
||||||
class environment:
|
class environment:
|
||||||
t_alerted = False
|
t_alerted = False
|
||||||
h_alerted = False
|
h_alerted = False
|
||||||
|
|
||||||
def __init__(self, lcd: lcd, leds: leds, sensors: sensors) -> None:
|
def __init__(self, lcd: lcd, leds: leds, sensors: sensors) -> None:
|
||||||
self.lcd = lcd
|
self.lcd = lcd
|
||||||
self.leds = leds
|
self.leds = leds
|
||||||
|
@ -18,7 +19,7 @@ class environment:
|
||||||
while True:
|
while True:
|
||||||
if self.sensors.get_temperature() > 38.0:
|
if self.sensors.get_temperature() > 38.0:
|
||||||
if not self.t_alerted:
|
if not self.t_alerted:
|
||||||
#self.lcd.play_video("keke_died")
|
self.lcd.play_video("keke_hurt")
|
||||||
self.t_alerted = True
|
self.t_alerted = True
|
||||||
else:
|
else:
|
||||||
self.t_alerted = False
|
self.t_alerted = False
|
||||||
|
|
|
@ -52,6 +52,7 @@ class lcd:
|
||||||
print(f"Setting speed to {speed} and turn angle to {turn}")
|
print(f"Setting speed to {speed} and turn angle to {turn}")
|
||||||
if not self.motion.is_roaming():
|
if not self.motion.is_roaming():
|
||||||
self.motion.drive_skew(speed, turn)
|
self.motion.drive_skew(speed, turn)
|
||||||
|
|
||||||
def _sensor_screen_updator(self):
|
def _sensor_screen_updator(self):
|
||||||
while True:
|
while True:
|
||||||
self.nextion.send_command(
|
self.nextion.send_command(
|
||||||
|
|
|
@ -71,7 +71,6 @@ class motion:
|
||||||
self.leds.set_right_signal_led(False)
|
self.leds.set_right_signal_led(False)
|
||||||
self.leds.set_left_signal_led(True)
|
self.leds.set_left_signal_led(True)
|
||||||
|
|
||||||
|
|
||||||
lm_speed = (100+dir/2)*speed/100
|
lm_speed = (100+dir/2)*speed/100
|
||||||
if lm_speed > 99:
|
if lm_speed > 99:
|
||||||
lm_speed = 99
|
lm_speed = 99
|
||||||
|
@ -81,7 +80,7 @@ class motion:
|
||||||
if rm_speed > 99:
|
if rm_speed > 99:
|
||||||
rm_speed = 99
|
rm_speed = 99
|
||||||
elif rm_speed < -99:
|
elif rm_speed < -99:
|
||||||
rm_speed = -99;
|
rm_speed = -99
|
||||||
|
|
||||||
self.motor_write(MOTOR_FL_F, MOTOR_FL_R, lm_speed)
|
self.motor_write(MOTOR_FL_F, MOTOR_FL_R, lm_speed)
|
||||||
self.motor_write(MOTOR_FR_F, MOTOR_FR_R, rm_speed)
|
self.motor_write(MOTOR_FR_F, MOTOR_FR_R, rm_speed)
|
||||||
|
@ -123,12 +122,18 @@ class motion:
|
||||||
turn *= 100
|
turn *= 100
|
||||||
leftSpeed = speed - turn
|
leftSpeed = speed - turn
|
||||||
rightSpeed = speed + turn
|
rightSpeed = speed + turn
|
||||||
if leftSpeed>99: leftSpeed=99
|
if leftSpeed > 99:
|
||||||
elif leftSpeed<-99: leftSpeed= -99
|
leftSpeed = 99
|
||||||
if rightSpeed>99: rightSpeed=99
|
elif leftSpeed < -99:
|
||||||
elif rightSpeed<-99: rightSpeed= -99
|
leftSpeed = -99
|
||||||
if speed>99: speed=99
|
if rightSpeed > 99:
|
||||||
elif speed<-99: speed= -99
|
rightSpeed = 99
|
||||||
|
elif rightSpeed < -99:
|
||||||
|
rightSpeed = -99
|
||||||
|
if speed > 99:
|
||||||
|
speed = 99
|
||||||
|
elif speed < -99:
|
||||||
|
speed = -99
|
||||||
|
|
||||||
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))
|
||||||
|
@ -136,7 +141,6 @@ class motion:
|
||||||
#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)
|
||||||
|
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.leds.set_left_signal_led(False)
|
self.leds.set_left_signal_led(False)
|
||||||
self.leds.set_right_signal_led(False)
|
self.leds.set_right_signal_led(False)
|
||||||
|
|
Loading…
Reference in New Issue