Mindstorm NXT 编程循环退出条件

发布于 2024-12-19 03:10:55 字数 341 浏览 1 评论 0原文

我正在为工程课开发一个机器人。为了课程的目的,我需要使用 NXT 编程语言。为了移动,机器人需要沿着一条黑实线移动。

如果机器人失去了线,我让它向左扫描 1 秒,或者直到它到达黑线。如果没有找到线,它会向右扫描 2 秒,以便到达初始位置,然后再扫描 1 秒或实现旋转。

我设置了循环,这样如果没有找到线,机器人就会继续移动。它运行了整整 1 秒的时间段。如果找到该线,运动就会停止,但仍需完成整秒。最终,这意味着我的程序运行完美,但速度真的很慢。

tl;dr 有没有办法在 LEGO Mindstorm 编程环境中制作具有两个退出条件的循环? 1 秒过去后,或者传感器获得所需的输入?

I am developing a robot for an engineering class. For the purposes of the class I am required to use the NXT programming language. To move, the robot needs to follow a solid black line.

If the robot looses the line, I have it scan to the left for 1 second, or until it reaches a black line. If no line is found it scans to the right for 2 seconds so the initial position is reached then 1 more second or rotation is achieved.

I have the loop set up so that if the line has not been found, the robot continues to move. That runs for a full 1 second time period. If the line is found, motion stops, but the full second still has to complete. Ultimately that means that my program works perfectly, but is really really slow.

tl;dr Is there a way to make loops with two exit condition in the LEGO Mindstorm programming environment? Either after 1 second has elapsed, or a sensor gets the desired input?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

唱一曲作罢 2024-12-26 03:10:55

最后两个块是设置为“OR”的逻辑块。在本例中,正在监视 3 个传感器。如果任何一个被触发,程序就会退出循环。

.

这是来自 http://www.hightechkids.org/sites/default/files/CoachingLibrary/fll_programming_101_nxt_g.pdf

The last two blocks are Logic blocks set to "OR". In this case, 3 sensors are being watched. If any one is tripped the program drops out of the loop.

.

This is from page 86 of http://www.hightechkids.org/sites/default/files/CoachingLibrary/fll_programming_101_nxt_g.pdf

戏舞 2024-12-26 03:10:55

您可以做的是缩短超时时间(例如 100 毫秒),并在找到该行或循环运行 10 次时停止。

我不是头脑风暴专家,但我希望它具有 OR 功能。

What you could do is make the timeout shorter (100 ms for instance) and stop if the line is found OR the loop ran 10 times.

I am no mindstorms expert, but I expect it to have an OR function.

小姐丶请自重 2024-12-26 03:10:55

Mindstorms 没有 OR 函数。

解决方案是创建一个 exit 变量,然后有两个 switch 语句。在上面的示例中,我有一个带有计时器的 switch 语句,另一个带有传感器输出。将退出变量设置为 false,然后在 while 循环内运行,直到退出变量为 true。

如果计时器到期,则将该变量设置为 true,否则忽略退出变量。对传感器的输出执行相同的操作。

这是一个混乱且相当长的解决方案,但它在相当有限的乐高 Mindstorms 系统中完美地解决了问题。

Mindstorms does not have an OR function.

The solution is to create an exit variable, then have two switch statements. In the example above, I had one switch statement with a timer, and the other with the sensor output. Set the exit variable to false, then inside a while loop, run until the exit variable is true.

If the timer expires, set the variable to true, otherwise ignore the exit variable. Do the same with the sensor's output.

This is a messy and rather long solution, but it solves the problem perfectly within the rather limited LEGO Mindstorms system.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文