Robotics C++ Physics II AP Physics B Electronics Java Astronomy Other Courses Summer Session  

 

Robot Soccer

Compass Sensor, IR Emitting Ball, IR Detector, Ultrasonic Sensor, Light Sensor

 

Description and Construction  
Part 1  
Part 2  

 

 

 

Description and Construction

 

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.

 

What does the Compass Sensor Do?

The HiTechnic Compass Sensor contains 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.


 

Building a Compass Sensor on 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.

 


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 the picture to the left, you can see the compass sensor is mounted high, well above both the motors and computer brick.


PART 1

 

Construct the following program. The program lets you see the compass reading on your NXT’s screen.

 

Set up the compass control block (left of the three blocks above) to look like this:

 

The “Number to Text” block (middle of the three blocks above) should look like this:

 

The Display block (the rightmost of the three blocks in the NXT-G diagram on the previous page) should be adjusted to look like this:

 

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?

 

Introduction to Part 2

 

How does the compass Block Work?

Suppose you used the above program, 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 the one below.

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

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

 

PART 2

 

Using the Compass block in a Soccer Program.

Use the above program to find compass headings for the two edges of your opponent’s goal. Write them down. 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 below. Note that, any of the sensor slots 1, 2, 3 or 4 can be used.

 

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

 

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.

Soccer Strategy

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? Hints.

 

·  Check if you are out of bounds (marked with black tape) – if you are out of bounds try to return to the soccer field (turn around, go forward, and repeat this until

     you are inside 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)