首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当我的机器人驶过一个黑带,大声说出4号之后,我该如何阻止它呢?

当我的机器人驶过一个黑带,大声说出4号之后,我该如何阻止它呢?
EN

Stack Overflow用户
提问于 2022-04-26 03:57:11
回答 1查看 242关注 0票数 1
代码语言:javascript
复制
%%sim_magic_preloaded --background Coloured_bands -R
# Program to count the bands aloud

# Start the robot moving
tank_drive.on(SpeedPercent(15), SpeedPercent(15))

# Initial count value
count = 0

# Initial sensor reading
previous_value = colorLeft.reflected_light_intensity_pc

# Create a loop
while True:

    # Check current sensor reading
    current_value = colorLeft.reflected_light_intensity_pc

    # Test when the robot has entered a band
    if previous_value==100 and current_value < 100:
        # When on a new band:
        # - increase the count
        count = count + 1
        # - display the count in the output window
        print(count)
        # - say the count aloud
        say(str(count))

    # Update previous sensor reading
    previous_value = current_value

需要一些帮助在这个编码,我试图让机器人停下来后,它超过了黑带,这是第四波段,而且它也没有说出响亮的数字4,一旦它超过了黑带

EN

回答 1

Stack Overflow用户

发布于 2022-04-26 05:17:51

代码语言:javascript
复制
import time

previous_value = colorLeft.color

tank_drive.on(SpeedPercent(15), SpeedPercent(15))

count = 1

while True:
    current_value = colorLeft.color
    print(current_value)

    if previous_value==6 and current_value != 6:
        print(count)
        say(str(count))

        count += 1

    #Now it should stop at band 4
    if count > 4 and current_value==6:
        time.sleep(1)
        tank_drive.off()
        break

    previous_value = current_value
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72008200

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档