update code to change driver board to RPi Pico

This commit is contained in:
Siwat Sirichai 2022-10-25 14:49:19 +07:00
parent 0395df8d30
commit 767a4c4ad5
12 changed files with 98 additions and 43 deletions

View File

@ -1,4 +1,11 @@
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__':
board = telemetrix_rpi_pico.TelemetrixRpiPico()
pass
aux_board = telemetrix_rpi_pico.TelemetrixRpiPico(com_port=SERIAL_AUX_BOARD)
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)

View File

@ -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:
def __init__(self, board) -> None:
self.board = board
def collision_handle(self):
pass
def __init__(self, aux: telemetrix_rpi_pico.TelemetrixRpiPico, lcd: lcd, leds: leds) -> None:
self.aux = aux
self.lcd = lcd
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()

View File

@ -1,12 +1,15 @@
SERIAL_DRIVER_BOARD = "/dev/serial/by-id/..."
MOTOR_FL_F = 4
MOTOR_FL_R = 5
MOTOR_FR_F = 6
MOTOR_FR_R = 7
MOTOR_R_F = 8
MOTOR_R_R = 9
MOTOR_FL_F = 6
MOTOR_FL_R = 7
MOTOR_FR_F = 8
MOTOR_FR_R = 9
MOTOR_RL_F = 10
MOTOR_RL_R = 11
MOTOR_RR_F = 12
MOTOR_RR_R = 13
SERIAL_AUX_BOARD = "/dev/serial/by-id/..."
COLLISION_DETECTOR_PIN = 2
LEDS_DATA_PIN = 3
DHT22_PIN = 5
LEDS_NUM = 15

View File

@ -1,9 +1,8 @@
from kuukar_lcd import lcd
from kuukar_leds import leds
from kuukar_noise import noise
class cv:
def __init__(self, lcd: lcd, leds: leds, noise: noise) -> None:
def __init__(self, lcd: lcd, leds: leds) -> None:
self.lcd = lcd
self.leds = leds
self.noise = noise

View File

@ -1,3 +1,10 @@
from telemetrix_rpi_pico import telemetrix_rpi_pico
from kuukar_config import LEDS_DATA_PIN, LEDS_NUM
class leds:
def __init__(self, board, led_pin: int) -> None:
self.board = board
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)
def flash(r: int,g: int,b: int,duration_ms: int):
pass

View File

@ -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_sensors import sensors
from telemetrix import telemetrix
from telemetrix_rpi_pico import telemetrix_rpi_pico
import threading
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.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:
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):
pass
self.drive(0)
def roam_start(self):
pass
self.roaming = True
def roam_stop(self):
pass
def roam_loop(self):
self.roaming = False
def __roam_looper__(self):
while True:
if self.roaming:
self.__roam_handle__()
def __roam_handle__(self):
#TODO Implement Roaming Function
pass

0
kuukar_nextion.py Normal file
View File

View File

@ -1,2 +0,0 @@
class noise():
pass

View File

@ -1,4 +1,5 @@
from telemetrix_rpi_pico import telemetrix_rpi_pico
class sensors:
def __init__(self, board, driver) -> None:
self.board = board
self.driver = driver
def __init__(self, aux_board: telemetrix_rpi_pico.TelemetrixRpiPico, driver_board: telemetrix_rpi_pico.TelemetrixRpiPico) -> None:
self.aux = aux_board
self.driver = driver_board

View File

@ -2,16 +2,14 @@ import threading
from time import sleep
from kuukar_lcd import lcd
from kuukar_leds import leds
from kuukar_noise import noise
from kuukar_sensors import sensors
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.leds = leds
self.sensors = sensors
self.noise = noise
threading.Thread(target=self.temperature_checker).start()
def temperature_checker(self):

View File

@ -4,9 +4,8 @@ from kuukar_noise import noise
class voice:
def __init__(self, lcd: lcd, leds: leds, noise: noise) -> None:
def __init__(self, lcd: lcd, leds: leds) -> None:
self.lcd = lcd
self.leds = leds
self.noise = noise
def handle_voice_prompt(self, command):
pass

View File

@ -1,3 +1,2 @@
telemetrix-rpi-pico
telemetrix
pyaudio