Lesson 5
Last lesson we learned how to move forwards. However you may have a few questions:
Why do the motors start at the same time even though the B motor block comes first?
What we must remember as programmers is that everything happens at computer speed. That means because we only asked it to turn on a motor, it was able to do it quickly and move on in the program. Think about how much time it takes for you to turn on a light. It takes a second to flick a switch. That is all the robot is doing. It is flicking the on switch to the motor and then moving on. But it does this at a computer speed which is many times faster than us.
Why didn't we add another wait block for the C motor?
This is because of when we started the motors. Starting the motors happens so quick that they are moving at the same time. The robot starts them milliseconds apart because it is moving at computer time. Milliseconds isn't noticeable so they move at the same time and that means the rotation sensors would see the same thing at the same time. So waiting on the C motor isn't necessary since it will be at 360 when B motor is. This also means we could have waited for C motor instead of B motor and it still would have worked.
Finally, there is still an issue with our program. Grab a ruler. Moving 360 with the educator bot is approximately 17.5cm. Mark a starting point, run the robot, and then measure from the starting point to the end point. It should be greater than 17.5cm. This is because of that invisible stop block again. Remember how it stopped the motors earlier? well it stops the motors by setting them to coast. Coast is the option that will shut off power to the motor but won't stop it on its spot. So when the robot reaches 360 it is not stopped there, instead it is rolling past 360. We need accuracy so we have to be able to stop it at 360 exactly. Any ideas?
We actually don't need a new block for this, we have one that works already. The motor block has the capability of stopping motors as well. Instead of setting it to forwards or backwards, we can set it to stop. Grab two motor blocks, one for B and the other for C. Set both of their directions to stop and next action to Brake. Make sure you have placed them after the wait block so we will stop after we reach 360. Now try the program.
You'll notice now the robot stops quickly. Try measuring the start and end points again. It should be 17.5cm give or take a millimetre. Now you should have the program below.
Why do the motors start at the same time even though the B motor block comes first?
What we must remember as programmers is that everything happens at computer speed. That means because we only asked it to turn on a motor, it was able to do it quickly and move on in the program. Think about how much time it takes for you to turn on a light. It takes a second to flick a switch. That is all the robot is doing. It is flicking the on switch to the motor and then moving on. But it does this at a computer speed which is many times faster than us.
Why didn't we add another wait block for the C motor?
This is because of when we started the motors. Starting the motors happens so quick that they are moving at the same time. The robot starts them milliseconds apart because it is moving at computer time. Milliseconds isn't noticeable so they move at the same time and that means the rotation sensors would see the same thing at the same time. So waiting on the C motor isn't necessary since it will be at 360 when B motor is. This also means we could have waited for C motor instead of B motor and it still would have worked.
Finally, there is still an issue with our program. Grab a ruler. Moving 360 with the educator bot is approximately 17.5cm. Mark a starting point, run the robot, and then measure from the starting point to the end point. It should be greater than 17.5cm. This is because of that invisible stop block again. Remember how it stopped the motors earlier? well it stops the motors by setting them to coast. Coast is the option that will shut off power to the motor but won't stop it on its spot. So when the robot reaches 360 it is not stopped there, instead it is rolling past 360. We need accuracy so we have to be able to stop it at 360 exactly. Any ideas?
We actually don't need a new block for this, we have one that works already. The motor block has the capability of stopping motors as well. Instead of setting it to forwards or backwards, we can set it to stop. Grab two motor blocks, one for B and the other for C. Set both of their directions to stop and next action to Brake. Make sure you have placed them after the wait block so we will stop after we reach 360. Now try the program.
You'll notice now the robot stops quickly. Try measuring the start and end points again. It should be 17.5cm give or take a millimetre. Now you should have the program below.
This program is simple and very useful. We will probably need it again in the future. Can you remember how to write it? Try rewriting is from scratch.
Good, but there is a way to reuse this program without rewriting it every time.
Good, but there is a way to reuse this program without rewriting it every time.
Let's make a My Block of this program. Select all five block and turn them into a My Block. Name it forward360 and put a gear on it so we can remember what it does.
Your homework for this lesson is to make your robot move 1080 degrees forwards using only our My Block. Try it out now.
Seems there is a problem.
Seems there is a problem.