Can't kill main.py? #11266
Unanswered
FlydGitHub
asked this question in
RP2040 / Pico
Can't kill main.py?
#11266
Replies: 1 comment
-
Solved - disconnect motors |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have code that is runng maim.py now I an stuck as I can't kill main.py. Any comments?
import machine, time, utime, gc
from motor import Motor
from encoder import Encoder
class LineFollower:
def init(self, ir_pin1, ir_pin2, right_motor, left_motor):
self.ir1 = machine.Pin(ir_pin1, machine.Pin.IN, machine.Pin.PULL_UP)
self.ir2 = machine.Pin(ir_pin2, machine.Pin.IN, machine.Pin.PULL_UP)
self.right_motor = right_motor
self.left_motor = left_motor
class Robot:
def init(self, motor_pins, encoder_pins, ir_pins):
self.right_motor = Motor(*motor_pins[0])
self.left_motor = Motor(*motor_pins[1])
self.right_encoder = Encoder(encoder_pins[0], "Right")
self.left_encoder = Encoder(encoder_pins[1], "Left", self.right_encoder)
self.right_encoder.other_encoder = self.left_encoder
self.line_follower = LineFollower(ir_pins[0], ir_pins[1], self.right_motor, self.left_motor)
motor_pins = [(12, 26), (18, 16)]
encoder_pins = [10, 7]
ir_pins = [14, 15]
robot = Robot(motor_pins, encoder_pins, ir_pins)
with open("MotorsLog.txt", "w") as file:
robot.right_encoder.enable_interrupt(file)
robot.left_encoder.enable_interrupt(file)
gc.collect()
Start line following
robot.follow_line(speed=40, duration=1)
robot.stop()
END
motor.py
import machine
class Motor:
def init(self, pin1, pin2, freq=20000):
self.pwm = machine.PWM(machine.Pin(pin1))
self.pwm.freq(freq)
self.direction = machine.Pin(pin2, machine.Pin.OUT)
END
encoder.py
import machine, _thread, utime
class Encoder:
def init(self, pin, label, other_encoder=None):
self.pin = machine.Pin(pin, machine.Pin.IN, machine.Pin.PULL_UP)
self.label = label
self.count = 0
self.lock = _thread.allocate_lock()
self.other_encoder = other_encoder
Beta Was this translation helpful? Give feedback.
All reactions