Professional Documents
Culture Documents
Robotics Workshops
Play: Robotics In Education video (4:40)
Programming Workshop
Programming Resource Book
July 2011
Paul R Keeney
paul.keeney@anoka.k12.mn.us
(763) 506-5692
www.anoka.k12.mn.us/ovms.mr.keeney
© Copyright 2011 Paul R Keeney rev 5.2 1
Introduction
This training guide was designed to help classroom
teachers, F.I.R.S.T LEGO League coaches, and students
with the new LEGO Mindstorms NXT Robotics System.
Materials also include suggestions to help keep your
LEGO pieces organized and inventoried.
The packet will go over the process of developing good
robotic programming skills from the concept stage
through computer programming and file maintenance.
There are numerous people developing other good
training materials and videos being posted on-line, so
there is no shortage to the amount of training available.
NXT Robotics Programming Resource rev 5.2
© Copyright 2011 Paul R Keeney No reproduction of this material is allowed without written permission from the author
2
Table of Contents
ORGANIZATION COMMON PALLET NXT Buttons Block ----------------------- 66
Keeping parts organized --------------------- 4 Move Block forward & reverse----------- 34 Sensor Feedback Box ---------------------- 67
Tray diagrams ---------------------------------- 5 Modifying Move commands -------------- 35 Using multiple sensors (cascading) ------ 68
LEGO PARTS Comments ----------------------------------- 36 Data Hubs & Data Wiring ---------------- 69
Parts diagram ----------------------------------- 6 *Hands-On Activity Challenge #1 ------------37 Number To Text Block ------------------- 70
NXT Brick -------------------------------------- 7 Point Turn ----------------------------------- 38 Variables --------------- ------------------ 71-72
Motors ------------------------------------------- 8 Swing Turn ---------------------------------- 39 Math Block ---------------------------------- 73
Sensors --------------------------------------- 9-12 Curve Turn ---------------------------------- 40 Logic Commands -------------------------- 74
SOFTWARE & CURRICULUM *Hands-On Activity Challenge #2 ---------- 41 Reset Motor Block ------------------------- 75
LEGO Mindstorms Edu NXT (NXT-G)- 13 COMPLETE PALLET Calibrate Sensors ----------------------- 76-77
Robot Educator ------------------------------- 14 Motor Block -------------------------------- 42
Data Logging ---------------------------- 78-81
Data Logging -----------------------------------15 Configuration Panel ----------------------- 43
*Hands-On Activity Challenge #6 ---------- 82
Carnegie Mellon Robotics Engineering -- 16 Forward & Reverse ------------------------ 44
CUSTOM PALLET
Carnegie Mellon NXT Video Trainer ---– 17 Swing Turn ---------------------------------- 45
Creating a My Block (subroutine) -------83
Green City Challenge--------------------------18 Point Turn ----------------------------------- 46
Adding a My Block to a program ------- 84
Carnegie Mellon Robots In Motion-- ---– 19 Curve Turn ---------------------------------- 47
My Block with variables ------------------ 85
Using Profiles --------------------------------- 20 Selecting & moving blocks --------------- 48
*Hands-On Activity Challenge #7 ---------- 86
PROGRAMMING Rewiring with sequence beam ----------- 49
ADVANCED COMMUNICATIONS
Brainstorming & Pseudocode -------------- 21 Wait For Blocks ------------------------ 50-51
Sensor Blocks (reset) ---------------------- 52 NXT Window information -------------- 87
Simple Text ------------------------------------ 22
*Hands-On Activity Challenge #3 ---------- 53 BlueTooth Communications ------------ 88
Creating a new program --------------------- 23
Sound Block -------------------------------- 54 FILE MAINTANENCE
Saving a program ----------------------------- 24
Loop Block --------------------------------- 55 Deleting files from NXT ------------- 89-92
Opening an existing program -------------- 25
*Hands-On Activity Challenge #4 ---------- 56 Deleting files from the computer ------- 93
Downloading a program to the NXT ---- 26
Running a program on the NXT ---------- 27 Switch Block -------------------------------- 57 Updating Firmware (operating system)--94
Common Pallet ------------------------------- 28 Sensor Threshold ---------------------- 58-59 Backing up & transferring files ---------- 95
Complete Pallet ------------------------------- 29 View Mode on NXT ---------------------- 60 Downloading to multiple NXTs -------- 96
Custom Pallet --------------------------------- 30 Line Tracking using Light Sensor ------- 61 Technical Support & Problems --------- 97
Sequence Beam ------------------------------- 31 *Hands-On Activity Challenge #5 ---------- 62 Bibliography / Resources ---------------- 99
Adding commands --------------------------- 32 Parallel Sequence Beams(multitasking)-- 63
Display Block ---------------------------- 64-65 3
Configuration Panel -------------------------- 33
Organization suggestions
Tray organizer diagrams are provided by LEGO in each kit to help
the students keep their parts organized and they list the quantities
of each part to help with inventory.
Fishing tackle box with multiple bins and/or removable trays to
sort the LEGO pieces individually are sometimes very helpful for
organizing the many pieces for FLL teams.
Create teacher lab rules and procedures: hold students to them so
the classroom runs smoothly.
Build student responsibilities: develop procedures to help keep the
students on-task and all of the equipment taken care of properly.
Develop a plan for where you will store the parts and make sure
students understand your expectations for them at clean-up time.
4
LEGO NXT robotics kits
The basic #9797 NXT kit contains 431 LEGO pieces
stored in orange and white trays that fit inside the white
storage bin to keep everything organized.
FIRST LEGO LEAGUE (FLL) team kits also include a
blue resource bin (#9648) with 672 additional LEGO
building elements for more advanced building projects.
You can download the pdf file from my website and then
print copies of these tray diagrams onto sticky-back
paper. Cut them into individual pictures and stick them
on the bottom of the tray compartments to help sorting.
6
LEGO Mindstorms NXT brick
Rechargeable Lithium battery with
charger is included with the LEGO
Educational version of the NXT and
also with the FLL sets. Otherwise, the
“brick” will run on 6- AA batteries
(not 1.2 volt NiCad batteries)
3 Output Ports for actuators View the interactive NXT image
(ports A, B, C on top edge of brick)
4 Input Ports for sensors
(ports 1, 2, 3, 4 on bottom edge of brick)
●
USB data port for communication between computer & robot
(downloading)
●
Wireless Bluetooth compatible communications are possible if
you have a Bluetooth dongle or transmitter for your computer
(Bluetooth is not allowed at most FLL tournaments). 7
NXT Motors
The NXT servo motors have built-in rotation sensors that
can very accurately measure how the motor spins in number
of rotations or degrees of travel. They will always be
connected to output ports (A, B, C).
●
When you set a Move or Motor block’s
direction, you are specifying the direction the
motor will spin. This may be different than the
direction your robot actually moves. View the interactive Motor images
●
Depending on how you build your robotic invention, setting the
motors to go forwards may actually cause your creation to move
backwards. The image here shows a motor spinning in the
default, forwards direction.
●
The motors spin at approximately 150 RPM at full power.
8
NXT Sensors
Sound sensor
Measures sound level in decibals (dB)
or modified frequencies (dBA)
Ultrasonic sensor
Distances in inches or centimeters
Light sensor
Measures ambient or reflected light levels
Touch sensor
Can be pressed, released, or bumped
Rotation sensor (built into motors)
Measures motors in degrees or rotations
RCX sensors View the interactive Sensors images
Sensor blocks for HiTechnic sensors are available for free download at www.LEGOeducation.us/hitechnic 10
Additional NXT Sensors
HiTechnic Gyro sensor
Contains a single-axis gyroscopic sensor that detects rotation and returns a
value that represents the number of degrees per second of rotation.
Sensor blocks for HiTechnic sensors are available for free download at www.LEGOeducation.us/hitechnic 11
Additional NXT Sensors
HiTechnic EOPD sensor
Electro Optical Proximity Detector, uses an internal light source to detect the
presence of a target or determine changes in distance to a target
19
Working with “Profiles”
Mindstorms NXT Education software
Setting up “Profiles” for each team/group of students will
allow you to use one computer for more than one group of
students. It will automatically keep their software programming
files in separate folders on that computer.
• To Create a new Profile: (set up only once)
• Click “Edit” in top menu bar
• Select “Manage Profiles”
• Click on the “Create” button
• Type in the new group name
• Click on the “Close” button
• Make sure students select their profile
every time they log onto their computer.
Launch LME Edu NXT software
20
Turning Your Ideas into Robotics Code
(How do I suggest getting started with writing a program?)
• Begin by brainstorming ideas of what you want your robot to do.
• Select your best idea.
• Convert your written robot actions
into pseudocode (not quite sentences
& not quite computer code).
• Describe all of the steps your robot will need to do
(go forward, turn left, lift an arm, etc).
• Create a pictorial representation (flow chart) of your
solution. This linear set of actions is called an algorithm.
• Define what computer code will make your robot perform the
actions you have described.
• Start to write your program on the computer & test your ideas
one step at a time. 21
Using “Simple Text”
For File Names & Robot Commands
The supported characters for the NXT display are the capital and
lower letters A-Z, the numerals 0-9, and the punctuation and
symbols shown below.
!”#$%&’()*+,-./0123456789:;<=>?
@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
º abcdefghijklmnopqrstuvwxyz{|}~√
Simple Text is used for the brick name, My Blocks, file names,
and displaying text on the NXT device using the Display Block.
If simple text fields contain other than simple characters or
symbols, they will display a blank instead. To avoid confusion
caused by lots of blanks, you should always use simple characters
for the marked text fields.
All places mentioned above require that you use “Simple Text”.
They won’t let you type in other characters. The exceptions are
the program filename and the text in the Display Block.
22
Creating a new program
• If you have decided to use “Profiles”,
have students click on their profile.
• Click in the “Start New Program”
window and type in the name you
want students to call their program.
• Click the “Go” button.
• Close the “Robot Educator” window
if you want more space on the screen
to write the program.
• The NXT software will automatically
create a set of folders on the hard drive
where the programs will be saved., so
file maintenance is very easy.
23
Saving a program
• “File – Save”
• Can be used if the program has been correctly
named already and you want to save it.
• You can also click on the icon on the top
menu bar to save a program.
• “File – Save As…”
●
Should be used when a program needs to
be renamed before it is saved. Type the
new name and follow the prompts in the
window that appears. (you can also use
this command if the student
has created their program within the wrong
“Profile” by clicking the “Browse” button and
navigating to the correct “Profile” folder) 24
Opening an existing program
• If you are using “Profiles”, click on your
team’s profile to get to the correct folders.
• Open existing files by clicking on “File”
and then “Open”. Select the file that
you want to open and then click on “OK”.
• You can also click on the triangle in the
“Open Recent Program” window
to select a recently used program.
Select the file that you want to open
and then click on “GO”.
• Close the “Robot Educator window if you want more space on
the screen to view or modify your program. The LME Edu NXT
software will automatically remember your preferences & keep
the Robot Educator window closed unless you open it again.
25
Downloading programs to the NXT
• Hook up the USB cable that is provided in each kit to connect the
computer to the NXT brick.
• Open the program that you want to download.
• Make sure the NXT power is on.
• Click the “Download” button from the window in the bottom
right corner ( down arrow=download).
• After the download is complete, the NXT will beep and the screen
will briefly say “Download Complete”.
• Bluetooth communications are possible if the NXT settings for
Bluetooth is turned on. You must click on the “NXT window”
button to connect using the Bluetooth. You
will be asked to go through a process of
setting up a passkey to make sure you are
communicating with the correct NXT unit.
(Bluetooth setup covered on page #88)
26
Running a program on your NXT
• Turn on your NXT by pressing the large orange
button. Tones will sound when you turn on the NXT.
• If it is already on, press the dark grey button repeatedly
until the words “My Files” appear.
• Press the orange button to select “My Files”. View the NXT movie (1:24 )
• Web Downloads
To use programs you have downloaded from the
Internet. These are not allowed in FLL tournaments.
30
Sequence Beam
The sequence beam controls the flow of your program.
Generally, one block represents one
command given to the robot. Blocks
perform their operations in order
along the Sequence Beam.
Blocks connected to the sequence beam can be
downloaded to the NXT to perform tasks on the robot.
Other blocks in the work area that are
not connected to the sequence beam will
appear grayed out and will not function
as any part of the working program.
The “Start Block” will appear automatically for new
programs and will always indicate the starting point. 31
Adding commands to
the Sequence Beam
• Hold the curser over the task palette.
• Click and drag on the command that you want
added to the sequence beam.
• Move the command to the right side of the existing
commands and drop it in place to add it to the end
of the existing sequence.
• You can also drop a new command into the middle
of an existing sequence by holding it in place until a
space opens up and then dropping it there.
• If an icon becomes grey/opaque, that means that it
is not connected to the sequence beam any more.
Reconnect it by dragging it to a different place on
the screen and then dropping it back into place
where it should be connected. 32
Configuration Panel
(for modifying attributes of commands
on the sequence beams)
• Click on an icon in the sequence beam to view the
attributes for that command.
• A teal colored outline around the icon indicates that it
is the command that is selected and has its attributes
displayed in the configuration panel at the bottom of
the screen.
• Change any of the attributes of that block within the
configuration panel and that block will be modified.
33
Forward using “Move” Block
The “Move” block can be configured to make
your robot go forwards or backwards in a straight
line or to turn in a curved path. You must define
how far your robot will go by using the Duration
property in the Configuration Panel.
●
The letters at the top right corner of the block show which of the
ports on the NXT will be controlled through this block.
●
This icon shows which direction your motor is programmed.
●
This icon shows the power level. The default level is 75%. Your
robot’s speed may also be affected by other conditions, such as
wheel size, the friction of the surface it is moving over, or whether
it is moving up or down a slope.
●
This icon shows whether you have set the Duration property to
unlimited, degrees, rotations, seconds, or stop.
Note: Setting the motors’ duration to anything other than “Unlimited” will cause the program to wait until the
robot completes the set duration; only then will the program continue to the next command. 34
Modifying Move Commands
With The Configuration Panel
Select the motors you would like to control. If you
choose to control motors B & C, the motors will be
synchronized; going forward or backwards at exactly
the same power. If you select all three motors, then
A, B & C will all work at the same time.
Choose whether the motors will go “forward”, “backwards”, or “stop”.
Selecting “Stop” will also reset the motor rotations to zero.
The slider or the editable input box will let you set the power level (speed)
[0-100%]. Either slide the marker on the bar or type in your power level.
Using the Duration pull-down menu, you can set the motors to run for an
unlimited interval or for a set number of seconds, rotations [default] or degrees.
By choosing Time, Rotation or Degrees you can control how far your robot will
travel.
Choose whether the motors will brake or coast after they’ve finished their action.
If you want your robot to stop precisely at an exact location, set the motors to
brake. Setting your motors to brake will also keep your robot from slowly rolling
backwards on a slope but the setting will wear out the NXT’s batteries quicker
because the motors are doing work to keep the robot in place.
35
Comments
Comments are typewritten notes or directions left by the
programmer but they do not change the way the robot
behaves in any way. Comments are very important to the
programmer’s ability to remember what a certain piece of
code does, or so other programmers can understand
what is being attempted in the program.
To use the Pointer Tool, double click
anywhere on the grey programming workspace
where you want the comment added.
To use the Comment Tool,
single click on the workspace.
Type the important information
you want noted for that area. 36
View Robot Educator Activities #3 & #4
Caution: It is very difficult to fine-tune your robot’s turns using the slider bar! 40
HANDS-ON ACTIVITY SET #2
Program your robot to make 3
different turns using the “Move” block
Use the Move Block and Configuration Panel to make your robot
make a “Point Turn” to the right exactly 3 wheel rotations
(1080 degrees) and then stop. Make sure you include “comments”
in your program. Save your program with the name “pointRx3”.
Download it onto your robot and test it.
Modify that program to make the robot do a “Swing Turn” to the
left for 3 wheel rotations and then stop. Save that program as
“swingLx3”. Download it onto your robot and test it.
Make another program so the robot will make a “Curve Turn” to
the right for 3 wheel rotations, then stop. Save that program as
“curveRx3”. Download to your robot & test it. Compare the turns.
Create a new program that uses one style of turn to drive in a
“Figure Eight” around two obstacles.
BONUS ACTIVITY: Navigate the course using all 3 styles of turns
View Robot Educator Activities #6 & #7 41
“Motor” Block
The Motor block allows for precise control
of one motor’s speed. You can “ramp up” to a
set speed or “ramp down” to a stop. By
deselecting “Wait for Completion,” your
program can move on to the next block once
the Motor block has started a motor.
1. The letter at the top right corner of the block shows which
NXT port is set to control this particular motor.
2. This icon shows which direction the motor will go.
3. This icon shows the power level.
4. This icon shows whether you have set the Duration property
to unlimited, degrees, rotations, seconds, or stopped.
5. You can change many of the values dynamically by connecting
data wires to this block’s data hub. This will de discussed later
in the booklet.
42
Configuring the “Motor” Block
1) Select the motor to control.
2) Choose whether the motor
should go “forwards”, .
“backwards”, or “stop”.
1) You can precisely control the acceleration of the motor by selecting “Ramp
Up” or “Ramp Down.” A motor set to “Constant” will reach full power
immediately and will stop quickly.
2) The slider and the editable input box will let you set the power level (speed)
[0-100%]. Either slide the marker on the bar or type in your desired power.
3) Select this checkbox if you’d like to turn on power control to attempt to
compensate for any resistance or slippage that the motor encounters to
maintain the same rotation amount per second.
4) Using the Duration pull-down menu, set the motor to run for an unlimited
interval or for a set number of rotations, degrees, or seconds.
5) With “Wait for completion” selected, the motor will finish its action
completely before allowing the program to move on. If you de-select “Wait
for completion,” other blocks in the program can proceed while your motor
completes its action.
6) Choose whether the motor will brake or coast after finishing its action.
43
Forward & Reverse using “Motor” Block
If you use Motor blocks in your programming instead of
Move blocks, you will often have many more options on
how to control the behavior of the motors.
A motor block will only control
one output port, so you will
need a Motor block for each
motor that will be moving
(2 wheel drive= 2 motor blocks)
You can start 2 or 3 motors simultaneously, if they are wired in
sequence along the beam and the Duration time is set to Infinite.
Use a Wait For block to control how long you want the motor(s)
to do the desired action.
Use more Motor blocks with other commands (stop, change
direction, etc) to begin the next set of actions. 44
Swing Turn using “Motor” Blocks
Swing turns are very easy to create and fine-tune the
robot performance if they are created using a series of
Motor blocks and Wait For blocks.
Because a swing turn only has
one motor running at a time, it is
very easy to program it with a
Motor block.
To make the robot turn to the
left, turn on the motor on the
right side of the robot.
Use a Wait For block to control how long you want the motor(s)
to do the desired action.
Use more Motor blocks with other commands (stop, change
direction, etc) to begin the next set of actions. 45
Point Turn using “Motor” Blocks
Point turns will allow your robot to spin quickly in either
direction. Because the robot moves so quickly, I suggest that
you slow down the motors to keep wheels from slipping.
Point turns are sometimes called
spin turns because the wheels are
running at the same speed but in
opposite directions.
To make the robot spin to the left, set the motor on the right side
of the robot to run forward and the left side motor to run in
reverse.
Use a Wait For block to control how long you want the motors
to do the desired action. (you will only need to wait for one
motor if using rotations or degrees)
Use more Motor blocks with other commands (stop, change
direction, etc) to begin the next set of actions.
46
Curve Turn using “Motor” Blocks
Curve turns will allow your robot to drive forward or
backwards while turning at the same time. Using Motor Blocks
is the most accurate way to create curve turns that you can
accurately adjust later.
Curve turns are usually the fastest
method of allowing the robot to
move a new spot if it cannot
drive in a straight line.
To make the robot spin to the left, set the motor on the right side
of the robot to run forward at a higher power level. The larger
the difference in power levels are, the sharper the robot will turn.
Use a Wait For block to control how long you want the motors
to do the desired action. (you will only need to wait for one
motor if using rotations or degrees)
Use more Motor blocks with other commands (stop, change
direction, etc) to begin the next set of actions. 47
Selecting & Moving Blocks Around
Sometimes it is very helpful to move blocks around on the
workspace. If a block was created correctly, it can easily be
moved to a different part of the sequence beam.
Click on the block that you want moved so a blue
border appears around it.
You can also select multiple blocks
together by clicking and dragging a box
around all of them together.
While the block(s) are still outlined with blue, drag them
to the location where you want them. The other blocks
will automatically move to open up space to add them.
Click to drop the blocks in the new location.
If they become greyed out, reselect them, wiggle them around a bit
and then place them back to reconnect to the sequence beam. 48
Rewiring Long Sequence Beams
Sequence beams sometimes need to be routed into odd
paths, especially when the programs get very long with
many blocks strung together.
Use the arrow keys on the keyboard to navigate left, right, up, or down to
determine which blocks you want to move.
Click & drag to create a window of blocks
you want to move.
Drag the selected blocks to the location you
would like them, then click to drop them in
the new spot.
To reconnect the moved blocks to the
sequence beam, hold the “shift” key while
clicking from the end sequence beam hub to
the beginning hub of the moved blocks.
Re-select any greyed out blocks, wiggle them around the screen a bit, and
when they are placed back in the correct location, they will be connected. 49
“Wait For” Block
The Wait For block lets your robot sense its
environment for a certain condition before it
continues. Use the slider or type in a value to set a
trigger point (threshold) so that the program continues
when sensor values are below or above that level.
The number or letter at the top right
corner of the Wait block shows the
port the block is monitoring. The
configuration panel will let you
change ports if necessary.
If you have chosen to wait for a light, sound, or ultrasonic sensor,
this icon indicates at what level the trigger point (threshold) is set;
the more colored bars displayed, the higher the trigger point. If you
have chosen to wait for a touch sensor, the icon will display the
touch sensor condition (bumped, pressed, or released) that will
trigger the block and allow the program to move on.
50
“Wait For” Block Options View the Wait For movie (2:29)
By de-selecting the “Display Flat View” checkbox, the Switch block will use a
tabbed interface to show the alternative sequences of programming blocks. By
clicking on a tab, you will be able to view and edit the blocks and see which
condition will cause those particular blocks to run. 57
Sensor Threshold
A threshold is a “cutoff” or dividing line between two regions.
One common use for thresholds is to divide the hundreds of
possible sensor readings from a sensor (a Light Sensor can give a
value anywhere from 0-100, for example) into two manageable
categories.
For the Light Sensor, this would mean setting a threshold value
somewhere between 0 and 100, then declaring that all values
above the threshold are now “light” while all values below the
threshold are now “dark.”
A light sensor reading can then be easily categorized and handled
appropriately.
The threshold value can be chosen in any
way desired, but it is conventional to
choose a value exactly halfway between
two known extremes (e.g. halfway between
a very dark surface and a very light one). View Thresholds explanation movie
58
Calculating & Setting Thresholds
A threshold number must be set in the
configuration panel for the following sensors:
●
Light Sensor
●
Ultrasonic Sensor
●
Sound Sensor
1. Record the maximum reading from the sensor on your robot
(sound, light, distance, etc).
2. Record the minimum reading from the sensor.
3. Threshold numbers are usually placed around midway between
the maximum and minimum readings of the sensor, so
calculating the average (mean) is the typical method.
4. Enter that calculated threshold number into the configuration
panel as needed for the sensor. (the software will only accept whole numbers)
59
View Mode on NXT
If you want to see exactly what a sensor is reading on your
NXT, you may use the “View” mode on the NXT brick
and the sensor you want information from. View movie about Light sensor View Mode
You can use the starting point to create additional sequence beams
that will allow your program to run simultaneous tasks. For example,
you might have the main sequence beam in
your program controlling a robot’s forward
motion but have a second sequence beam
controlling a robotic arm on the robot.
To create a parallel sequence beam, move the mouse pointer
over the starting point (or over the wire stub), then press and
hold your mouse button while you move the mouse upwards or
downwards. This will draw out a sequence beam that can be
connected to programming blocks. When you download and run
the program, the blocks on both sequence beams will run in
parallel. You can use data wires to have the blocks on both
sequence beams communicate with each other.
You can also start a new sequence beam later in your program
(i.e., not from the starting point). Do this by holding down the
Shift key and moving your mouse pointer straight up or down
from a position on the main sequence beam. 63
Display Block
Use this block to display an image, display text, or draw
a shape on the NXT’s display screen.
The screen measures 100 pixels wide by 64 pixels high.
1. This icon shows whether the block is set to
display an image, some text, or a drawing; or
whether it will just reset the display to the
default icon.
2. You can control the Display block dynamically
by connecting data wires (from other blocks’
data hubs) to the Display block’s data hub.
3. Information can be displayed on various
sections of the LCD screen by using settings
located in the configuration panel.
Caution: using display blocks can quickly use up NXT memory space 64
Display Block Settings
Configuring the Display Block:
1. Use the pull-down menu to choose whether you want to display an image, some text, or your
own drawing. You can also select that you just want to reset the display.
2. To erase the contents of the NXT’s screen, check the “Clear” checkbox.
If you choose to display an image, you’ll be able to set the following
additional properties:
3. The File property will you let select the image to display.
Click on each name to see a preview.
4. Use your mouse to move an image, some text, or a
drawing around the preview screen to position it. The X and
Y input boxes let you precisely position the image.
If you choose to display some text, you’ll be able to set the following
additional properties:
5. The Text property will allow you to enter the text to be
displayed on screen.
6. Use the pull-down menu to choose the line number that
you would like your text displayed on or use the X and Y
input boxes to set a precise starting location for the text.
Typing zeros into both boxes will start the text at the bottom
edge of the screen against the left edge.
7. For Drawing Actions: the Type property will allow you
to select between drawing a dot, a line or a circle.
View the Display Blocks video (2:49) 65
NXT Buttons Block
If you choose “NXT” Buttons within a “Wait For block,” the
program will wait for a chosen NXT buttons to be bumped,
pressed, or released before moving on.
If you select “NXT Buttons” within the “Sensor” block, you
can select which NXT button will send out a “true” signal when
activated. The block’s data hub will automatically open when the
block is placed on the sequence beam. You will need to drag a
data wire from the NXT Buttons block to another block that can
accept a logic (true/false) signal.
The configuration panel must be set using these options:
Select which NXT button will send out a “true” signal when activated and
cause the program to move on.
Choose “Pressed” if you want the chosen button to be activated at the
instant the button is pressed in.
Choose “Released” if you want the chosen button to be activated at the
instant the button is released.
Choose “Bumped” if you want the chosen button to be activated after
66
the button is both pressed then released.
Sensor Feedback Box from NXT
The feedback boxes on the bottom left View the Viewing Sensors video (7:39)
By placing Switch blocks inside other SwitchCan you predict the robot behaviors?
blocks, the program can be written with
multiple “If-Then” choices.
Place a Switch block into the program to
determine the first sensor decision.
Place a new switch block inside the first Switch
block to make the second decision.
Flat View
By de-selecting the “Display Flat View”
checkbox, the Switch block will use a series of
tabs on the interface to show the alternative
sequences of programming blocks. Click on a
tab to view and edit the blocks and see what
blocks will run under that sensor condition.
Tab View
68
Opening Data Hubs
& Creating Data Wires
Open a block’s data hub by clicking the tab at the lower left edge of the block
after it has been placed on the work area.
Note: Sometimes data hubs will not open completely, leaving some plugs
hidden. Reveal all of a data hub’s plugs by clicking again on the tab area. You
can also close a data hub (or hide any unused plugs not connected to data wires)
by clicking the tab area.
The cursor will change shape when it hovers over or is near a data plug. If you
then press the mouse button and drag to the right, a data wire will “unroll” that
can then be connected to a plug on another block’s data hub
Data wires carrying input information to a block are
connected to the plugs on the left side of its data hub. Data
wires carrying output information away from a block to
another block are connected to the plugs on the right side.
Each data wire carries a specific type of data between
blocks. For example, if a data wire is dragged from a logic
plug on a block’s data hub, it can only be connected to a
logic plug on another block’s data hub. Data wires are View Data Hubs video (4:46)
69
identified with specific colors as shown in this diagram:
Number To Text Block
This block will take a number (like a reading from
a sensor) and turn it into text that can be displayed on
the NXT’s screen. The input number can be typed in
or supplied dynamically by a data wire.
Text is a group of characters of any length that you type in using your
keyboard. Text is important because it can be displayed on the NXT’s screen.
The numbers (data) generated by the NXT as it runs your program are not
text; they can’t be displayed directly on the NXT’s screen. You must first
convert them to text using a Number To Text block from the “Advanced”
commands in the “Complete” pallet.
The Number To Text block’s input number can be typed in or supplied
dynamically by a data wire. The output text can only be sent out using a data
wire. See the Data Hub section on page 64 for more information.
When you convert a number into text, you can add it to a sentence that will
be displayed on your NXT’s screen. By using a different block called a Text
block, you can create sentences such as: “The motor turned 6 times” or “The
light sensor reading is 35%” that can be displayed on the NXT’s screen. In
these sentences, the numbers 6 and 35 were generated by the NXT (and not
typed in). Those numbers (data from the NXT) had to be processed by a
Number To Text block before being added to the other pieces of text. 70
Variables Block
View the Variables movie (7:02)
First make sure that your NXT is connected to your computer and that it is
turned on. Also, make sure that the sensors you want to calibrate are connected
to the NXT. Pay particular attention to the ports they are connected to.
When you are ready, select the Calibrate Sensors function from the Tools menu.
The Calibrate Sensors dialog box will appear. If no NXT is connected to your
computer, the dialog box will appear grayed out.
Select the light sensor and the port the sensor is connected to. Then click the
Calibrate button. This will download a small program to the NXT and run it
automatically.
On the NXT’s screen you will see text that reads “Min Value:”. Point the light
sensor towards a material or spot that represents what the light sensor should
measure as dark. Press the orange Enter button on the NXT.
Next you will see text that reads “Max Value:”. Point the light sensor towards a
material or spot that represents the brightest location the sensor will encounter
during the program. Press the orange Enter button again. Calibration is
complete.
Note: The calibration will work for the specific sensor no matter which port you
connect it to after completing the calibration process. If you calibrate the light
sensor on port 3, the calibration will still remain in effect if you later connect the
light sensor to port 4.
76
Calibrate Sensor Blocks
Use this block to calibrate the minimum (0%)
and maximum (100%) values detected by a
sound or light sensor.
You will need two Calibration blocks to fully
calibrate a sound or light sensor: one to set the
minimum value for the sensor and another to
set the maximum value.
One way to fully calibrate a sound or light sensor is to set up two
Calibration blocks at the beginning of your program with a Wait
block (set to wait for a Touch sensor) positioned after each one.
If your are calibrating a light sensor, for example, and you set the
first Calibration block to calibrate the minimum value and the
second Calibration block to calibrate the maximum value, the
calibration procedure would happen like this:
1. Place your robot in the darkest/quietest place it will encounter during its
program and press the touch sensor. This will calibrate the minimum value.
2. Then place your robot in the lightest/noisiest place it will encounter during its
program and press the touch sensor. This will calibrate the sensor’s maximum
value and your robot will continue on with its program. 77
Data Logging
Configuring a Start Data Hub or Experiment
You can use this block to let your NXT collect data from sensors
and save it to a file on the NXT. The Experiment Configuration
panel is configured in the same manner and is used to create
a new experiment or modify an existing one.
1) Use the input box to name a log. The default
name is myData
2) Select the duration of the experiment in
Seconds or Minutes and enter the value
in the text field to the left. Select Unlimited
to run the experiment indefinitely until it is stopped by a Stop Data Logging Block, or
choose Single Measurement to take only one measurement.
3) Select the rate at which samples will be taken in Samples per Second or Seconds between
Samples and use the editable input box to the left to set the number.
4) With "Wait for Completion" selected (default), the Start Datalog block will finish its
action completely before allowing the program to move on. If you de-select "Wait for
Completion," other blocks in the program can proceed while your Start Datalog block
completes its action.
5) Using the sensor pull-down menu, select the sensor(s) that you want to use.
6) Using the Port drop-down menu, select the port on the NXT the sensor is connected to.
7) Choose the measurement unit by clicking on the icon and toggling between the options
for each sensor. 78
Data Logging
Configuring a Stop Data Hub
This block stops a Start Data Logging block
that had been previously set to unlimited.
●
Use the drop-down menu to choose
the name on the Start Data Logging
block you would like to stop.
●
You can control the Stop Data Logging Block
dynamically by connecting data wires (from other
block’s data hubs) to the Stop Data Logging block’s
data hub.
●
You can open a block's data hub by clicking the tab
at the lower left edge of the block after it has been
placed on the work area.
79
Data Controller
The Data Logging Controller is the interface between the
Data Logging program and the NXT. The Controller allows
you to open the NXT Window, download and transfer log
files from the NXT, download and run experiments and stop
active experiments.
The Controller is inactive until you move or “hover” your mouse cursor over it, changing it
from a small grey form to a larger, fully interactive version. You can do five things with the
Data Logging Controller:
●
NXT Window: Opens the NXT Window, allowing you to connect your computer to the NXT, view
important information about your NXT, and manage NXT files. If your NXT memory becomes full while
data logging, you can delete log files in the Memory tab.
●
Download to NXT: Downloads a program to the NXT, allowing you to use the NXT remotely to run
experiments and log data for Upload to the Data Logging program.
●
Download and run: Downloads and runs the selected experiment.
●
Stop: Allows you to stop an experiment that is currently being run on the NXT.
●
Upload: This allows you to move data logging files from your NXT to your computer. The log files on the
NXT can originate from data logging experiments and from any data logging programs on the NXT. You
can run experiments and log data remotely, and then connect the NXT to the computer when you are
finished. 80
Data Logging
Accessing log files on the NXT
A Start Data Logging block creates a log file on the NXT.
●
To access the log file, open the NXT Window, click on the file category “Other”
on the list to the left, select the log file you would like to upload from the list, then
click on Upload. Then select the location on your computer where you would like
to copy your log files to.
●
Once your log files are copied to your
computer, they can be opened using a
text editor or spreadsheet program.
●
You can have multiple Start Data
Logging blocks create different log files.
The Name on the block
identifies a specific log file on the NXT. If the same name is used in more than .
. one block, the data will be written to the same log file. If different names are used
. for the Start Data Logging blocks, different log files will be created.
81
HANDS-ON ACTIVITY SET #6
Data Logging with Color Sensor
Devise a method to use Data Logging to evaluate the
effectiveness of using a LEGO color sensor to differentiate
different colors (this can also be done with a light sensor).
Use a separate piece of paper to formulate a Data Logging experiment that will
test whether 2 specific colors will have enough contrast for your robot to
differentiate between them using the LEGO light sensor.
Have your experiment approved by your instructor.
Use the chart below to predict whether 2 particular colors will have
“High”, “Moderate”, or “Low” contrast with each other.
Write your experiment into a working program and test it with your robot.
BONUS ACTIVITY: Program your robot to utilize your collected data to
navigate through an obstacle course using your color sensor data.
Hint: you may need to slow the driving speed of your robot for it to collect quality data points for your
specific color samples.
82
Creating a “My Block” (subroutine)
A “My Block” (often called a subroutine) is used to help
save NXT memory space by putting commonly repeated
robot actions into a custom file that
can be reused multiple times.
• Click and drag to highlight the
code sections that you want to
change into a My Block.
• Click the “Create My Block” button
98
Bibliography / Resources
LEGO Mindstorms Edu NXT (LEGO Education)
http://www.legoeducation.us
Robotics Engineering v1 (Carnegie Mellon University)
http://www.education.rec.ri.cmu.edu/content/lego/curriculum/rev1_index.htm