(J) Using the Internal and Motor Sensors
In addition to the external sensors that attach to the
sensor ports on the NXT (ports 1-4), the NXT brick itself also has some
built-in sensors, and the NXT motors also have built-in Rotation
Sensors that communicate to the NXT through ports A-C.
Using the NXT Buttons
The three buttons on the face of the NXT Brick (Left
Arrow, Right Arrow, Orange Enter button) are accessible as sensors from
a program and act almost exactly like Touch Sensors. See the Single Touch Sensor
section for ideas on basic use of these sensors. One important
difference between the NXT Buttons and Touch Sensors, however, is that
the NXT cannot detect multiple NXT buttons being pressed at the same
time, so strategies involving simultaneous presses, such as those used
in the double-touch sensor remote controls, will not work with NXT
buttons. Also note that the fourth NXT button (dark gray
Back/Abort button) is not accessible from NXT-G programs, as pressing
this button will always abort the program.
(Downloadable programs are available only on the
CD "LEGO MINDSTORMS NXT 2.0 by Example").
Program |
Description and Observations |
Attachments |
J1-AskNumbers |
|
|
|
This
program uses the AskNumber My Block, which shows an
advanced use of the NXT Buttons to allow the user to enter a
number into a running program using the NXT Buttons and the
display. The
J1-AskNumbers program uses the AskNumber My Block
twice to allow the user to enter a number of degrees and a power
level, then uses the results to configure a Move block to
make the robot drive the specified distance at the specified
power level.
The AskNumber My Block is complex
internally, but using it in a program is simple. You
simply specify the name for the value to be displayed on
the screen, and the minimum, maximum, increment
step, and default (start) values in the block's
configuration panel, and then the block handles all of the user
interaction and display and outputs the final number chosen from
the Number Out data port. |
(none required) |
Using a Timer
The NXT-G programming system provides a few simple ways
to do timing that are built into other blocks, such as the Wait
block with Control set to Time, the Move block with
Duration set to Seconds, and the duration of Sound
Tone. However, these controls do not allow you to
keep track of time while other blocks in the program are running.
To measure time without pausing the program, you can use the Timer
block.
(Downloadable programs are available only on the
CD "LEGO MINDSTORMS NXT 2.0 by Example").
Program |
Description and Observations |
Attachments |
J2-ReactionTest |
|
|
|
This program uses
the Timer block to play a little reaction test game on the NXT.
The program will display "Ready..." then wait a random of time
(using the Random block), then display "GO!" and time how
long it takes for the user to press touch sensor 1. You
can use the
Touch Sensors remote or just a loose touch sensor on a wire to the
NXT.
Since the program does not know how long to wait
(and is in fact waiting for a sensor press), it must time the
action with the Timer block. |
Touch Sensors
(as Wired Remote) |
Using the Rotation Sensors
The NXT motors each have a built-in Rotation Sensor
that can measure the rotation or angle change in a motor accurate to
1 degree and keep track of the total degrees turned since the program
started or the last time the sensor was Reset. In
addition to the simple uses of the Rotation Sensors built into the
Motor and Move blocks (see the Driving Straight
and Turning sections), you can also measure
rotations independently in a program using the Rotation Sensor
block.
(Downloadable programs are available only on the
CD "LEGO MINDSTORMS NXT 2.0 by Example").
Program |
Description and Observations |
Attachments |
J3-DispMotors |
|
|
|
This
program uses the DisplayMotors My Block to simply display
the rotation angle of all three motors while the motors are idle
(not being powered). Run the program, then turn Multi-Bots
wheels/treads and/or arm by hand and watch the degrees displayed
on the screen. Press the Enter button on the NXT at any
time to reset (zero) all three rotation sensors.
Motors do not have to be powered to measure their
rotation. You can turn the motors by hand or any other
action, and the rotation sensors will measure the amount of
their rotation. This can be useful or making things like a
hand-turned dial, using an unpowered motor. |
Golfing Arm
(Optional) |
J4-PathRemote |
|
|
|
This
program uses the DisplayMotors My Block and the
Touch Sensors remote control
to make a remote-controlled path measuring robot. You
control the robot with the remote control, and the program will
display the number of degrees travelled by each motor. You
can zero the sensors at any time and also adjust the motors by
hand at the end of a motion. This can be used to measure
the Duration (in Degrees) needed by a sequence of
Move and Motor blocks to get the robot to travel
along a desired path by itself.
Control the robot as follows:
-
Enter the Power
(speed) to use at the beginning of the program using the NXT
buttons. Slower speeds will generally be easier to
control.
-
Press and hold
both touch sensors to drive straight forward.
-
Press and hold
the left touch sensor (1) to do a
one-wheeled left turn.
-
Press and hold
the right touch sensor (2) to do a one-wheeled right turn.
-
Release both
buttons to stop.
-
After stopping
a motion, you can adjust the desired robot position by
turning the wheels by hand if desired.
-
Press the Enter
button on the NXT at any time to reset (zero) all of the
sensors. Typically you will want to reset after each
type of motion, to measure for a sequence of Move and
Motor blocks.
|
Touch Sensors
(as Wired Remote) |
[Back to Programs Index] |