lite mode
This commit is contained in:
parent
3766284cde
commit
26b353762c
1
app.py
1
app.py
|
@ -21,7 +21,6 @@ from kuukar.kuukar import kuukar
|
|||
# collision = kuukar_collision.collision(mcu, lcd, leds)
|
||||
|
||||
car = kuukar()
|
||||
|
||||
while True:
|
||||
temp = car.sensors.get_temperature()
|
||||
humid = car.sensors.get_humidity_pct()
|
||||
|
|
|
@ -12,9 +12,7 @@ class kuukar:
|
|||
def __init__(self) -> None:
|
||||
self.mcu = telemetrix_rpi_pico.TelemetrixRpiPico(
|
||||
com_port=SERIAL_MCU, sleep_tune=0.001)
|
||||
self.drv = telemetrix_rpi_pico.TelemetrixRpiPico(
|
||||
com_port=SERIAL_DRV, sleep_tune=0.001)
|
||||
self.sensors = kuukar_sensors.sensors(self.mcu, self.drv)
|
||||
self.sensors = kuukar_sensors.sensors(self.mcu)
|
||||
self.leds = kuukar_leds.leds(self.mcu)
|
||||
self.motion = kuukar_motion.motion(
|
||||
self.mcu, self.drv, self.leds, self.sensors)
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
SERIAL_MCU = "/dev/serial/by-id/usb-Raspberry_Pi_Pico_E660B4400771212A-if00"
|
||||
SERIAL_DRV = "/dev/serial/by-id/usb-Raspberry_Pi_Pico_E6609CB2D3846033-if00"
|
||||
SERIAL_MCU = "/dev/serial/by-id/usb-Raspberry_Pi_Pico_E6609CB2D3846033-if00"
|
||||
SERIAL_LCD = "/dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0"
|
||||
|
||||
# HC Sonar Pins
|
||||
SONAR_1_ADC_PIN = 0
|
||||
SONAR_2_ADC_PIN = 1
|
||||
SONAR_3_ADC_PIN = 2
|
||||
# Sonar Pin
|
||||
SONAR_ADC_PIN = 1
|
||||
|
||||
|
||||
# Motor Pins
|
||||
MOTOR_FL_F = 7
|
||||
|
@ -20,8 +18,6 @@ MOTOR_RR_R = 12
|
|||
# Full Speed 90 Degrees Turn Time
|
||||
TURN_TIME_FS_90DEG_MS = 3000.0
|
||||
|
||||
BEEPER_PIN = 15
|
||||
|
||||
COLLISION_DETECTOR_PIN = 16
|
||||
COLLISION_ENABLE = True
|
||||
|
||||
|
@ -32,6 +28,6 @@ LEFT_SIGNAL_LEDS = [4, 5, 6, 7]
|
|||
RIGHT_SIGNAL_LEDS = [0, 1, 14, 15]
|
||||
REVERSE_LEDS = [11, 10, 9]
|
||||
|
||||
LIGHT_SENSOR_PIN = 2
|
||||
LIGHT_SENSOR_PIN = 0
|
||||
|
||||
DHT22_PIN = 14
|
||||
DHT22_PIN = 0
|
||||
|
|
|
@ -114,40 +114,6 @@ class motion:
|
|||
time.sleep(0.3)
|
||||
|
||||
def __roam_handle(self):
|
||||
sensitivity = 35
|
||||
turn_speed = 40
|
||||
drive_speed = 25
|
||||
|
||||
f_dist = self.sensors.sonar_get_distance(1)
|
||||
if 0 < f_dist < sensitivity: # Close to collision, turn the vehicle
|
||||
print("collision")
|
||||
self.drive(-drive_speed)
|
||||
time.sleep(0.75)
|
||||
self.stop()
|
||||
l_dist = self.sensors.sonar_get_distance(0)
|
||||
r_dist = self.sensors.sonar_get_distance(2)
|
||||
if l_dist < sensitivity: # Left side is blocked
|
||||
if r_dist < sensitivity: # Both side are blocked, do a full 180deg turn
|
||||
print("full turn")
|
||||
self.turn(30, 2)
|
||||
self.drive(23)
|
||||
else:
|
||||
# Right Side is Free, turn right
|
||||
print("right turn")
|
||||
self.turn(turn_speed, 1)
|
||||
self.drive(drive_speed)
|
||||
elif r_dist < sensitivity: # Right side is blocked, left side is free, turn left
|
||||
print("right left")
|
||||
self.turn(-turn_speed, 1)
|
||||
self.drive(drive_speed)
|
||||
else: # Both Side are free, randomize a direction
|
||||
print("turn random")
|
||||
right: bool = randint(0, 1)
|
||||
if right:
|
||||
self.turn(turn_speed, 1)
|
||||
self.drive(drive_speed)
|
||||
else:
|
||||
self.turn(-turn_speed, 1)
|
||||
self.drive(drive_speed)
|
||||
time.sleep(1)
|
||||
if not self.roaming:
|
||||
self.stop()
|
|
@ -1,32 +1,25 @@
|
|||
from telemetrix_rpi_pico import telemetrix_rpi_pico
|
||||
from kuukar.kuukar_config import DHT22_PIN, SONAR_1_ADC_PIN, SONAR_2_ADC_PIN, SONAR_3_ADC_PIN, LIGHT_SENSOR_PIN
|
||||
from kuukar.kuukar_config import DHT22_PIN, SONAR_ADC_PIN, LIGHT_SENSOR_PIN
|
||||
|
||||
|
||||
class sensors:
|
||||
__sonar_adc_pins = [SONAR_1_ADC_PIN,
|
||||
SONAR_2_ADC_PIN, SONAR_3_ADC_PIN]
|
||||
__sonar_distances = [0, 0, 0]
|
||||
__sonar_distances = 0
|
||||
__temperature = 0
|
||||
__humidity = 0
|
||||
__brightness = 0
|
||||
|
||||
def __init__(self, mcu: telemetrix_rpi_pico.TelemetrixRpiPico, drv: telemetrix_rpi_pico.TelemetrixRpiPico) -> None:
|
||||
def __init__(self, mcu: telemetrix_rpi_pico.TelemetrixRpiPico) -> None:
|
||||
self.mcu = mcu
|
||||
self.drv = drv
|
||||
self.drv.set_pin_mode_analog_input(SONAR_1_ADC_PIN, 100, self.__sonar_callback)
|
||||
self.drv.set_pin_mode_analog_input(SONAR_2_ADC_PIN, 100, self.__sonar_callback)
|
||||
self.drv.set_pin_mode_analog_input(SONAR_3_ADC_PIN, 100, self.__sonar_callback)
|
||||
self.mcu.set_pin_mode_dht(DHT22_PIN, self.__dht22_callback)
|
||||
self.drv.set_pin_mode_analog_input(LIGHT_SENSOR_PIN, 0, self.__light_sensor_callback)
|
||||
self.mcu.set_pin_mode_analog_input(SONAR_ADC_PIN, 100, self.__sonar_callback)
|
||||
self.mcu.set_pin_mode_dht(DHT22_PIN, self.__dht22_callback)
|
||||
self.mcu.set_pin_mode_analog_input(LIGHT_SENSOR_PIN, 0, self.__light_sensor_callback)
|
||||
|
||||
def sonar_get_distance(self, id: int) -> float:
|
||||
return self.__sonar_distances[id]
|
||||
def sonar_get_distance(self) -> float:
|
||||
return self.__sonar_distances
|
||||
|
||||
def __sonar_callback(self, data):
|
||||
pin = data[1]
|
||||
distance = data[2]
|
||||
sonar_id = self.__sonar_adc_pins.index(pin)
|
||||
self.__sonar_distances[sonar_id] = distance
|
||||
self.__sonar_distances = distance
|
||||
|
||||
def get_brightness_pct(self) -> float:
|
||||
return self.__brightness
|
||||
|
|
Loading…
Reference in New Issue