Note: We have had requests for these tutorials to be made available in Mandarin - this is a dual Chinese/English test translation to see how practical this would be. We'd appreciate your opinions in either English or Simplified Chinese calligraphy to Graeme@postoffice.utas.edu.au  - thanks in advance!

Compasses and Robot Soccer

In Robot Soccer it is useful for your robot to be able to tell the direction to both your goal and your opponent’s goal. A compass can help your robot do this.

There are two kinds of compass available for your NXT robot, Wiltronics compasses and HiTechnic compasses. We will use the latter, as LEGO has approved them for use with the NXT robots.

在机器人足球比赛中, 机器人要明确己方和对方的球门位置。 罗盘能帮助确认位置。

NXT机器人中有两种类型罗盘,Wiltronic罗盘和HITechnic高科罗盘。我们选用后者是因为LEGO公司已将它用在NXT机器人中。

1.         What does a HiTechnic Compass Sensor Do?

The HiTechnic Compass Sensor Figure 1contains a digital magnetic compass that measures the earth’s magnetic field and calculates a compass bearing to the nearest 1° . It can report a compass bearing to an NXT robot 100 times per second.

高科罗盘Figure 1有何作用?

高科罗盘内设电子磁铁罗盘用于测试地球磁场和计算方位, 其角度误差为1. 它能以每秒100次的频率将测算结果传送给NXT计器人。

 

Figure 1

2.         Building a HiTechnic Compass Sensor on to your Robot.

The HiTechnic compass sensor will only operate correctly in a horizontal position, so you must keep the compass level for it to read correctly. This is very important. Please remember this when you building the compass sensor into your robot.

 

Figure 2

 It is also highly desirable to mount the compass at least 15 cm. (6 inches) away from the motors and 10 cm. (4 inches) away from the NXT computer brick itself. This is necessary because both the NXT computer brick and NXT motors produce magnetic fields that can change the compass sensor readings. 

In Figure 2, you can see the compass sensor is mounted high, well above both the motors and computer brick.

 如何在机器人上安装高科罗盘?

要保证计算精确度,必须确保高科罗盘的水平安装, 这一点极为重要。

高科罗盘高度至少为15厘米,即离马达6英寸或10厘米, NXT小电脑4英寸。 这些参考值至关重要, 因为马达和NXT小电脑在工作时会射放磁场从而干扰高科罗盘的精确运算。

Figure 2所示,高科罗盘的安装远远高出马达和NXT小电脑位置。

3.         Using the HiTechnic Compass Sensor with NXT-G

To use the compass sensor from NXT-G, an additional piece of software needs to have been added to your computer. To see if your copy of the NXT-G software has been upgraded, start up NXT-G, start up a program, & check the menu. Does it contain a  option? If it does, you can use a compass with your robot. If it does not, it will be necessary for you to arrange that your software be upgraded before you can use the compass sensor.

If your copy of NXT-G has been upgraded, construct the following program in Figure 3. The program aims to let you see the compass reading on your NXT’s screen.

 NXT-G运用高科罗盘

NXT-G运用高科罗盘还需要在电脑下载一个附加软件。要检验你的NXT-G是否已更新,只需启动nxt-g 打开程序,    菜单。若界面显示     则表明你能用高科罗盘。 反之, 则表明你必须首先下载指定附加软件才能继续。

若你的nxt-g 已更新, 则编写Figure3 所示程序。 这一程序的作用是在NXT 小电脑显示屏上阅读高科罗盘的测算结果。

 

Figure 3

Set up the compass control block (left of the three blocks in Figure 3) to look like Figure 4:

Figure 4所示设置高科罗盘控制参数。点击Figure3 中左面版块显示Figure 4

 

Figure 4

The “Number to Text” control block (middle of the three blocks in Figure 3) should look like Figure 5:

数字到文字控制界面 - (点击Figure3 版块显示Figure 5

 

Figure 5

The Display block (the rightmost of the three blocks in Figure 3) should be adjusted to look like Figure 6:

屏显控制界面(点击Figure3 中右面版块显示Figure 6)须选择下面参数。

 

Figure 6

Now when you download this program to your NXT and run it, you will see a number displayed on your NXT’s small computer screen; this number (between zero and 360⁰) is the compass heading.

Move your robot around, and notice how the reading changes. Experiment and see if the reading changes when the compass sensor is tilted one way or another. Do you have to be quite careful to keep the sensor horizontal, or does this not matter?

 完成这些参数选定后将它们下载到NXT的小电脑里, 你就能在它的小电脑屏上读到数字。0°-360°即表明高科罗盘的测算范围。

移动机器人, 检查测量值是否有变。试一下将高科罗盘上扬或下俯, 同时观察其测量值的相应变化。现在你该相信高科罗盘的水平安装的重要性了吧,还是你仍然觉得无关紧要?

 4.         Which is the direction of your opponent’s Soccer goal?

How does the Compass Control Block Work?

Suppose you used the program shown in Figure 3, and found out that the compass directions of the two edges of your opponent’s goal were 90 and 100 degrees. Now also suppose that the compass control block in your program was set up like Figure 7.

 对方球队的球门在哪?

高科罗盘控制如何工作?

假设你作了Figure 3 的参数设置,看到对方球门的两边角度分别为90°100° 同时假设你在高科罗盘控制里设figure 7所示参数。

Figure 7

If your robot was in a game and saw the compass readings of either 90 degrees, or 100 degrees, the compass control block would behave as in Table 1:

如果你的足球机器人在比赛, 看到高科罗盘显示90°或者100°那么高科罗盘控制会显示如Table1 1 所示行为:

 Table 1

A

B

Range

Absolute

Reading

Compass Block True or False?

85

95

Inside Range

90

True

85

95

Inside Range

100

False

85

95

Outside Range

90

False

85

95

Outside Range

100

True

Using the Compass control block in your Soccer Program.

 Use the program in Figure 3 to find out the compass headings for the two edges of your opponent’s goal. Write them down so you don’t forget them. Now if you used the “Inside Range” option in your program to see if your robot is pointed at your opponent’s goal, you could then program your robot similarly to the program in Figure 8 and Figure 9. Note that, while in this program it is assumed that the compass is connected to sensor slot 1, any of the sensor slots 1, 2, 3 or 4 can be used.

在足球比赛中使用高科罗盘控制

使用本文3.0所示程序来确定对方球门的两边参数。 用笔记下以免遗忘。 现在你将机器人对着球门,如果你是使用”Inside Range”参数,你可拷贝Figure 8 and Figure 9图示编程 注意Figure9图中示意用感应器接口1 其实1,2,3,4 接口任选一个都行。

Figure 8

A compass sensor control block like Figure 9 below would tell your robot to obey the top line of your program if the compass reading is inside the range 90 to 180.

如果罗盘所读的数值在90°180°之间, 类似Figure 9 高科罗盘控制参数会让你的机器人使用Figure 8 中上面的程序。

Figure 9

In the example program above, the top line of the program would tell the robot to go forward if it is facing in the direction of your opponent’s goal (that is, if the compass reading is inside the range 90 to 180 degrees). If the robot is not pointing at the opponent’s goal, (that is, the compass reading is outside the range of 90 to 180 degrees) it will spin around looking for your opponent’s goal.

在上述举例中, 上半部程序指示你的机器人前行, 它面向对方球门时用 罗盘所读的数值在90度至180度之间)。如果你的机器人不面向对方球门 (既罗盘所读的数值在90度至180度之外) 则机器人会转身寻找对方球门。

5.         Soccer Strategy for GEN II Soccer

The program above is one way to program your soccer robot. But is this the only way to arrange your soccer program? Is there a better way to use the compass sensor in your soccer program? What should you do if the ball is between your robot and your opponent’s goal – charge at it? What should you do if the ball is between your robot and your own goal – should you charge at it or do something different? In a 2007 GEN II soccer workshop in Tasmania, Mr. Brian Thomas gave the following hints:

Check if you are out of bounds (the mat under you is white) – if you are out of bounds try to return to the soccer field (turn around, go forward, and repeat this until the mat under you is not white and you are back in the soccer field).

Find the soccer ball (spin around until you see the soccer ball, but be careful, too fast a spin and you may miss it).

Go to a good place to kick the ball towards your opponent’s goal (if the soccer ball is between you and your own goal, travel to the other side of the soccer ball so that the soccer ball is between you and your opponent’s goal).

Go to the soccer ball (go fast towards the soccer ball, trying to reach it before your opponent’s robot)

 

上述举例是一种足球机器人编程方式。它是唯一的方式吗?是否还有其他方法更有效地使用罗盘?当球的位置在你和对方球门之间, 你该怎么办?直冲过去?当球的位置在你和你自己的球门之间, 你又该怎么办?直冲过去还是另有高招?在塔斯马尼亚2007 GEN II 机器人足球研讨会上, Brian Thomas 先生给了如下提示:

检查你是否出线 (你的阅读显示地毯呈白色) - 如果你出线了, 则回到线内(回转身,前行, 重复这些直到你的阅读显示地毯不是白色, 你已回到比赛区内。

寻找足球(不停转身直到找到足球, 但切记转身速度不要太快, 否则容易错过足球)。

走到一个好的位置才射门(当球的位置在你和你自己的球门之间,则走到足球的另一边, 那样

球的位置就在你和对方球门之间了)。

逼近足球 (速度要快, 赶在对方球员之前劲射)。

Good luck - enjoy your Robot Soccer!

祝你好运 机器人足球乐无穷!

 Free tutorial on HiTechnic Compass Sensor and Robot Soccer - English and Mandarin - copyright Dr. Graeme Faulkner 2010 - www.DrGraeme.net