(A-B) Driving Straight
The programs in the section show different ways to
make Multi-Bot drive in a straight line. Working through the
examples in order will help you learn the different options for motor
control.
Driving Straight - Basic
(Downloadable programs are available only on the
CD "LEGO MINDSTORMS NXT 2.0 by Example").
Program |
Description and Observations |
Attachments |
A1-MoveRot100 |
|
|
A2-MoveRot50 |
|
|
A3-MoveSec100 |
|
|
A4-MoveSec50 |
|
|
|
These
four simple programs variations demonstrate using the Move
block to make Multi-Bot drive in a straight line. By
comparing the behavior of the four variations, you can see the
difference that the power level has on the distance and time
travelled.
With Rotations for the Duration,
the power level affects the time but not the distance.
With Seconds for the Duration, the power level
affects the distance but not the time. |
(none required) |
A5-MoveUnlim |
|
|
|
This
program uses the Unlimited option of the Move
block to allow the following program blocks to control the
duration. By using the Rotation Sensor block, the
robot is made to drive 3 rotations and then stop.
Note than when compared to specifying the
Duration directly in the Move block, such as with the A1-MoveRot100 program, the robot
does not slow down gradually at the end but rather stops
suddenly. This can be useful when you need full
power throughout the motion. |
(none required) |
A6-MoveBrake |
|
|
|
This
program helps reveal the true behavior of the Brake
option of the Move block, which is to hold the motor's
current position by applying power as necessary in either
direction to return to the position at which the "brake"
occurred.
After stopping with Brake, a tone is
sounded and then a loop prevents the program from ending.
After the tone is sounded, you can observe that if you manually
move one or more of the robot's wheels, they are hard to move
and will return to their original position. When you abort
the program, the "brakes" are released. |
(none required) |
A7-MoveCoast |
|
|
|
This
program shows the behavior of the Coast option of the
Move block, which is to cut power to the motors and let them
coast down on momentum.
Compare this program to the similar
A6-MoveBrake program, and you
will see that the robot goes a little bit farther on momentum,
and the motors are not difficult to turn after stopping.
|
(none required) |
A8-Move2Coast |
|
|
|
This
program shows how the Coast option of the Move
block can be used to string sequences of Move blocks
together smoothly.
The robot does not wait to coast to a stop
after the first Move, but just continues right away.
Note however, that if you change Seconds to Rotations,
it will slow down between the two Move blocks. To
get a smooth combination measured in Rotations (or
Degrees), you will need to use the technique shown in
A5-MoveUnlim for each segment of
the motion. |
(none required) |
Driving Straight - Advanced
(Downloadable programs are available only on the
CD "LEGO MINDSTORMS NXT 2.0 by Example").
Program |
Description and Observations |
Attachments |
B1-MoveTimeout |
|
|
|
This
program uses the Unlimited option of the Move
block along with sensor tests and other logic to produce a
measured move in rotations with a "timeout" in seconds.
The resulting motion will stop after the
either the robot has travelled 1 full motor rotation or
3 seconds have elapsed. |
(none required) |
B2-Motors |
|
|
|
This
program shows one simple way to get two motors to run at same
time using two Motor blocks instead of the Move
block, by un-checking the Wait for Completion option on
the first motor. One problem with this
technique is that the automatic "Go straight" functionality of
the Move block is not being used, so the robot may curve
gradually to one side of a long run because the motor on one
side is stronger, or it encounters less friction or less wheel
slip.
Another problem with this technique is that
the Brake option will not work if selected on the first
motor (both motors use Coast in this example). |
(none required) |
B3-MotorsWait1 |
|
|
|
This
program fixes one of the two problems with the B2-Motors program by measuring
rotations separately with a Rotation Sensor and then
using a Stop to brake both motors.
However, a possible problem is that the rotations
on motor C are not being measured, so it possible that motor C
may travel fewer or more than the desired rotations. |
(none required) |
B4-MotorsWait2 |
|
|
|
This
program is a more complete variation on the B3-MotorsWait1 technique that
stops only after both motors have completed the full
rotations required. Now both motors are
guaranteed to travel the required rotations. However, it
is now possible that either motor may travel more than
the desired rotations. |
(none required) |
B5-MotorsSeq |
|
|
|
This
program shows another way to get two motors to run at the same
time using two Motor blocks instead of the Move
block, by using two sequence beams.
Compared to the B3-MotorsWait1
program, this technique measures rotations independently on both
motors, so both motors are told to stop when they finish.
One possible and subtle problem is that the
program will stop when the main sequence finishes, so if motor C
gets hung up for some reason (try stopping or slowing it by
hand), it may not finish the requested rotations. |
(none required) |
B6-MotorsSeq2 |
|
|
|
This
program solves the subtle problem with the
B5-MotorsSeq program by using a
block wired between the two sequences to force the main sequence
to wait for the second sequence to finish before continuing.
Now the program will sound the tone and then
end only after both motors have completed their
rotations. |
(none required) |
B7-SquareWall |
|
|
|
This
program shows a simple way to get a robot to square itself up
against a wall, so that it can back up perpendicular to the
wall, using a simple time delay. |
(none required) |
B8-StallWall |
|
|
|
This
program is a more complex alternative to the
B7-SquareWall program to align
perpendicular to a wall. It uses the Rotation Sensor
and Timer blocks to detect when both motors have stalled
(stopped or slowed significantly) against the wall, or when an
overall timeout has elapsed. This will allow it to
continue sooner than if just the timeout is used. |
(none required) |
Using My Blocks to Drive Straight
(Downloadable programs are available only on the
CD "LEGO MINDSTORMS NXT 2.0 by Example").
Program |
Description and Observations |
Attachments |
B9-Move_cm |
|
|
|
This
program uses custom My Blocks designed to allow the
program to specify how far the robot should move in
centimeters rather than motor rotations or degrees, which
makes it easier to use and easier to adapt to a different robot
design. Note: The Forward
and Backward My Blocks in this program are similar to the
Forward and Backward My Blocks developed in the
My Blocks
Tutorial, except that the Treads option is done with
a parameter instead of a variable. |
(none required) |
B10-Accelerate |
|
|
|
This
program uses a custom My Block named ForwardAccel to
smoothly accelerate up to the requested power level and travel a
requested number of centimeters. The test program allows
the user to set the distance in cm by using the display and
buttons on the NXT.
The ForwardAccel block is an extension
of the Forward My Block (used in the
B9-Move_cm program) and uses
several additional Logic and Math blocks as well
as a Loop to achieve the acceleration. |
(none required) |
[Back to Programs Index] |