【问题标题】:Rasperry pi reboots when running program运行程序时树莓派重启
【发布时间】:2016-07-06 01:36:26
【问题描述】:

当我使用以下代码运行以下代码时,我的树莓派会重新启动:sudo python robot.py 我的树莓派通过机器人控制器(Robohat)连接到 4 个电机、一个平移和倾斜组件以及一个超声波传感器。

import robohat, time, random
dist_l = 0
dist_r = 0
speed = 80
pan = 1
tilt = 0
tVal = 25 # 20 degrees is centre
pVal = 20 # 25 degrees is centre

robohat.init()
def doServos():# Set servo to wanted degrees
    robohat.setServo(pan, pVal)
    robohat.setServo(tilt, tVal)

end = "False"
while end == "False":

   def dist_check(): #gets distance
        pVal = 20
        tVal = 25
    doServos() #Centre the servos       
def servoPosGo():
    pVal2 = (90)
    robohat.setServo(pan, pVal2)
    robohat.setServo(tilt, tVal)
    dist_l = robohat.getDistance()
servoPosGo()
#Take right reading at 90 degrees


def servoPosGo2():
    pVal3 = (-60)
    robohat.setServo(pan, pVal3)
    robohat.setServo(tilt, tVal)
    dist_r = robohat.getDistance()
servoPosGo2()

doServos() #Centres the servos
dist_check()
if dist_r < 100 or dist_l < 100: #Is the distance greater than 100, and go which is greater but less than 100
    if dist_l > dist_r:
        robohat.spinLeft(speed)
        robohat.forward(speed)
        time.sleep(dist_l - 10)
        robohat.stop()
    elif dist_r > dist_l:
        robohat.spinRight(speed)
        robohat.forward(speed)
        time.sleep(dist_r - 10)
        robohat.stop()
    elif dist_l == dist_r: #If the two distnaces are the same, choose a   random one
        ran = random.randrange(1, 2)
        if ran == (1):
            robohat.spinLeft(speed)
            robohat.forward(speed)
            time.sleep(dist_l - 10)
            robohat.stop()
        elif ran = (2):
            robohat.spinRight(speed)
            robohat.forward(speed)
            time.sleep(dist_r - 10)
            robohat.stop()
elif dist_l > 100 or dist_r > 100: #If distance IS greater than 100, go forward and set end to true
    end = "True"
    robohat.forward(speed)
     if dist_r > dist_l:
        time.sleep(dist_r - 10)
     elif dist_l > dist_r:
        time.sleep(dist_l - 10)

【问题讨论】:

  • 你用什么来给你的树莓供电?访问外部电机和/或传感器所消耗的能量可能超过您的源所能提供的能量,从而导致重新启动,因为您的 Raspberry 没有获得足够的能量一秒钟。
  • 电源故障可能导致重启。它会在没有连接任何设备的情况下重新启动吗?
  • 看起来您的 dist_check 函数从未定义过。你所拥有的只有 dist_check(),但绝不会定义 dist_check()。

标签: python raspberry-pi raspbian


【解决方案1】:

为您的 RPi 提供更强大的交流适配器。它应该至少有 1.2 A。

另外,请确保您的伺服系统不是由 RPi 供电,接地必须相同,并且只有伺服命令行连接到 RPi 引脚。还有一个事实是,RPi 向其 GPIO 提供 3.5V 输出,而大多数伺服系统在电源和 cmd 线上需要 5V。尽管它们中的一些可以在 cmd 行上的较低电压下正常工作。

如果您没有将电机直接连接到 GPIO,则必须重新检查接地等。

有时会有助于在电源输入上添加大电容,这样突然的瞬变不会使您的 RPi 受到冲击而重新启动。

【讨论】:

    猜你喜欢
    • 2022-12-05
    • 2016-03-16
    • 2017-04-22
    • 1970-01-01
    • 1970-01-01
    • 2021-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多