Loading...

Robotics_Week_3.8
Key Stage 2
Year 5
Computing
Now you're going to create a line following algorithm, which is a set of rules to keep your buggy on the track. Each of the sensors has two states, when it does detect a line and when it does not detect a line. What do you reckon should happen when this sensor on the left does detect a line? <v ->And it should turn left?</v> <v ->Yeah, it should. </v> And when the sensor on the right detects a line, it should then turn right. <v ->Okay. </v> <v ->How about when neither the sensor detects a line?</v> <v ->I'm not sure, will it stop? Will it go forward?</v> <v ->So in this state, we should actually have</v> the motors going forward. So the buggy carries on going forward, assuming that the line is in the middle. <v ->Okay. </v> <v ->Okay until one</v> of the states changes and it detects a line. <v ->Right. Okay. </v> <v ->You can see that we've recreated those rules</v> now in our Python code. So when the left sensor is over the line, we turn left. When the right sensor is over the line, we turn right. And when the left sensor and the right sensor don't detect a line, we move forwards. <v ->Okay. </v> <v ->Now that we're happy with the codes,</v> we can create a track and test that the programme works. Yes. Okay, let's do it. <v ->We're going to use white paper</v> and black tape to create really high contrast between the white surface and the black line. That way it's easier for the line sensors to pick up when it's over a line or when it's over the white surface. If we make a sort of curvy line, that way we can test if the- <v ->If it goes. </v> <v ->Robots. </v> <v ->Yep. </v> <v ->Yeah tries to follow it. </v> <v ->Okay. </v> <v ->If you cut short bits of tape off,</v> what we'll do is we'll start to make a curve in the line as it goes around the paper, <v ->Down the middle, or?</v> <v ->Yeah if you do,</v> right this, the start of the piece of paper. Now that our track's ready, we're gonna test whether the programme works. If you place the robot onto the track, what you want is the bull caster right in the middle of the line. That way the sensors shouldn't be detecting a line and it should start by moving forwards. <v ->Okay. </v> <v ->Do you wanna try running the programme see what happens?</v> <v ->Let's do it. </v> (epic music) Oh, it works. (buggy thudding) Oops. We should probably get the buggy to stop. <v ->Oh, okay yes. And how can we do that?</v> <v ->So we will add in a sleep command first. </v> <v Participant>Okay and that goes at the end of the code. </v> <v ->Yep, so we can tell out how long</v> that we want the programme to run for. <v ->Okay. </v> <v ->So we're gonna choose three seconds</v> 'cause our track is actually really short and then we can tell the robot to stop. That will stop the motors. And we can actually close all of the connections for the motor controller and for both sensors. Should we give it another go? <v ->Yes. Let's do it. </v> <v ->Oh, there it's. </v> <v ->Still in one piece, luckily. </v> <v ->Okay. Fingers crossed. </v> (buggy whirring) Ooh, yay. Stopped. <v ->How are you getting on?</v> Can you think of any improvements? Did the line following algorithm? Let us know in the comments. <v ->You can even share a video of your line following robot. </v> We would love to see it in action.
Robotics_Week_3.8
Key Stage 2
Year 5
Computing
Now you're going to create a line following algorithm, which is a set of rules to keep your buggy on the track. Each of the sensors has two states, when it does detect a line and when it does not detect a line. What do you reckon should happen when this sensor on the left does detect a line? <v ->And it should turn left?</v> <v ->Yeah, it should. </v> And when the sensor on the right detects a line, it should then turn right. <v ->Okay. </v> <v ->How about when neither the sensor detects a line?</v> <v ->I'm not sure, will it stop? Will it go forward?</v> <v ->So in this state, we should actually have</v> the motors going forward. So the buggy carries on going forward, assuming that the line is in the middle. <v ->Okay. </v> <v ->Okay until one</v> of the states changes and it detects a line. <v ->Right. Okay. </v> <v ->You can see that we've recreated those rules</v> now in our Python code. So when the left sensor is over the line, we turn left. When the right sensor is over the line, we turn right. And when the left sensor and the right sensor don't detect a line, we move forwards. <v ->Okay. </v> <v ->Now that we're happy with the codes,</v> we can create a track and test that the programme works. Yes. Okay, let's do it. <v ->We're going to use white paper</v> and black tape to create really high contrast between the white surface and the black line. That way it's easier for the line sensors to pick up when it's over a line or when it's over the white surface. If we make a sort of curvy line, that way we can test if the- <v ->If it goes. </v> <v ->Robots. </v> <v ->Yep. </v> <v ->Yeah tries to follow it. </v> <v ->Okay. </v> <v ->If you cut short bits of tape off,</v> what we'll do is we'll start to make a curve in the line as it goes around the paper, <v ->Down the middle, or?</v> <v ->Yeah if you do,</v> right this, the start of the piece of paper. Now that our track's ready, we're gonna test whether the programme works. If you place the robot onto the track, what you want is the bull caster right in the middle of the line. That way the sensors shouldn't be detecting a line and it should start by moving forwards. <v ->Okay. </v> <v ->Do you wanna try running the programme see what happens?</v> <v ->Let's do it. </v> (epic music) Oh, it works. (buggy thudding) Oops. We should probably get the buggy to stop. <v ->Oh, okay yes. And how can we do that?</v> <v ->So we will add in a sleep command first. </v> <v Participant>Okay and that goes at the end of the code. </v> <v ->Yep, so we can tell out how long</v> that we want the programme to run for. <v ->Okay. </v> <v ->So we're gonna choose three seconds</v> 'cause our track is actually really short and then we can tell the robot to stop. That will stop the motors. And we can actually close all of the connections for the motor controller and for both sensors. Should we give it another go? <v ->Yes. Let's do it. </v> <v ->Oh, there it's. </v> <v ->Still in one piece, luckily. </v> <v ->Okay. Fingers crossed. </v> (buggy whirring) Ooh, yay. Stopped. <v ->How are you getting on?</v> Can you think of any improvements? Did the line following algorithm? Let us know in the comments. <v ->You can even share a video of your line following robot. </v> We would love to see it in action.