Time to turn

LEGO Robotics - Lesson 2

Objectives

  • Write algorithms to control the movements of a robot
  • Debug algorithms to solve problems 
  • Understand different types of turn and program a robot to perform them.

Lesson Resources


Lesson 1 - Measure and move

Lesson 2 - Time to turn

Lesson 3 - Get in shape

Lesson 4 - Lifting and moving

Lesson 5 - Sensors

Lesson 6 - Sensors and Robot challenges

Introduction

Begin by recapping the last lesson and in particular the properties that were available for changing the movement of the robot and the way that they were able to calculate the number of rotations needed to move precise distances.

What different movements could we achieve with just one block? How did you work out how many rotations to use to travel a particular distance?

  1. Measure the distance.
  2. Divide the distance of the line by 17.4*
  3. Program the robot to move that many rotations.

 

This lesson is about turning and improving their understanding of getting the robot to perform different types of movement.  

 

Turning

The EV3 robot can perform several types of turn, but ask the  students, how does it actually turn when the wheels are always fixed in a forward direction? Establish that by only moving one wheel or by moving the two wheels at different speeds the robot will turn - one wheel will overtake the other and propel that side of the robot forward faster, causing a turn. 

The two main turns they need to know about are pivot and spin turns. Show the students the images below which demonstrate the difference. Discuss how the robot achieves each turn.

 

Pivot turns

With a pivot turn only one wheel turns. When the robot performs a 180 degree turn it will end up to the left or right of its original position. The axis of the turn is through the centre of whichever wheel remains still. 

 

 

A pivot turn can work well for going around an object 

 

 

Spin turns

With a spin turn, both wheels turn. One turns forwards while the other turns backwards. This creates a turn on the spot.  The axis of the turn is through the centre of the robot. 

 

Images courtesy of EV3lessons.com

 

Spin turns are great for tighter turns where there isn’t space to swing the robot round and where you want the centre of the robot to stay on a predetermined path. 

 

 

The steering values needed for both types of turn are as follows:

PIVOT turn left (-50)

 

 

PIVOT turn right (50)

SPIN turn left (-100)

 

SPIN turn right (100)

 

Give the students time to try both types of turn out. Emphasise that's important that they only use the values above in the steering variable. In all cases, it is the number of rotations that will control how far the robot turns. Small rotation number = small angle of turn or vice versa. Using small and decimal numbers can be important for this to work well. A value less than 1 is usually needed. 

 

Follow the line

For this next task we will focus on using ONLY spin turns. Stick two pieces of masking tape to the floor to create an angle a bit like this.

 

 

Position the centre of the robot over the start of the tape. We want it to drive along the line and stop at the end. Ask the class, how can we solve this problem?

There are three steps to the solution: move > turn > move.

 

Step 1

Measure the first piece of tape from its start to the centre of the angle. Calculate how many rotations will be needed to travel this distance (divide the distance by 17.4) or use a divide operator block to do it for you.

 

Step 2

Emphasise that we are going to use a spin turn as we want to turn on the spot and remain on the tape. This means the turning value should always be -100 (left) or 100 (right) when performing a spin turn. Again, the rotation value will dictate how long the turn lasts and therefore the angle turned. The rotations value will always be between 0.1 and 1 as 1 will perform slightly more than a 180 degree (half) turn, and all these angles will be smaller than that. 

Try 0.5 rotations to begin with and test this out. Ask the students to suggest adjustments for this value until the turn is accurate.

 

Step 3

Repeat step 1 for the second length of tape.

 

Your code should look a little bit like this (the length and rotation values will vary):

 

 

Add a selection of acute and obtuse angles around the room using masking tape and ask the students to replicate the process you demonstrated with the class. Remind them to:

  • position the centre of the robot over the start of the tape
  • consider if it's a left or right turn
  • stick to spin turns (-100 or 100 for steering)

 

Square dance

Set the students the following problem. Can you extend your code to make your robot move in a perfect square that has sides of 1 metre? The robot must also start and stop in the same place.

 

 

Ask the class for ideas and suggestions how they might do this. How many movements (and programming blocks) will it need? 

We can break the problem down (decompose) into the following eight steps, we call this pseudocode - putting the instructions in order, in our own words:

  • Move forward 
  • Turn at a right angle
  • Move forward
  • Turn at a right angle
  • Move forward
  • Turn at a right angle
  • Move forward
  • Turn at a right angle

It's actually two instructions repeated four times. In coding we call this repetition, iteration or a loop.

They should hopefully notice that first two movements are the same concept as the previous challenge:

  1. Move in a straight line for a specific distance
  2. Perform a spin turn at the end of the line.

But what is the most efficient way to program this in EV3 Classroom? 

Loops are available in the orange Control section. There are different types of loop, such as an infinite 'forever' loop, but in this case we want a counted loop:

 

 

Change the count number to 4 and then ask the students to add two movement blocks inside the loop to create the straight sides of the square and the right angle corners, using a SPIN turn. It might look a bit like this (some numbers may need adjusting):

 

 

Plenary

Ask some of the groups to demonstrate their square programs and explain the code and settings they used. Check if they are aware which setting in each block controls each of the movements.

Ask the class:

  • What have we learned about controlling our robots today?
  • What is the difference between a pivot and spin turn?
  • When might each one be useful? 
  • What have we done to try and be as precise as possible with our robots' movements?

< Previous Lesson

Next Lesson >