obstacle_detection.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:dronestorm 作者: Stanford-BIS 项目源码 文件源码
def measureDistance_HCSRO4(TRIG_ID, ECHO_ID):
    GPIO.output(TRIG_ID, True)
    time.sleep(0.00001)
    GPIO.output(TRIG_ID, False)

    edge_detect = GPIO.wait_for_edge(ECHO_ID, GPIO.RISING, timeout = 100)

    if edge_detect is not None:
        pulse_start = time.time()
    else: return MAX_DIST

    edge_detect = GPIO.wait_for_edge(ECHO_ID, GPIO.FALLING, timeout = 100)

    if edge_detect is not None:
        pulse_end = time.time()
    else: return MAX_DIST

    pulse_duration = pulse_end - pulse_start
    distance = round(pulse_duration * 17150, 2)

    return distance
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号