Compare commits

..

No commits in common. "cc8b01d5749279e47c1b3bd5ad2d17971e6f91cf" and "82620a98ca14416c6c47802602256ffca5833ef3" have entirely different histories.

10 changed files with 74 additions and 68 deletions

View File

@ -1,4 +1,3 @@
from time import perf_counter
import cv2
from kuukar.kuukar import kuukar
from LaneDetectionModule import getLaneCurve
@ -6,6 +5,7 @@ from utils import initializeTrackbars
import WebcamModule
from threading import Thread
global speed, sen, car, delay
from time import perf_counter
sen = 1
speed = 0
delay = 0.15
@ -14,34 +14,27 @@ car = kuukar()
##################################################
############### MAIN ROBOT LANE ##################
##################################################
def main():
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
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)
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)
@ -50,3 +43,7 @@ if __name__ == '__main__':
speed = float(input("speed: "))
sen = float(input("sen: "))
delay = float(input("delay: "))

21
app.py
View File

@ -1,5 +1,24 @@
from kuukar.kuukar import kuukar
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
# 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()
while True:

View File

@ -22,4 +22,4 @@ class kuukar:
self.lcd, self.leds, self.sensors)
self.collision = kuukar_collision.collision(
self.mcu, self.lcd, self.leds)
self.cv = kuukar_cv.cv(self.lcd, self.leds, self.motion)
self.cv = kuukar_cv.cv(self.lcd,self.leds)

View File

@ -3,16 +3,13 @@ from kuukar.kuukar_config import COLLISION_DETECTOR_PIN, COLLISION_ENABLE
from kuukar.kuukar_lcd import lcd
from kuukar.kuukar_leds import leds
class collision:
def __init__(self, mcu: telemetrix_rpi_pico.TelemetrixRpiPico, lcd: lcd, leds: leds) -> None:
self.mcu = mcu
self.lcd = lcd
self.leds = leds
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):
val = data[2]

View File

@ -31,3 +31,4 @@ REVERSE_LEDS = [11, 10, 9]
LIGHT_SENSOR_PIN = 0
DHT22_PIN = 3

View File

@ -1,25 +1,22 @@
from kuukar.kuukar_lcd import lcd
from kuukar.kuukar_leds import leds
from kuukar.kuukar_motion import motion
import threading
import multiprocessing
import cv2
class cv:
def __init__(self, lcd: lcd, leds: leds, motion: motion) -> None:
self.motion = motion
def __init__(self, lcd: lcd, leds: leds) -> None:
self.lcd = lcd
self.leds = leds
self.camera = cv2.VideoCapture(0)
threading.Thread(target=self._cv_loop).start()
#self.camera = cv2.VideoCapture(0)
#threading.Thread(target=self._cv_loop).start()
def _cv_loop(self):
while True:
img = self.capture_image()
stop_signs = self.detect_sign(img)
if len(stop_signs) >= 1: # Stop Sign Found~!
self.motion.stop()
##stop_sign = self.detect_sign(img)
def get_road_curve(self, frame):
pass
@ -31,6 +28,7 @@ class cv:
def detect_sign(self, frame):
stopsign_cascade = cv2.CascadeClassifier('./stopsign_good.xml')
image = frame.array
gray_img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
found_stopsigns = stopsign_cascade.detectMultiScale(gray_img, 1.1, 5)
gray_img=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
found_stopsigns=stopsign_cascade.detectMultiScale(gray_img,1.1,5)
return found_stopsigns

View File

@ -8,7 +8,6 @@ from kuukar.kuukar_sensors import sensors
class environment:
t_alerted = False
h_alerted = False
def __init__(self, lcd: lcd, leds: leds, sensors: sensors) -> None:
self.lcd = lcd
self.leds = leds
@ -19,7 +18,7 @@ class environment:
while True:
if self.sensors.get_temperature() > 38.0:
if not self.t_alerted:
self.lcd.play_video("keke_hurt")
#self.lcd.play_video("keke_died")
self.t_alerted = True
else:
self.t_alerted = False

View File

@ -51,8 +51,7 @@ class lcd:
turn = (x - 5) / (150 - 5) * 200 - 100
print(f"Setting speed to {speed} and turn angle to {turn}")
if not self.motion.is_roaming():
self.motion.drive_skew(speed, turn)
self.motion.drive_skew(speed,turn)
def _sensor_screen_updator(self):
while True:
self.nextion.send_command(

View File

@ -18,7 +18,7 @@ class leds:
def __init__(self, mcu: telemetrix_rpi_pico.TelemetrixRpiPico) -> None:
self.mcu = mcu
self.mcu.set_pin_mode_neopixel(LEDS_DATA_PIN, LEDS_NUM)
self.ambient_light = [2, 2, 10] # Keke Image Color
self.ambient_light = [2, 2, 10] #Keke Image Color
self.__update_leds()
def set_headlights(self, state: bool):

View File

@ -71,16 +71,17 @@ class motion:
self.leds.set_right_signal_led(False)
self.leds.set_left_signal_led(True)
lm_speed = (100+dir/2)*speed/100
if lm_speed > 99:
if lm_speed>99:
lm_speed = 99
elif lm_speed < -99:
elif lm_speed<-99:
lm_speed = -99
rm_speed = (100-dir/2)*speed/100
if rm_speed > 99:
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_FR_F, MOTOR_FR_R, rm_speed)
@ -118,22 +119,16 @@ class motion:
'''
def skt_drive(self, speed: float, turn: float, t=0):
speed *= 100
turn *= 100
speed *=100
turn *=100
leftSpeed = speed - turn
rightSpeed = speed + turn
if leftSpeed > 99:
leftSpeed = 99
elif leftSpeed < -99:
leftSpeed = -99
if rightSpeed > 99:
rightSpeed = 99
elif rightSpeed < -99:
rightSpeed = -99
if speed > 99:
speed = 99
elif speed < -99:
speed = -99
if leftSpeed>99: leftSpeed=99
elif leftSpeed<-99: leftSpeed= -99
if rightSpeed>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_FR_F, MOTOR_FR_R, abs(rightSpeed))
@ -141,6 +136,7 @@ class motion:
#self.motor_write(MOTOR_RR_F, MOTOR_RR_R, speed)
time.sleep(t)
def stop(self):
self.leds.set_left_signal_led(False)
self.leds.set_right_signal_led(False)
@ -163,12 +159,12 @@ class motion:
while True:
if self.roaming:
self.__roam_handle()
time.sleep(0.1)
time.sleep(0.5)
def __roam_handle(self):
if self.sensors.sonar_get_distance() < 900:
self.turn(32, 2600)
if self.sensors.sonar_get_distance()<500:
self.turn(30,2000)
self.drive(25)
time.sleep(0.5)
if not self.roaming:
self.stop()