Now that you've tried basic driving with the S3 robot, you will be ready to move on to slightly more complex motion commands. Start by taking a look under the ACTIONS > MOTORS block category, locating the drive speed block.
Take a close look at the two large wheels on the left and right side of the robot. Each of these is attached to a gear motor inside the plastic case. The rear tail wheel is not powered, but it does monitor whether the S3 is moving or stalled (more about that later).
The drive speed block has three parameters (values) you may enter:
- Left motor speed and right motor speed values are are shown as percentages:
- Positive speed percentages (1 to 100%) move the S3 forward.
- Negative speed percentages (-100% to -1%) move the robot in reverse.
- Using a 0 value means the robot stops (if in motion), or stays still (if not moving).
- Duration is set in milliseconds. A millisecond (from milli- and second; abreviation: ms) is one thousandth (0.001 or 10^-3 or 1/1000) of a second. Therefore, a 1000 ms value entered for the duration would be one second in length.
Setting the right motor speed and left motor speed for the same value over a certain duration would cause the S3 to travel forward or backward in a straight line. Small changes in direction might occur on a tile floor or carpet because of friction, small obstructions, uneven, or sloped surfaces encountered along the way. Variations like these, or wheel slippage could keep us from arriving perfectly at our intended destination.
The Physics of Motion
When studying the physics of motion, you often learn that there can be some variation between theory and real world conditions. An example of this idea is that you might ignore the effects of friction or air resistance when doing theoretical calculations, yet when you start looking at real-world examples, these forces remain present and cannot be ignored.
Your S3 robot operates in the real world, therefore you will encounter variation in the way it moves at different speeds and on different surfaces. This is due in part to the way the S3’s motors respond at various speeds, changes in current, internal resistance, friction - even changes in the gear lubrication over time. As noted above, different sloped or irregular drive surfaces may also cause changes in observed movement.
Put plainly, this means that there will be noticeable differences in your S3's motion as you drive at different speeds and on different surfaces. Do not mistake these variations for limitations. The S3 is quite capable of moving very exact distances and directions. This does mean that some ways of controlling the S3’s movement are more accurate than others, as you will discover in future tutorials.
Let’s look at an example.
Distance (d) = rate (r) x time (t)
You are probably familiar with the equation d = rt, which shows that the distance your robot travels is a function of how fast it is moving and for how long. While you can use a variety of units in this equation we’ll keep it simple was below:
- Distance is meters (m) - Metric units are often used as a standard in science. A meter is 3.28 feet or a bit more than 1 yard. You can find a metric tape measure at most hardware stores.
- Rate is meters per second (m/s) - This is speed: the distance (in meters) traveled in 1 second.
- Time is in seconds (s).
At 100% drive speed the S3 moves about 0.18 m/s, and at 50% drive speed around 0.09 m/s or about half as fast. An S3 moving at 100% speed for five seconds should travel exactly twice the distance of an S3 moving at 50% speed for five seconds.
The following two blocks both result in the S3 arriving at the same destination – just at different times. This is theoretically what should happen... but we operate in the real real world. Differences in how the motors respond, variations in driving surface, or other conditions that cause friction or slippage make this approximately true.
Putting these values in the d = rt formula as below demonstrates this idea.
According to this equation, an S3 programed with a drive speed value of 50% can travel the same distance as an S3 with a 100% drive speed value, simply set the duration for twice as long. Further along in this tutorial, you will experiment with this process and you will be able to observe the real world variations that can occur.
Some food for thought as you experiment with navigation programs: a slower moving robot is often more precise and easier to control than a fast moving one since it has less abrupt changes in speed.
Did You Know?
The Mars Science Lab, MSL - Curiosity Rover is in its 5th year of exploration on Mars. Based on variables including power levels, terrain difficulty, slippage, and visibility, the maximum terrain-traverse speed is estimated to be 200 m (660 ft) per day using automatic navigation. It can travel up to 90 meters (300 ft) per hour but the average speed is 30 meters (98 ft) per hour. Source: https://en.wikipedia.org/wiki/Curiosity_(rover)
Remember that the S3 travels 0.18 meters per second at top speed, or 10.8 meters per minute - which is a speed of 648 meters (or 2,125 feet) per hour! Our S3 moving at a controlled speed can cover in 1 hour what the Mars Science Lab covers in 1 day.
To be fair to the Curiosity Rover though, the surface of Mars is more difficult terrain than our home or classroom floor or tabletop. Of course, Curiosity doesn’t have a pen port for a Sharpie® either!
Time Blocking and Real Time Motor Commands
The drive speed block can be used in two different ways: with or without a duration value. When a duration value greater than zero is used it's considered a blocking command. This is because the S3 does not proceed to the next line of code until the duration value has elapsed.
When a duration is not set (that is, left at the default of zero), the motor direction and speed are maintained forever or until changed by another block. This is referred to as a non-blocking command.
Example: Motor Speed with a Duration (Time Blocked)
This program takes about four seconds (4000 ms) to run. The S3 moves forward at 3/4 speed (75%), stops, and returns to where it started (there and back again).
Example: Motor Speed with no Duration (Non-blocked Time)
This program makes the S3 robot move backwards, forever. Notice that there is actually a forward motion block first. Because it has no set duration, it is changed instantly by the second block (backward motion). Since there is nothing after it, the backward motion block runs forever.
Why would you use a time blocked drive speed command instead of a non-blocked drive speed command? Time blocking commands are useful for drawing more accurate shapes with a Sharpie® in the S3’s pen port, and for other activtities requiring the S3 to travel a precise distance. Distance commands will be discussed in later tutorials.
You will learn as you continue to work with your S3 which movement control methods work best and most accurately in certain conditions. Non-blocked driving commands are more useful for sensor-based navigation, where the S3 must respond immediately to changes in the physical environment. Examples: light-following, line-following, or object detection and avoidance with infrared sensors.
Using a Wait Block with Non-blocked Drive Speed Blocks
A single program can usually be developed several different ways and have the same, or similar, end results. Within the CONTROL menu the wait block can be used with a non-blocked drive speed block and have the same result as a drive speed block with a time duration. For example, these two programs produce the same result:
You may have noticed the third drive speed block on the program on the right. This block is necessary in order to tell your robot to stop. In an earlier tutorial you learned that the wait block means pause, but it's a bit more complicated than that. Picture a light. When you slip the light switch on, the light turns on. And while it waits for the next command, it continues to follow the previous ON command. Then you flip the switch off, and the light turns off. Again it waits for the next command, continueing to follow the OFF command. All while the motor itself is still running. The third drive speed block is in place and set to zero in order to stop the motor entirely.
Program the S3 to drive forward at 100% speed for 4000 ms and then drive backwards to the starting point at 50% speed. Make a tape square around your S3 to test your program to be sure you returned to the starting point.
Here is an example:
How did your S3 perform? Did it return to the exact spot where it began? What factors did you have to modify to make your S3 return to the exact spot? Remember that however you have to vary your settings to have the S3 drive forward and backward to the exact point, the formula above applies. Distance (d) = rate (r) x time (t). Using exactly ½ speed (100% and 50%), how close does your time come to being double? Using exactly double the time (4000 ms and 8000 ms), in what way does your speed setting have to change to start and end at exactly the same spot?
Did You Know?
Engineers, programmers, and roboticists often keep notebooks (digital or paper) of experiments and/or the results of tests, designs, or methods of doing something as they work. For example, many electronics hobbyists know of Forrest M. Mims III’s wonderful Notebook series.
It is a great idea and helps you remember what you’ve done, what worked, and what did not. Try to get into this habit in your own work.
It is always true that distance (d) = rate (r) x time (t) when given perfect conditions with no friction or other challenges. Since our conditions are not perfect, let's record your results for the Try This example shown above in a chart like the one below. This should give you an idea of how the ideal varies from your actual real world results.
Try This Results - Drive Forward 4000 ms at 100% and return to start point at 50% speed.
The S3s drive speed settings, 0 to 100% (+ for forward movement and - for reverse movement), have some real world limitations. The relationship between 25%, 50%, 75%, and 100% drive speeds are not exactly proportional in the real world. There is, of course, a speed setting (based on specific conditions) that is exactly half of the speed setting of 100%. The percentage settings in the drive speed block are good approximations, but they are approximations. This means that if you need the S3 to drive at half-speed, you will likely have to test a few different speed settings in order to get it right for your environment.
Note: Remember, as stated above, that there are more accurate ways to control the S3’s movement and that these methods will be covered in other tutorials.
For now, let’s continue to experiment...
- Modify the program above to execute in reverse, so that the robot drives backward to the finish line and then forward to the starting line. What variations did you find in this example? How did you change the settings to arrive at the exact starting point - did you vary time, or speed, or both? Any of the methods should work, because distance (d) = rate (r) x time (t).
- Modify the program above to do the same thing, but use the wait block with a non-blocked (duration set to zero) drive speed block. Did it work correctly? If not, can you figure out what went wrong? Hint: Following the second delay, did you notice in the example that the motors need be instructed to stop running continuously?
- Make your S3 go forward for approximately 2 meters (m). Use the distance formula you have been working with to calculate the duration of movement (t), with 2 m as the distance (d) and an estimated rate (r) of 0.18 m/s at 100% motor speed. Remember that using these units, time will be in seconds, so you will need to convert it to ms. How would you do this using both Time Blocked and Non-blocked methods? Record your results in your own notebook.
- Modify the above program to drive backwards to the same starting point at 25% speed. What real world variations did you encounter? Adjust or tweak your setting so that the program works just as you want. Record your results.
- What do you think will happen if you set the drive speed to different forward speeds on the left and the right? Set one side to move forward (positive) and one move in reverse (negative)? What if one motor speed remains at a zero value and the other is set to a positive or negative value? Give it a try!
- Can you make your S3 turn in place in a clockwise direction? How about turning counter-clockwise? Use your tape square from above to test your programming!
Special thanks to Parallax friend Whit Stodghill for his assistance in writing, editing, and testing material for these S3 tutorials.