update code to change driver board to RPi Pico
This commit is contained in:
parent
0395df8d30
commit
767a4c4ad5
11
kuukar.py
11
kuukar.py
|
@ -1,4 +1,11 @@
|
||||||
from telemetrix_rpi_pico import telemetrix_rpi_pico
|
from telemetrix_rpi_pico import telemetrix_rpi_pico
|
||||||
|
import kuukar_leds, kuukar_collision, kuukar_motion, kuukar_lcd, kuukar_sensors
|
||||||
|
|
||||||
|
from kuukar_config import SERIAL_AUX_BOARD, SERIAL_DRIVER_BOARD
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
board = telemetrix_rpi_pico.TelemetrixRpiPico()
|
aux_board = telemetrix_rpi_pico.TelemetrixRpiPico(com_port=SERIAL_AUX_BOARD)
|
||||||
pass
|
driver_board = telemetrix_rpi_pico.TelemetrixRpiPico(com_port=SERIAL_DRIVER_BOARD)
|
||||||
|
sensors = kuukar_sensors.sensors(aux_board,driver_board)
|
||||||
|
leds = kuukar_leds.leds(aux_board=aux_board)
|
||||||
|
lcd = kuukar_lcd.lcd()
|
||||||
|
motion = kuukar_motion.motion(driver_board=driver_board,leds=leds,sensors= sensors)
|
|
@ -1,5 +1,17 @@
|
||||||
|
from telemetrix_rpi_pico import telemetrix_rpi_pico
|
||||||
|
from kuukar_config import COLLISION_DETECTOR_PIN
|
||||||
|
|
||||||
|
from kuukar_lcd import lcd
|
||||||
|
from kuukar_leds import leds
|
||||||
class collision:
|
class collision:
|
||||||
def __init__(self, board) -> None:
|
def __init__(self, aux: telemetrix_rpi_pico.TelemetrixRpiPico, lcd: lcd, leds: leds) -> None:
|
||||||
self.board = board
|
self.aux = aux
|
||||||
def collision_handle(self):
|
self.lcd = lcd
|
||||||
pass
|
self.leds = leds
|
||||||
|
aux.set_pin_mode_digital_input(COLLISION_DETECTOR_PIN, self.collision_handle)
|
||||||
|
|
||||||
|
def collision_handle(self, data):
|
||||||
|
val = data[2]
|
||||||
|
if val == 1:
|
||||||
|
self.leds.flash(r=255,g=0,b=0,duration_ms=250)
|
||||||
|
self.lcd.keke_hurt()
|
|
@ -1,12 +1,15 @@
|
||||||
SERIAL_DRIVER_BOARD = "/dev/serial/by-id/..."
|
SERIAL_DRIVER_BOARD = "/dev/serial/by-id/..."
|
||||||
MOTOR_FL_F = 4
|
MOTOR_FL_F = 6
|
||||||
MOTOR_FL_R = 5
|
MOTOR_FL_R = 7
|
||||||
MOTOR_FR_F = 6
|
MOTOR_FR_F = 8
|
||||||
MOTOR_FR_R = 7
|
MOTOR_FR_R = 9
|
||||||
MOTOR_R_F = 8
|
MOTOR_RL_F = 10
|
||||||
MOTOR_R_R = 9
|
MOTOR_RL_R = 11
|
||||||
|
MOTOR_RR_F = 12
|
||||||
|
MOTOR_RR_R = 13
|
||||||
|
|
||||||
SERIAL_AUX_BOARD = "/dev/serial/by-id/..."
|
SERIAL_AUX_BOARD = "/dev/serial/by-id/..."
|
||||||
COLLISION_DETECTOR_PIN = 2
|
COLLISION_DETECTOR_PIN = 2
|
||||||
LEDS_DATA_PIN = 3
|
LEDS_DATA_PIN = 3
|
||||||
DHT22_PIN = 5
|
DHT22_PIN = 5
|
||||||
|
LEDS_NUM = 15
|
|
@ -1,9 +1,8 @@
|
||||||
from kuukar_lcd import lcd
|
from kuukar_lcd import lcd
|
||||||
from kuukar_leds import leds
|
from kuukar_leds import leds
|
||||||
from kuukar_noise import noise
|
|
||||||
|
|
||||||
class cv:
|
class cv:
|
||||||
def __init__(self, lcd: lcd, leds: leds, noise: noise) -> None:
|
def __init__(self, lcd: lcd, leds: leds) -> None:
|
||||||
self.lcd = lcd
|
self.lcd = lcd
|
||||||
self.leds = leds
|
self.leds = leds
|
||||||
self.noise = noise
|
self.noise = noise
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
|
from telemetrix_rpi_pico import telemetrix_rpi_pico
|
||||||
|
|
||||||
|
from kuukar_config import LEDS_DATA_PIN, LEDS_NUM
|
||||||
class leds:
|
class leds:
|
||||||
def __init__(self, board, led_pin: int) -> None:
|
def __init__(self, aux_board: telemetrix_rpi_pico.TelemetrixRpiPico) -> None:
|
||||||
self.board = board
|
self.aux_board = aux_board
|
||||||
|
self.aux_board.set_pin_mode_neopixel(LEDS_DATA_PIN,LEDS_NUM)
|
||||||
|
|
||||||
|
def flash(r: int,g: int,b: int,duration_ms: int):
|
||||||
|
pass
|
|
@ -1,29 +1,61 @@
|
||||||
from kuukar_config import MOTOR_FL_F, MOTOR_FL_R, MOTOR_FR_F, MOTOR_FR_R, MOTOR_R_F, MOTOR_R_R
|
from kuukar_config import MOTOR_FL_F, MOTOR_FL_R, MOTOR_FR_F, MOTOR_FR_R, MOTOR_RL_F, MOTOR_RL_R, MOTOR_RR_F, MOTOR_RR_R
|
||||||
|
import time
|
||||||
from kuukar_leds import leds
|
from kuukar_leds import leds
|
||||||
from kuukar_sensors import sensors
|
from kuukar_sensors import sensors
|
||||||
from telemetrix import telemetrix
|
from telemetrix_rpi_pico import telemetrix_rpi_pico
|
||||||
|
import threading
|
||||||
|
|
||||||
class motion:
|
class motion:
|
||||||
def __init__(self, driver: telemetrix.Telemetrix, led: leds, sensors: sensors) -> None:
|
|
||||||
self.driver = driver
|
roaming = False
|
||||||
|
|
||||||
|
def __init__(self, driver_board: telemetrix_rpi_pico.TelemetrixRpiPico, leds: leds, sensors: sensors) -> None:
|
||||||
|
self.driver = driver_board
|
||||||
self.leds = leds
|
self.leds = leds
|
||||||
self.sensors = sensors
|
self.sensors = sensors
|
||||||
|
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_R_F,MOTOR_R_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:
|
for drive_pin in drive_pins:
|
||||||
self.driver.set_pin_mode_digital_output(drive_pin)
|
self.driver.set_pin_mode_pwm_output(drive_pin)
|
||||||
|
|
||||||
|
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)
|
||||||
|
elif speed >= 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)
|
||||||
|
|
||||||
|
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)
|
||||||
|
time.sleep(duration)
|
||||||
|
self.stop()
|
||||||
|
|
||||||
def forward(self, speed: int):
|
|
||||||
self.driver.digital_write(MOTOR_FL_F,1)
|
|
||||||
def turn(self, speed: int, angle: float):
|
|
||||||
pass
|
|
||||||
def backward(self, speed: int):
|
|
||||||
pass
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
pass
|
self.drive(0)
|
||||||
|
|
||||||
def roam_start(self):
|
def roam_start(self):
|
||||||
pass
|
self.roaming = True
|
||||||
|
|
||||||
def roam_stop(self):
|
def roam_stop(self):
|
||||||
pass
|
self.roaming = False
|
||||||
def roam_loop(self):
|
|
||||||
|
def __roam_looper__(self):
|
||||||
|
while True:
|
||||||
|
if self.roaming:
|
||||||
|
self.__roam_handle__()
|
||||||
|
|
||||||
|
def __roam_handle__(self):
|
||||||
|
#TODO Implement Roaming Function
|
||||||
pass
|
pass
|
|
@ -1,2 +0,0 @@
|
||||||
class noise():
|
|
||||||
pass
|
|
|
@ -1,4 +1,5 @@
|
||||||
|
from telemetrix_rpi_pico import telemetrix_rpi_pico
|
||||||
class sensors:
|
class sensors:
|
||||||
def __init__(self, board, driver) -> None:
|
def __init__(self, aux_board: telemetrix_rpi_pico.TelemetrixRpiPico, driver_board: telemetrix_rpi_pico.TelemetrixRpiPico) -> None:
|
||||||
self.board = board
|
self.aux = aux_board
|
||||||
self.driver = driver
|
self.driver = driver_board
|
|
@ -2,16 +2,14 @@ import threading
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from kuukar_lcd import lcd
|
from kuukar_lcd import lcd
|
||||||
from kuukar_leds import leds
|
from kuukar_leds import leds
|
||||||
from kuukar_noise import noise
|
|
||||||
from kuukar_sensors import sensors
|
from kuukar_sensors import sensors
|
||||||
|
|
||||||
|
|
||||||
class temperature:
|
class temperature:
|
||||||
def __init__(self, lcd: lcd, leds: leds, sensors: sensors, noise: noise) -> None:
|
def __init__(self, lcd: lcd, leds: leds, sensors: sensors) -> None:
|
||||||
self.lcd = lcd
|
self.lcd = lcd
|
||||||
self.leds = leds
|
self.leds = leds
|
||||||
self.sensors = sensors
|
self.sensors = sensors
|
||||||
self.noise = noise
|
|
||||||
threading.Thread(target=self.temperature_checker).start()
|
threading.Thread(target=self.temperature_checker).start()
|
||||||
|
|
||||||
def temperature_checker(self):
|
def temperature_checker(self):
|
||||||
|
|
|
@ -4,9 +4,8 @@ from kuukar_noise import noise
|
||||||
|
|
||||||
|
|
||||||
class voice:
|
class voice:
|
||||||
def __init__(self, lcd: lcd, leds: leds, noise: noise) -> None:
|
def __init__(self, lcd: lcd, leds: leds) -> None:
|
||||||
self.lcd = lcd
|
self.lcd = lcd
|
||||||
self.leds = leds
|
self.leds = leds
|
||||||
self.noise = noise
|
|
||||||
def handle_voice_prompt(self, command):
|
def handle_voice_prompt(self, command):
|
||||||
pass
|
pass
|
|
@ -1,3 +1,2 @@
|
||||||
telemetrix-rpi-pico
|
telemetrix-rpi-pico
|
||||||
telemetrix
|
|
||||||
pyaudio
|
pyaudio
|
Loading…
Reference in New Issue