ObstacleRL.py 文件源码

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

项目:RaspberryPi-Robot 作者: timestocome 项目源码 文件源码
def get_state(sleep_time=wheel_pulse):

    # clear trigger sensor
    gpio.output(trigger, False)
    time.sleep(sleep_time)

    # send trigger pulse
    gpio.output(trigger, True)
    time.sleep(0.00001)
    gpio.output(trigger, False)

    while gpio.input(echo) == 0:
        pulse_start = time.time()

    while gpio.input(echo) == 1:
        pulse_end = time.time()


    pulse_duration = pulse_end - pulse_start
    distance = pulse_duration * 343 * 100 / 2.  # speed of sound m/s * m to cm / round trip

    if distance > 2 and distance < 400:         # sensor range
        distance = distance + distance_from_sensor_to_car_front

    # don't worry about things further 4'
    # this also reduces the size of the state machine
    if distance >= max_distance:    
        distance = max_distance - 1

    return int(distance)





##############################################################################
# perform action
##############################################################################
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号