Robot Educator

The education version of the Lego EV3 software proposes various example programs in a sequence called ‘Robot Educator’. You can see those programs and my commentaries HERE. You can also see HERE how the same problems can be solved in EV3 Python, if you're interested.

Let’s see how to get the same functionality using EV3 Basic. Let’s not forget that EV3 Basic can also do other kinds of program that the Lego software is incapable of doing. And above all, let’s not forget that the main reason to use EV3 Basic is that it is the simplest way to do textual programming on the EV3, and learning textual programming is a much better preparation for a career in programming than learning Lego’s non-standard icon-based programming system. As for all exercises on this site, it is assumed that you are using the official ‘Lego ‘Driving Base’ model, or something very similar, with motors attached to ports B and C. The 'Driving Base' model is also called the 'Educator Vehicle'. Building instructions for making the Driving Base model from the education version of the EV3 kit can be viewed or downloaded HERE. Building instructions for making the Driving Base model from the home (retail) version of the EV3 kit can be viewed HERE. The program solutions below can be copied into Small Basic so that you can test them, if you wish.

Further down this page you can find the 'Basics' exercises. Once you have completed them, follow these links for the 'Hardware' and 'Beyond Basics' exercises:

BASICS

Lesson 1 of the official Lego lesson sequence is about configuring blocks and is not relevant to EV3 Basic and therefore not discussed here.

Lesson 2: Straight Move

Objective:

EV3 Basic solution:

Motor.Move ("BC", 50, 720, "True")

Program.Delay(1000)

Motor.Move ("BC", -50, 720, "True")

Program.Delay(1000)

Motor.Start("BC", 50)

Program.Delay(1000)

Motor.Stop("BC","True")

For comparison, here is the solution as it appears within the standard Lego icon-based programming environment:

You can find the Lego solutions to the other challenges HERE.

Notes:

Lesson 3: Curved Move

Objective:

Solution:

To make two motors move simultaneously with different speeds, such as when following a curved path or turning on the spot, the best option is to use the command Motor.MoveSync(ports, speed1, speed2, degrees, brake).

Note that this function causes program execution to pause until the movement completes.

Motor.MoveSync("BC", 50, -50, 685, "True")

Program.Delay(1000)

Motor.Move ("B", 40, 1380, "True")

Program.Delay(1000)

Motor.MoveSync("BC", 50, 25, 720, "True")

Notes:

Lesson 4: Tank Move

Objective:

The intended movement in the official Lego lesson 4 is exactly the same as in lesson 3 above, so the solution has already been given. In the Lego lessons, the difference is that lesson 3 is to be achieved using the 'Move Steering' block while lesson 4 is to be solved using the 'Move Tank' block. EV3 Basic always uses the 'Move Tank' approach, specifying the speed that each wheel should have, but the two approaches are equivalent and it is not very difficult to figure out the speed settings that correspond to a certain 'steering value'.

Lesson 5: Move Object

Objective:

This program uses the medium motor to lower the robot's gripper bar, trapping an object, then it does a medium left turn backwards, pulling the object with it, then it raises the gripper bar. EV3 Basic makes no distinction between the large and medium motors - they should both work fine. It is assumed that the medium motor is attached to port A.

Solution:

Motor.Move ("A", -30, 100, "True")

Motor.Move ("B", -50, 360, "True")

Motor.Move ("A", 30, 100, "True")

Notes:

Lesson 6: Stop at line

Objective:

This exercise assumes that a colour sensor is attached to port 3 and is suspended just above the ground, pointing at the ground. This program turns on the right motor (making the robot turn left), then waits until the detected brightness falls below a certain value (because the sensor has passed over a black line, for example) then turns off the motor.

Solution:

Motor.Start("C", 30)

While Sensor.ReadPercent(3)>50

Endwhile

Motor.Stop("C", "True")

Notes:

Lesson 7: Stop at Angle

This exercise uses the gyro sensor, which is assumed to be connected to port 2. Note that the gyro sensor is included in the education version of the EV3 but not in the home version, so if you have the home version you will not be able to test this program (it's always possible to buy additional sensors). In mode 0 the gyro sensor measures the angle in which it is pointing, relative to the angle that is was at when the program was launched. It's very important to keep the Gyro Sensor and EV3 steady when connecting the cable and during start-up of the EV3, otherwise the gyro reading will continually wander away from the correct value. If you are not sure that this condition was met then simply unplug the sensor from port 2 and then reconnect it before running the program, while ensuring that the EV3 and the gyro sensor are perfectly still.

Objective:

Solution:

'Connect gyro sensor to port 2

Sensor.SetMode(2,0) 'set port 2 to mode 0: measure angle in degrees

Motor.Start("B", 40)

While Sensor.ReadRawValue(2,0) < 45

EndWhile

Motor.Move ("BC", 50, 360, "True") 'advance 360° (one revolution)

Lesson 8: Stop at Object

This project will use the ultrasound sensor, which is assumed for this exercise to be on port 4. If you don't have the ultrasound sensor (because you bought the home edition of the EV3) you could perhaps substitute the IR sensor but it won't be possible to get exact distances because the IR sensor does not return exact distances. Also, the code will be different if you use the IR sensor because with the ultrasound sensor Sensor.ReadRaw is used and with IR sensor (in mode 0: distance) Sensor.ReadPercent is used. This difference means other small changes need to be made to the code. See note 2 for a solution using the infrared sensor.

Objective:

The robot will move forward in a straight line (speed=50) until it has moved (at least) 11 cm closer to the reflecting object in front of it, then it will stop and pause for one second, then it will back up continuously (speed=-50) until it detects that it has moved (at least) 6 cm away from the object, then it will stop. (Note that if the robot moves 11 cm closer and then 6 cm further away it will then be 5 cm from its starting position.)

Solution (using the ultrasound sensor):

First we need to ensure that the sensor is in mode 0: measure distance in mm (not cm). To obtain the distance reading from the ultrasound sensor, Sensor.ReadRawValue(port number, 0) should be used.

'Connect ultrasonic sensor to port 4

Sensor.SetMode(4,0) 'set port 4 to mode 0: distance in mm

StartDistance = Sensor.ReadRawValue(4,0) 'Distance in mm

Motor.Start("BC", 50)

While Sensor.ReadRawValue(4,0) > (StartDistance - 110) '11cm=110mm

EndWhile

Motor.Stop("BC", "True")

Program.Delay(1000)

Motor.Start("BC", -50) 'reverse with speed= -50

While Sensor.ReadRawValue(4,0) < (StartDistance - 50) '5cm=50mm

EndWhile

Motor.Stop("BC", "True")

Notes:

'Connect infrared sensor on port 4

Sensor.SetMode(4,0) 'set port 4 to mode 0: distance in cm

StartDistance = Sensor.ReadPercent(4) 'Returns distance in cm

Motor.Start("BC", 50) 'Move forward at speed 50

While Sensor.ReadPercent(4)>(StartDistance-11)

'robot hasn't yet moved 11cm closer

EndWhile

Motor.Stop("BC", "True") 'Brake on

Program.Delay(1000) ' pause 1 second

Motor.Start("BC", -50) 'reverse with speed= -50

While Sensor.ReadPercent(4)<(StartDistance-5)

'robot hasn't yet moved 6cm further away

EndWhile

Motor.Stop("BC", "True")

Now that you have complete the 'Basics' exercises you are ready to tackle the 18 'Beyond Basics' exercises which begin with Beyond Basics exercises 1-6.