Lesson 4
Now that we can use Mindstorms, lets make our first program. Make a new program and save it as "First Program". Let's start by making our robot move forwards. The first block we will need for this is the motor block.
Put a motor block onto the program line and set it to port B, forwards, at 75 power for Unlimited duration. Download this to your robot and give it a try. What happens?
It seems our robot didn't move. Why do you think this happened?
Stepping through the program, we can see one issue. The motor block is set to unlimited so the robot just turns on the motor and then moves to the next block in the program. But there is no next block right? Wrong:
It seems our robot didn't move. Why do you think this happened?
Stepping through the program, we can see one issue. The motor block is set to unlimited so the robot just turns on the motor and then moves to the next block in the program. But there is no next block right? Wrong:
So you see, the invisible block stopped the robot from moving right after we told it to start moving. How can we get it to keep moving forwards?
In plain english, I would want my robot to start the motor and then wait for a while before going to the invisible stop block. I know we could set duration to something other than unlimited but that can cause funny things to happen. So it seems we need a block that will cause the robot to wait. I think we have something like that:
In plain english, I would want my robot to start the motor and then wait for a while before going to the invisible stop block. I know we could set duration to something other than unlimited but that can cause funny things to happen. So it seems we need a block that will cause the robot to wait. I think we have something like that:
Well that was convenient! Now let's grab our own wait block and place it after the motor block. We will set it to wait for the robot to move 360 degrees forwards. Try setting it yourself.
Just to make sure, your wait block should be set to Sensor, Rotation Sensor, Port B, forwards, and 360 degrees. Check this and then download and test your program.
You may find it does move, but it turns instead of going forwards. How would you fix this?
If you said another motor block, you're correct! Add a second motor block in between the motor and wait blocks. This one should match the first motor block exactly except that port should be set to C (Hint: This may be a good time to try using the copy and paste you learned earlier). This will start both motors, and then wait to move forwards. Download and try this.
Great it worked! We can now move forwards. However, there are still an issue and questions with this program. We will answer those in the next lesson.
Just to make sure, your wait block should be set to Sensor, Rotation Sensor, Port B, forwards, and 360 degrees. Check this and then download and test your program.
You may find it does move, but it turns instead of going forwards. How would you fix this?
If you said another motor block, you're correct! Add a second motor block in between the motor and wait blocks. This one should match the first motor block exactly except that port should be set to C (Hint: This may be a good time to try using the copy and paste you learned earlier). This will start both motors, and then wait to move forwards. Download and try this.
Great it worked! We can now move forwards. However, there are still an issue and questions with this program. We will answer those in the next lesson.