【发布时间】:2023-01-03 22:52:13
【问题描述】:
我正在尝试在一个线程上运行 balance() 函数并在另一个线程上使用 Timer。这两种方法单独运行时都可以正常工作,但是当我尝试同时使用它们时,定时器调用的 issr() 函数在几次调用后就停止工作。 Raspberry 的 REPL 没有错误。 motor.do_step() 方法只是在调用时将 Pin 值从 0 更改为 1。任何想法是什么问题?
def issr(timer):
global motor1, motor2, i
motor1.do_step()
motor2.do_step()
def balance():
while True:
global motor1, motor2
motor1.set_speed(1000)
motor2.set_speed(1000)
_thread.start_new_thread(balance, ())
tim = Timer()
tim.init(freq=3000, mode=Timer.PERIODIC, callback=issr)
【问题讨论】:
-
你应该将你的
global语句从while循环中移开,并有一些睡眠平衡功能 -
我遇到了类似的问题。我刚刚在 MicroPython 论坛 Timer gets stuck when thread is running - RP2040 上发布了一个简单的问题。到目前为止,没有解决办法。
标签: micropython stepper raspberry-pi-pico rp2040