我在玩覆盆子馅饼。在
我用Python控制一个四轮驱动的机器人。默认程序允许您实时控制它。但我试图创建一个程序,通过使用以下代码为机器人提供一个设定的路径,即move forwards 3 seconds then stop
:
def fwd():
BrickPi.MotorSpeed[fl] = speed
BrickPi.MotorSpeed[fr] = speed
BrickPi.MotorSpeed[bl] = -speed
BrickPi.MotorSpeed[br] = -speed
BrickPiUpdateValues()
def stop():
BrickPi.MotorSpeed[fl] = 0
BrickPi.MotorSpeed[fr] = 0
BrickPi.MotorSpeed[bl] = 0
BrickPi.MotorSpeed[br] = 0
BrickPiUpdateValues()
fwd()
time.sleep(4)
stop()
但它只是加速一秒钟然后立刻停止。。。 我已经在代码的其他地方设置和分配了马达。速度设置为200。在
图书馆的文件没用。在
我该怎么做?在
看起来这应该是全速运转,然后停止。The BrickPi固件有一个安全功能,如果每隔几秒钟没有收到树莓派的声音,它就会关闭电机。您可能需要将代码更改为如下所示:
第四行的循环每100毫秒调用一次代码(更新BrickPi),并使电机保持运行。在
您可以看到running LEGO Mindstorms motors with the Raspberry Pi here的代码示例。在
希望这有帮助!在
相关问题 更多 >
编程相关推荐