Defend the goal – use a seeker sensor to detect the ball.
What the goalie robot needs to do: Scan for the ball, left then right in front of the goal. When it see the ball in front it pushes out quickly, then moves back into the goal.
To code the robot you need to see what the sensor on the robot is "seeing".
Use the ‘Port View’ menu on the EV3 brick to read the sensor values. You should be able to see the values from the infrared sensor in the Port it is plugged into.
The EV3 Seeking Coding may help with coding the goalie robot.
Part 1: Let's Find the Ball with the IR Seeker sensor
We will use the IRSeeker to locate the ball. The IRseeker consists of 5 individual sensors, inside the curved face, that give us readings of where the ball is located. The IRSeeker direction values are shown (diagram right) with 1 indicating the infrared target is left and behind, 5 if the target is directly ahead and 9 if the target is to the right and behind. A value of 0 is returned if no signal is detected.
Choose "Port View". Turn on the infrared ball and move it around the sensor. The infrared sensor will show a value of between 1 to 9, depending on what angle the ball is located, relative to the sensor. A reading of 0 means that the sensor cannot see the ball. I.e., a value of 5 means the ball is straight ahead. A value of 2 means the ball is to the left of the sensor.
When programming, it is suggested that the IR sensor follows the ball in front with a reading of 4, 5 and 6. Then, if it is < 4, it will turn left and > 6, turn right.
There is no specific block for the HiTechnic infrared sensor or HiTechnic compass sensor. Instead, we use the Ultrasonic Blocks as a substitute. This can be a little confusing as the code will talk about "distances" when using the IR sensor, whereas we are talking about the block reading a number between 0 and 9.