EV3 Ball seeker basic
Although EV3 can be used as a striker robot the Spike Prime robots with sensors work much better.
Although EV3 can be used as a striker robot the Spike Prime robots with sensors work much better.
To code the Seeker robot you need to see what the sensors on the robot are "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 Port 2, and the compass sensor in Port 4.
Run through each of the Ball Seeker Programs (basic, nested and improved) so that you understand the programming steps:
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 2 in "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.
Set motors to B & C and check IR sensor is plugged into Port 2.
As there is no specific block for the Infrared Sensor, use the Ultrasonic Block instead.
We are now going to make the robot follow the infrared (IR) ball.
Our robot is going to do four things:
1. If the IR sensor returns a value of 0, it means the robot cannot see the ball. The robot spins (at half-speed) on the spot until it can find the ball.
2. If the IR sensor returns a value of 5, our robot will go straight ahead.
3. If the IR sensor returns a value of 1 to 4, our robot will turn left.
4. If the IR sensor returns a value of 6 to 9, our robot will turn right.
This program includes a conditional that tells a program to run different actions depending on whether a condition is true or false, uisng "if - else" statements.
Once you have this working with the robot following the ball, go to the next page to "nest" your commands.
Set motors to B & C and check IR sensor is plugged into Port 2.
A Nested Event places one or more objects within another object ( like a loop within a loop).
This program will include a conditional statement that tells a program to run different actions depending on whether a condition is true or false, uisng "if - else" statements. Simplifying the program in this way will allow the program to run more smoothly.
Our robot is going to do four things:
1. If the IR sensor returns a value of 5, our robot will go straight ahead.
2. Else, if the IR sensor returns a value of 0, it means the robot cannot see the ball. The robot spins (at half-speed) on the spot until it can find the ball.
3. Else, if the IR sensor returns a value of 1 to 4, our robot will turn left.
4. Else, our robot will turn right.
Once you have this working smoothly, go to the next page to adjust the "forward" program.
Set motors to B & C and check IR sensor is plugged into Port 2.
This program is identical to the previous "Seeker nested program" other than the IR sensor will be changed to test for a reading of 4, 5 or 6 which will indicate the ball is in front.
Our robot is going to do four things:
1. If the IR sensor returns a value between 3 and 7 (4, 5 or 6) our robot will go straight ahead.
2. Else, if the IR sensor returns a value of 0, it means the robot cannot see the ball. The robot spins (at half-speed) on the spot until it can find the ball.
3. Else, if the IR sensor returns a value of 1 to 3, our robot will turn left.
4. Else, our robot will turn right.
Next: Now the robot successfully follows the ball we now need to program the Compass Sensor so we can direct the robot to the correct goal.