The Robot drive distance block tells the ActivityBot how far each wheel should turn. It is intended for projects where the goal is to drive specific distances and turn specific angles. You can use positive values for forward distances and negative values for backward ones. The default distance unit for Robot drive distance is 3.25 mm ticks. Inches and centimeters are also options in the drop-down menu. The example below shows how to make the ActivityBot roll forward 208 mm by setting the left and right distances for 64 ticks. We've used this value because 64 x 3.25 mm = 208 mm.
The direction the Robot drive distance block will make the ActivityBot move is:
Here are some examples – look carefully at the sign (+/-) of each value:
An easy way to remember turns is to make the wheel on the side you want the ActivityBot to turn to go backward (negative value).
The ActivityBot's wheel circumference is 208 mm, so a full turn makes the wheel travel that far. A single tick is equal to 1/64th of a full turn, and 1/64th of 208 mm works out to 3.25 mm.
If you know how far you want your ActivityBot to roll, you could divide the distance by 3.25 mm (or 0.325 cm or 0.00325 m) to find out how many ticks your program needs to tell the ActivityBot to travel.
ticks = distance mm ÷ 3.25 mm/tick
The ActivityBot’s pivot turning radius is the distance between the wheels. Ideally, it's 105.8 mm, but that will vary slightly with the shape of each aluminum chassis and also with how the servos are mounted. The left wheel will have to turn 2 × π × r to make the ActivityBot pivot by a full circle while holding the right wheel still. In this case, the r is the turning radius, so that’s 2 × π × 105.8 mm ≈ 664.76 mm.
Keep in mind that the turning radius will be slightly different for each ActivityBot, so you may have to tune the number of ticks for a 1/4 turn. For example, your ActivityBot's turning radius might need 50, 52, or 53 ticks to get as close as possible to a 1/4 turn.
This test code makes the ActivityBot go forward 128 ticks, and then make a 51-tick, 1/4 turn, to face 90- degrees to the right.
First comes the comment block noting the project name. Next, the frequency out block for the piezospeaker on P4 acts as a low-battery brown-out indicator.
After the required Robot ActivityBot initialize block, there are two Robot drive distance in ticks blocks.
The first Robot drive distance block moves both wheels forward with left 128 and right 128. Since 128 is enough ticks for two full wheel revolutions, the forward distance traveled is 3.25 x 128 = 416 mm, or about 16 inches.
The second Robot drive distance block uses left 26 and right -25 to move the wheels in opposite directions. As explained above, that is a combined 51 ticks, causing the ActivityBot to rotate in place to make the ActivityBot turn 90 degrees to the right.
Drive the distance, no distractions — The Robot drive distance block must complete the wheel turns for its target distance before it stops the motors. Only then will it allow the cog's code execution to continue to the next block. This behavior is called blocking, meaning that it makes the cog wait until it is complete before allowing the program the cog is running to continue. It's a lot like pause and frequency out, except that we know precisely how long each of those blocks will take. With Robot drive distance, we don't necessarily know the exact amount of time a given maneuver will take.
Different from the Robot drive speed block — The Robot drive speed block is introduced on another page. Unlike the Robot drive distance block, the Robot drive speed block is non-blocking. It sets the speed and then immediately moves to the next block as it maintains the wheel speeds you have set.
Unit Options — The Robot drive distance block's inches and centimeters options work only with the wheels that come with the ActivityBot robot. If you use wheels with a different circumference, the distance traveled per tick will change.
Line, arc, pivot, rotate in place — The values you use affects the path the ActivityBot takes. Use the same values for a straight line. For example 64, 64 makes the ActivityBot go forward. -64, -64 makes it go backward. Use different values for arcs, like 128, 64. To pivot on one wheel, set one of the two values to 0. To make the ActivityBot rotate in place, use positive values, like 26, -26.
Let's try making the ActivityBot navigate some basic shapes:
By repeating the forward and 90-degree turn maneuver 4 times, the program can make the ActivityBot draw a square.
Repeat x times need to change from 4 to 3, and -26 and 25 values need to change to make 120 degree turns instead of 90-degree turns.
Here is some arc code.
An example course is shown below. To run this particular course, the ActivityBot must perform the following maneuvers: