LEsson 6
So it seems when you put three forwards 360 blocks together and run the program, the robot only drove one 360 forwards. Why is this? To understand this problem, let's try to think like a robot.
We know the first My Block works fine. It turns on the motors, waits to reach 360 degrees, and then stops. That part of the program works. But the other blocks are the same so it should work the same too right? Let's keep going.
The second My Block turns on the motors, waits to reach 360 degrees, and then stops. Consider this, what number is the rotation sensor at when it reaches that second wait block?
At that time the rotation sensor would be at 360 degrees so the robot would ask "Am I at 360 degrees yet?" and immediately get a yes from the rotation sensor. So in a few milliseconds after the motors are started, they are stopped. The wait block is basically doing nothing because the robot is already at 360.
The same thing occurs at the third My Block. The motors are started and the immediately stopped because the wait block doesn't have to wait. The robot is still at 360 degrees. The robot sees its movement as the picture below.
We know the first My Block works fine. It turns on the motors, waits to reach 360 degrees, and then stops. That part of the program works. But the other blocks are the same so it should work the same too right? Let's keep going.
The second My Block turns on the motors, waits to reach 360 degrees, and then stops. Consider this, what number is the rotation sensor at when it reaches that second wait block?
At that time the rotation sensor would be at 360 degrees so the robot would ask "Am I at 360 degrees yet?" and immediately get a yes from the rotation sensor. So in a few milliseconds after the motors are started, they are stopped. The wait block is basically doing nothing because the robot is already at 360.
The same thing occurs at the third My Block. The motors are started and the immediately stopped because the wait block doesn't have to wait. The robot is still at 360 degrees. The robot sees its movement as the picture below.
Now let's fix the problem. We know the first movement from 0 to 360 works. So for the next two My Blocks, we need to make it so the robot starts at 0. Then the MY Block will work. As we already know, the rotation sensor can be reset to 0 so this idea will work. So how do we reset the sensor to 0?
We want the block to start at 0 so place the block at the start of the program. Set it to port B, since that is the rotation sensor we are watching in the wait block, and set action to reset. Now the inside of the My Block should look like this:
Save the My Block and download the main program again. Try it now.
It worked! Now the robot sees its movement as below:
It worked! Now the robot sees its movement as below:
Now we just created a very important program. This is known as the motion program. We can create any type of motion from it.
Since we can create all these types of motion, let's make some more My Blocks. Create a My Block named backwards360. I will let you figure out what it does. Once you've made it, you can move on to the next lesson.