remove reference to drv in motion

This commit is contained in:
Siwat Sirichai 2022-12-08 21:39:18 +07:00
parent ff5ff14bb9
commit dbfdd546ea
2 changed files with 7 additions and 8 deletions

View File

@ -15,7 +15,7 @@ class kuukar:
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)
self.mcu, self.leds, self.sensors)
self.lcd = kuukar_lcd.lcd(self.motion, self.sensors)
self.environment = kuukar_environment.environment(
self.lcd, self.leds, self.sensors)

View File

@ -11,9 +11,8 @@ class motion:
roaming = False
def __init__(self, mcu: telemetrix_rpi_pico.TelemetrixRpiPico, drv: telemetrix_rpi_pico.TelemetrixRpiPico, leds: leds, sensors: sensors) -> None:
def __init__(self, mcu: telemetrix_rpi_pico.TelemetrixRpiPico, leds: leds, sensors: sensors) -> None:
self.mcu = mcu
self.drv = drv
self.leds = leds
self.sensors = sensors
self.roam_thread = threading.Thread(target=self.__roam_looper)
@ -22,15 +21,15 @@ class motion:
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.drv.set_pin_mode_pwm_output(drive_pin)
self.mcu.set_pin_mode_pwm_output(drive_pin)
def motor_write(self, forward_pin: int, reverse_pin: int, speed: int):
if speed < 0:
self.drv.pwm_write(forward_pin, 0)
self.drv.pwm_write(reverse_pin, -int(speed))
self.mcu.pwm_write(forward_pin, 0)
self.mcu.pwm_write(reverse_pin, -int(speed))
elif speed >= 0:
self.drv.pwm_write(forward_pin, int(speed))
self.drv.pwm_write(reverse_pin, 0)
self.mcu.pwm_write(forward_pin, int(speed))
self.mcu.pwm_write(reverse_pin, 0)
def drive(self, speed: int):
self.motor_write(MOTOR_FL_F, MOTOR_FL_R, speed)