added environment sensing
This commit is contained in:
parent
37d8285b97
commit
3c3010d590
|
@ -1,5 +1,5 @@
|
|||
from telemetrix_rpi_pico import telemetrix_rpi_pico
|
||||
import kuukar_leds, kuukar_collision, kuukar_motion, kuukar_lcd, kuukar_sensors
|
||||
import kuukar_leds, kuukar_collision, kuukar_motion, kuukar_lcd, kuukar_sensors, kuukar_environment
|
||||
|
||||
from kuukar_config import SERIAL_AUX_BOARD, SERIAL_DRIVER_BOARD
|
||||
if __name__ == '__main__':
|
||||
|
@ -8,4 +8,6 @@ if __name__ == '__main__':
|
|||
sensors = kuukar_sensors.sensors(aux_board,driver_board)
|
||||
leds = kuukar_leds.leds(aux_board=aux_board)
|
||||
lcd = kuukar_lcd.lcd()
|
||||
environment = kuukar_environment.environment(lcd,leds,sensors)
|
||||
collision = kuukar_collision.collision(aux_board,lcd,leds)
|
||||
motion = kuukar_motion.motion(driver_board=driver_board,leds=leds,sensors= sensors)
|
|
@ -1,5 +1,6 @@
|
|||
SERIAL_DRIVER_BOARD = "/dev/serial/by-id/..."
|
||||
|
||||
# HC Sonar Pins
|
||||
SONAR_1_TRIG_PIN = 0
|
||||
SONAR_1_ECHO_PIN = 1
|
||||
SONAR_2_TRIG_PIN = 2
|
||||
|
@ -7,6 +8,7 @@ SONAR_2_ECHO_PIN = 3
|
|||
SONAR_3_TRIG_PIN = 4
|
||||
SONAR_3_ECHO_PIN = 5
|
||||
|
||||
# Motor Pins
|
||||
MOTOR_FL_F = 6
|
||||
MOTOR_FL_R = 7
|
||||
MOTOR_FR_F = 8
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
from kuukar_lcd import lcd
|
||||
from kuukar_leds import leds
|
||||
|
||||
|
||||
class cv:
|
||||
def __init__(self, lcd: lcd, leds: leds) -> None:
|
||||
self.lcd = lcd
|
||||
self.leds = leds
|
||||
self.noise = noise
|
||||
|
||||
def capture_image(self):
|
||||
pass
|
||||
|
||||
def detectFace(self, image):
|
||||
pass
|
||||
|
||||
def handle_face_detected(self):
|
||||
pass
|
||||
pass
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
import threading
|
||||
from time import sleep
|
||||
from kuukar_lcd import lcd
|
||||
from kuukar_leds import leds
|
||||
from 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
|
||||
self.sensors = sensors
|
||||
threading.Thread(target=self.__checker__).start()
|
||||
|
||||
def __checker__(self):
|
||||
while True:
|
||||
if self.sensors.get_temperature() > 38.0:
|
||||
if not self.t_alerted:
|
||||
lcd.keke_died()
|
||||
self.t_alerted = True
|
||||
else:
|
||||
self.t_alerted = False
|
||||
|
||||
if self.sensors.get_humidity_pct() > 60.0:
|
||||
if not self.h_alerted:
|
||||
lcd.keke_cute_noise()
|
||||
self.h_alerted = True
|
||||
else:
|
||||
self.h_alerted = False
|
||||
|
||||
sleep(5)
|
|
@ -5,9 +5,15 @@ class lcd:
|
|||
def keke_uwu(self):
|
||||
pass
|
||||
|
||||
def keke_cute_noise(self):
|
||||
pass
|
||||
|
||||
def keke_hurt(self):
|
||||
pass
|
||||
|
||||
def keke_died(self):
|
||||
pass
|
||||
|
||||
def takina_noise(self):
|
||||
pass
|
||||
|
||||
|
@ -20,7 +26,6 @@ class lcd:
|
|||
def resume_video(self) -> None:
|
||||
pass
|
||||
|
||||
|
||||
def stop_video(self) -> None:
|
||||
pass
|
||||
|
|
@ -1,10 +1,12 @@
|
|||
from telemetrix_rpi_pico import telemetrix_rpi_pico
|
||||
|
||||
from kuukar_config import LEDS_DATA_PIN, LEDS_NUM
|
||||
|
||||
|
||||
class leds:
|
||||
def __init__(self, aux_board: telemetrix_rpi_pico.TelemetrixRpiPico) -> None:
|
||||
self.aux_board = aux_board
|
||||
self.aux_board.set_pin_mode_neopixel(LEDS_DATA_PIN,LEDS_NUM)
|
||||
self.aux_board.set_pin_mode_neopixel(LEDS_DATA_PIN, LEDS_NUM)
|
||||
|
||||
def flash(self, r: int,g: int,b: int,duration_ms: int):
|
||||
pass
|
||||
def flash(self, r: int, g: int, b: int, duration_ms: int):
|
||||
pass
|
||||
|
|
|
@ -6,6 +6,7 @@ from kuukar_sensors import sensors
|
|||
from telemetrix_rpi_pico import telemetrix_rpi_pico
|
||||
import threading
|
||||
|
||||
|
||||
class motion:
|
||||
|
||||
roaming = False
|
||||
|
@ -14,32 +15,33 @@ class motion:
|
|||
self.driver = driver_board
|
||||
self.leds = leds
|
||||
self.sensors = sensors
|
||||
self.roam_thread = threading.Thread(target = self.roam_loop)
|
||||
self.roam_thread = threading.Thread(target=self.roam_loop)
|
||||
self.roam_thread.start()
|
||||
|
||||
drive_pins = [MOTOR_FL_F,MOTOR_FL_R,MOTOR_FR_F,MOTOR_FR_R,MOTOR_RL_F,MOTOR_RL_R,MOTOR_RR_F,MOTOR_RR_R]
|
||||
|
||||
drive_pins = [MOTOR_FL_F, MOTOR_FL_R, MOTOR_FR_F,
|
||||
MOTOR_FR_R, MOTOR_RL_F, MOTOR_RL_R, MOTOR_RR_F, MOTOR_RR_R]
|
||||
for drive_pin in drive_pins:
|
||||
self.driver.set_pin_mode_pwm_output(drive_pin)
|
||||
|
||||
def motor_write(self, forward_pin: int,reverse_pin: int, speed: int):
|
||||
def motor_write(self, forward_pin: int, reverse_pin: int, speed: int):
|
||||
if speed < 0:
|
||||
self.driver.pwm_write(forward_pin,0)
|
||||
self.driver.pwm_write(reverse_pin,-speed)
|
||||
self.driver.pwm_write(forward_pin, 0)
|
||||
self.driver.pwm_write(reverse_pin, -speed)
|
||||
elif speed >= 0:
|
||||
self.driver.pwm_write(forward_pin,speed)
|
||||
self.driver.pwm_write(reverse_pin,0)
|
||||
self.driver.pwm_write(forward_pin, speed)
|
||||
self.driver.pwm_write(reverse_pin, 0)
|
||||
|
||||
def drive(self, speed: int):
|
||||
self.motor_write(MOTOR_FL_F,MOTOR_FL_R,speed)
|
||||
self.motor_write(MOTOR_FR_F,MOTOR_FR_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_FL_F, MOTOR_FL_R, speed)
|
||||
self.motor_write(MOTOR_FR_F, MOTOR_FR_R, speed)
|
||||
self.motor_write(MOTOR_RL_F, MOTOR_RL_R, speed)
|
||||
self.motor_write(MOTOR_RR_F, MOTOR_RR_R, speed)
|
||||
|
||||
def turn(self, speed: int, duration: float):
|
||||
self.motor_write(MOTOR_FL_F,MOTOR_FL_R,speed)
|
||||
self.motor_write(MOTOR_FR_F,MOTOR_FR_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_FL_F, MOTOR_FL_R, speed)
|
||||
self.motor_write(MOTOR_FR_F, MOTOR_FR_R, -speed)
|
||||
self.motor_write(MOTOR_RL_F, MOTOR_RL_R, speed)
|
||||
self.motor_write(MOTOR_RR_F, MOTOR_RR_R, -speed)
|
||||
time.sleep(duration)
|
||||
self.stop()
|
||||
|
||||
|
@ -60,29 +62,29 @@ class motion:
|
|||
def __roam_handle__(self):
|
||||
self.drive(50)
|
||||
f_dist = self.sensors.sonar_get_distance(2)
|
||||
if f_dist > 0 and f_dist < 20: # Close to collision, turn the vehicle
|
||||
if f_dist > 0 and f_dist < 20: # Close to collision, turn the vehicle
|
||||
l_dist = self.sensors.sonar_get_distance
|
||||
r_dist = self.sensors.sonar_get_distance
|
||||
if l_dist < 20: #Left side is blocked
|
||||
if r_dist < 20: #Both side are blocked, do a full 180deg turn
|
||||
self.turn(100,2*TURN_TIME_FS_90DEG_MS)
|
||||
if l_dist < 20: # Left side is blocked
|
||||
if r_dist < 20: # Both side are blocked, do a full 180deg turn
|
||||
self.turn(100, 2*TURN_TIME_FS_90DEG_MS)
|
||||
self.drive(50)
|
||||
time.sleep(3)
|
||||
else:
|
||||
#Right Side is Free, turn right
|
||||
self.turn(100,TURN_TIME_FS_90DEG_MS)
|
||||
# Right Side is Free, turn right
|
||||
self.turn(100, TURN_TIME_FS_90DEG_MS)
|
||||
self.drive(50)
|
||||
time.sleep(3)
|
||||
elif r_dist < 20: #Right side is blocked, left side is free, turn left
|
||||
self.turn(-100,TURN_TIME_FS_90DEG_MS)
|
||||
else: #Both Side are free, randomize a direction
|
||||
right: bool = randint(0,1)
|
||||
elif r_dist < 20: # Right side is blocked, left side is free, turn left
|
||||
self.turn(-100, TURN_TIME_FS_90DEG_MS)
|
||||
else: # Both Side are free, randomize a direction
|
||||
right: bool = randint(0, 1)
|
||||
if right:
|
||||
self.turn(100,TURN_TIME_FS_90DEG_MS)
|
||||
self.turn(100, TURN_TIME_FS_90DEG_MS)
|
||||
self.drive(50)
|
||||
time.sleep(3)
|
||||
else:
|
||||
self.turn(-100,TURN_TIME_FS_90DEG_MS)
|
||||
self.turn(-100, TURN_TIME_FS_90DEG_MS)
|
||||
self.drive(50)
|
||||
time.sleep(3)
|
||||
time.sleep(0.5)
|
||||
time.sleep(0.5)
|
||||
|
|
|
@ -5,7 +5,8 @@ from kuukar_config import DHT22_PIN, SONAR_1_ECHO_PIN, SONAR_1_TRIG_PIN, SONAR_2
|
|||
|
||||
class sensors:
|
||||
|
||||
__sonar_trig_pins__ = [SONAR_1_TRIG_PIN, SONAR_2_TRIG_PIN, SONAR_3_TRIG_PIN]
|
||||
__sonar_trig_pins__ = [SONAR_1_TRIG_PIN,
|
||||
SONAR_2_TRIG_PIN, SONAR_3_TRIG_PIN]
|
||||
__sonar_distances__ = [0, 0, 0]
|
||||
__temperature__ = 0
|
||||
__humidity__ = 0
|
||||
|
@ -36,8 +37,8 @@ class sensors:
|
|||
def get_humidity_pct(self) -> float:
|
||||
return self.__humidity__
|
||||
|
||||
def __dht22_callback__(self,data):
|
||||
def __dht22_callback__(self, data):
|
||||
humidity = data[3]
|
||||
temperature = data[4]
|
||||
self.__humidity__ = humidity
|
||||
self.__temperature__ = temperature
|
||||
self.__temperature__ = temperature
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
import threading
|
||||
from time import sleep
|
||||
from kuukar_lcd import lcd
|
||||
from kuukar_leds import leds
|
||||
from kuukar_sensors import sensors
|
||||
|
||||
|
||||
class temperature:
|
||||
def __init__(self, lcd: lcd, leds: leds, sensors: sensors) -> None:
|
||||
self.lcd = lcd
|
||||
self.leds = leds
|
||||
self.sensors = sensors
|
||||
threading.Thread(target=self.temperature_checker).start()
|
||||
|
||||
def temperature_checker(self):
|
||||
while True:
|
||||
sleep(5)
|
Loading…
Reference in New Issue