【问题标题】:BrickPi motors rev but don't move robotBrickPi 电机转速但不移动机器人
【发布时间】:2015-01-28 11:21:44
【问题描述】:

我在 Raspberry Pi 上玩 BrickPi。

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

该库的文档没有帮助。

我该如何进行这项工作?

【问题讨论】:

    标签: python raspberry-pi raspbian


    【解决方案1】:

    但它只是加速了一秒钟然后立即停止......我已经设置了电机并在代码中的其他地方分配了。速度设置为 200。

    看起来这应该全速运行,然后停止。 The BrickPi 固件具有安全功能,如果每隔几秒钟没有收到来自 Raspberry Pi 的消息,它会关闭电机。您可能希望将代码更改为以下内容:

    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 的代码示例。

    希望这会有所帮助!

    【讨论】:

    • 非常好,很高兴我们能提供帮助!
    猜你喜欢
    • 2011-07-17
    • 2021-05-07
    • 2017-08-18
    • 1970-01-01
    • 2017-11-28
    • 2020-08-20
    • 1970-01-01
    • 1970-01-01
    • 2022-11-02
    相关资源
    最近更新 更多