NXT-G编程:自定义模块与数学基础
1. 自定义模块(My Block)的概念与价值
在NXT - G编程中,并没有名为“My Block”的实际模块。My Block是用户自己创建的,它是一组NXT - G模块的集合,方便用户重复使用。
1.1 示例程序与问题
假设有一个让机器人SPOT按正方形路径移动并回到起点的程序,伪代码如下:
Me: SPOT, move forward three rotations and then turn left 90 degrees.
Me: SPOT, move forward another three rotations and then turn left 90 degrees.
Me: SPOT, move forward another three rotations and then turn left 90 degrees.
Me: SPOT, move forward another three rotations and then turn left 90 degrees.
这个程序可以用简单的MOVE模块实现,也可以将前两个MOVE模块放在一个循环四次的LOOP模块中。但如果后续需要在第二次左转后让SPOT读取光传感器数据,修改程序就会变得复杂。对于简单的程序,直接插入光传感器模块即可;但对于使用LOOP模块的程序,需要修改第一个LOOP模块的循环次数,插入光传感器模块,再创建第二个LOOP模块。
1.2 My Block的优势
通过创建My Bl
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



