BrickPi motors rev但不要移动rob

2024-04-28 13:07:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我在玩覆盆子馅饼。在

我用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。在

图书馆的文件没用。在

我该怎么做?在


Tags: 代码br程序覆盆子def机器人frstop
1条回答
网友
1楼 · 发布于 2024-04-28 13:07:38

But it just revs up for like a second then instantly stops... I have the motors setup and assigned elsewhere in the code. And speed is set to 200.

看起来这应该是全速运转,然后停止。The BrickPi固件有一个安全功能,如果每隔几秒钟没有收到树莓派的声音,它就会关闭电机。您可能需要将代码更改为如下所示:

fwd()
ot = time.time()
while(time.time() - ot < 4):    #running while loop for 3 seconds
    BrickPiUpdateValues()       # Ask BrickPi to update values for sensors/motors
    time.sleep(.1)
stop()

第四行的循环每100毫秒调用一次代码(更新BrickPi),并使电机保持运行。在

您可以看到running LEGO Mindstorms motors with the Raspberry Pi here的代码示例。在

希望这有帮助!在

相关问题 更多 >