Sensors perceive the environment and send data to the robot.
传感器感知环境并将数据发送到机器人。
The sensors are connected to the robot via ports 1 to 4. Small icons at the top of the program show the current values.
传感器通过端口 1 到 4 连接到机器人。程序顶部的小图标显示当前值。
The motors are connected to ports A to D. They contain rotation sensors and display the current angular position:
电机连接到端口 A 到 D。它们包含旋转传感器并显示当前的角度位置:
The touch sensor can be used on robot to detect physical touch. It can be mounted as a bumper or an antenna.
触摸传感器可用于机器人以检测物理触摸。它可以作为保险杠或天线安装。
We program it to say something when the touch sensor is pressed.
我们对其进行编程,使其在按下触摸传感器时说出一些内容。
But we can also program it to do something when it is released.
但我们也可以对它进行编程,使其在发布时执行某些作。
When the color sensors sees red or green it pronounces these colors
当颜色传感器看到红色或绿色时,它会读出这些颜色
Now let’s use a different method. We will continously measure the distance and display it. For this we will use the forever loop.
现在让我们使用不同的方法。我们将不断测量距离并显示它。为此,我们将使用 forever 循环。
On line 3 we write once the explanation distance sensor. Inside the loop, we write continously the value measured with the disance sensor.
在第 3 行,我们写了一次解释 distance sensor。在循环中,我们连续写入使用位移传感器测得的值。
As we have seen in the beginning, all the motors have a rotation sensor built-in. We can use the wheels as input knobs and display the values.
正如我们在一开始所看到的,所有电机都内置了旋转传感器。我们可以将轮子用作输入旋钮并显示值。
If you look carefully, you notice the values are positive to one side, negative to the other. At the start of the program, the value is always 0.
如果您仔细观察,您会注意到这些值对一侧为正值,对另一侧为负值。在程序开始时,该值始终为 0。
Do you notice a problem? Let’s say you go up to:
您是否注意到问题?假设您上升到:
100
This occupies 3 characters. Once written, the caracters are not erased when the number becomes smaller. If you return back to 99 the display will now show 990. And when you’re back at 9 the display will now show:
这占用 3 个字符。写入后,当数字变小时,不会擦除 caracters。如果返回到 99,显示屏现在将显示 990。当你回到 9 点时,显示屏现在将显示:
900
There is a trick to correct this. The green operator join allows you to attach a couple of empty spaces after the number. These will erase any extra digits.
有一个技巧可以纠正这个问题。绿色运算符 join 允许您在数字后附加几个空白处。这些将擦除任何多余的数字。
We even can do better. We can add a unit after the number. Take care to add 1 space before and 4-5 spaces afterwards. Your string shoud look like this: _degrees____.
我们甚至可以做得更好。我们可以在数字后添加一个单位。注意在前面添加 1 个空格,在后面添加 4-5 个空格。你的字符串应该看起来像这样:_degrees____。