This is the EV3 unit we shall use for training in the basics of programming.
You can choose to either attempt each mission before referring to the solution or, if you are confident enough in your understanding just use these as programming guides.
The solutions given are the simplest, therefore, they have plenty of room for improvement.
Using only the drive motors, produce a program to make Johnny move forward in a straight line.
Programming Details: You should make sure the motors are at 100% power and the program only runs for 5 seconds.
The first stage with any programming is to think about what steps will need to be taken.
In this case there is a single step to take - Turning both the motors forward at 100% power for 5 seconds
Where does human error come into play here?
Can you think of why this program may not produce a perfect straight line with this robot (excluding the human error mentioned above)?
Using only the drive motors, produce a program to make Johnny move in a square and return to his starting position.
Programming details:
Move forward 4 rotations
Turn 90°
Move forward 4 rotations
Turn 90°
Move forward 4 rotations
Turn 90°
Move forward 4 rotations
Turn 90°
This shows we are repeating the same two instructions 4 times meaning we could use a loop with just these two commands set to run four times.
Why do you think the turning values for Johnny may differ from those of other robot designs using the same kit and motors?
If we ran this program on an identically built robot, it would not be guaranteed to work. Why might this be?
Let's add some sound effects to indicate the start and the end of the program produced in Mission Two.
Choose start sound effect
Insert into start of program
Choose end sound effect
Insert at the end of the program
How could you use sound effects or other additions to help with determining if a program is working correctly? Have a look at the sort of sounds available for clues.
Please note - This is not yet possible with the Microsoft MakeCode Software.
Get Johnny to detect an InfraRed beacon and move towards it.
Programming details: The beacon is set to channel 3 and we want Johnny to stop just before he hits the beacon
Detect beacon
Move towards
Stop before hitting it
To help with determining how to set the beacon detection and movement, we need to know more about how the InfraRed sensor measures the beacon's heading.
The values of the beacon heading are between -25 (left) and 25 (right).
The problem is that all the values between could refer to in front or behind of the sensor.
Image from 'The Lego Mindstorms EV3 Discovery Book' by Laurens Valk
So, if the beacon heading value is negative the robot needs to turn left, if the value is positive it needs to turn right.
Why have we not just set the switch to 'if 0 move forward, if not turn'?
What would have happened if we didn't instruct Johnny to stop when near the beacon?
Looking at how Johnny is built, why can we not use a threshold value between 0 and 5 for stopping?
Produce a program that will have Johnny following a line using the colour sensor mounted at the front.
Programming details: The line he will be following is white. The start position will have the colour sensor directly over the start of the line.
Constantly scan for the colour detected and check if it's white.
If not white need to adjust course to find the line again.
Put in a forever loop to keep it running, as no end point set.
It may help to review how we moved the robot in mission four as a similar principle is used here, just with a differen sensor input.
How could we use sounds to test line detection in the program?
Why would this program fail if the speed was increased too far?
Why would this program fail if the white line took a very tight turn to the left?
If a red taped line was put across the end of the white line how would you change the program to stop at this point?
Program Johnny to navigate a maze using his InfraRed sensor.
Programming details:
Move forward until the IR sensor detects a wall
Turn on the spot 90°
Check for a wall
If no wall it should move forward and repeat
If it detected a wall it needs to turn 180° in the other direction before moving forward and repeating
Why would this program not work if the maze involved dead-ends?
Why would it be better practice to write a program that wasn't just designed to navigate this maze of right-angled turns?