Welcome to the third tutorial for the CR102 course. In this lesson, we will revisit the rover and subroutines, as well as learn how to integrate the ultrasonic sensor into our rover.
Revisiting the Rover
In the previous course, we learned about the rover and how to control its movements. Remember that the rover is designed so your Arduino holder can fit directly on top of it. After securing the holder board and attaching the motors, we can use the blocks in the example on the right in CarduBlock to control the rover. Remember the rover moves like a tank; the wheels can’t turn. So to turn left, you’ll need to move the right motor forward and/or the left motor backwards. Do the opposite to turn right.
CHALLENGE: Review of the Rover
Program the rover to perform the following steps whenever a button is pressed.
- The Button is pressed
- The rover goes forward for 1 second
- Turns to face backward
- Goes forward for 1 second
- Turns to face forward again
- Stops, now in the same place and facing the same direction as when it began
Motor Speed in Detail
Last class, we mentioned the MotorSpeed block, but didn’t really go into detail about it. There’s really not a whole lot about it, but it’s still worth it to go into it just a bit more.
As the name suggests, the block allows you to specifically control how fast your motors are going. By selecting values from -255 to 255, you can individually control each wheel’s speed. A negative value just means that the motor will go backwards. Keep in mind that MotorForward is just MotorSpeed set to 255, and MotorBackwards is the same but set to -255.
This Week’s Activity
We will be mounting the ultrasonic sensor to our rover in order to create a robot capable of navigating obstacles without bumping into them. The concept is like that of the robot vacuums that you often see nowadays. Ideally, it should be able to get through a simple field of obstacles.
If you’re not sure where to start, try planning out your program on paper first by drawing a flowchart like last week. Remember that a reading of 1 from the ultrasonic sensor is equal to about 1 centimeter.
Hints: Make sure to carefully control your motor speed. If you remember about subroutines, they make the task a lot easier, so make sure to use them whenever you can.
That’s it for the lesson. Look forward to the final one!