Advanced NXT-G Programming Workshop – 2010

advertisement
Dublin Robotics Boosters
NXT-Step Programming Workshop
Basic Programming Workshop Review








Programming can not overcome poor robot and
attachment design
Think strategically with missions & attachments
Use Bluetooth
KISS it!
Change ONE thing at a time
Document changes
Leapfrog development
Save, Save, Save
NXT-Step Programming Workshop: Taking your programming to the
NXT Level

Adding on to the Basics:

Create a script or a checklist for the competition




This checklist should be run through each time you approach the table to
ensure that EVERY ITEM is in it’s place and you are ready to go
This checklist should be read by a non-robot handling student throughout the
competition.
This checklist can be as simple or as complex as needed to suit your team
Things to include





Check chassis
Check wiring is secure
NXT is “on” and set to it’s 1st program/mission
Attachments are assembled and ready for use
Who is the robot handler, what mission are they doing (repeat as needed)
Default Ports
Attachment Motor

Default port A
Drive Motors
Touch Sensor


Default port 1
Sound Sensor

Default port 2
Default ports B & C
Ultrasonic Sensor
Light Sensor

Default port 3

Default port 4
Use that BRAIN!

Use the NXT to
find accurate
sensor readings


“View” option
Bluetooth can
send sensor
readings to PC


select the sensor
block
readings will
appear on the far
left of the
configuration panel
Reading Sensors: Now it’s your turn…
Objective… take sensor readings using your NXT
Using your NXT and Bluetooth, we’re going to:
 Take rotation reading (only reads in degrees)
 Take light reading
 Calibrate NXT light readings


Select “Calibrate” program from tools menu (it will download and
run automatically).
Run this program EVERY time you approach the board if you use
light sensors
Multitasking!
What is multitasking?
 Programming your robot to accomplish multiple tasks at the
same time


Why use it? SAVES TIME!!
Example: Move forward and raise an attachment
Multitasking: Now it’s your turn…
Objective… Program your NXT to walk and chew gum at the
same time
In NXT-G, we’re going to:
 Create a multiple sequence beam



Program a standard move forward block
Add a 2nd sequence beam, programming the attachment motor to
raise or lower
TIP: Add a move block below the 1st sequence beam. Use
“Shift” and click on the 1st sequence beam, then drag down to
connect to the move block, creating a new sequence beam.
Loops: Going in Circles…
What’s a loop?
 Requires a task to be repeated a set number of times before
moving to the next block
 Repeat (or continue) a task until a specific variable is met (using
sensor input)
 Requires that specific conditions are met before moving on to the
next block
Loops: Now it’s your turn…
Objective… using a loop, learn to meet a specific condition
before moving on to the next block
Using a loop, we’re going to:
 Create a task that needs to repeat a set number of times
before moving to the next block
 Continue a task until a specific variable is met (using sensor
input)
Breaking and Entering: using a crow bar
What’s a Crow
Bar?
 A temporary
block used to
pry open a
space within a
loop or a
switch
Crow Bar: Now it’s your turn…
Objective… learn to manipulate blocks to pry open space for
loops and switches
Using a crow bar, we’re going to:
 Create a 2nd sequence beam inside a loop

Hint: The same process can be applied to a Switch
Can you count to ONE?: Single Count Loops

Single Count Loops:


Ensure that ALL tasks are met before leaving the loop
Why use a
Single Count
Loop?

It’s an insurance
policy that
everything is
synchronized
before moving
on
Single Count Loops: Now it’s your turn…
Objective… using a single count loop, learn to ensure ALL tasks
are completed before leaving the loop
Using a single count loop, we’re going to:
 Create a program that needs to meet a specific requirement
before moving to the next block

Hint:

Use a crowbar to put everything in a Loop
Switches: If/Then Conditions
What’s a Switch?
 If Condition A is met, then program chooses path 1
 If Condition B is met, then program chooses path 2

Example: Condition A: If the Light Sensor reads above 50, NXT says “Light”;
Condition B: If the Light Sensor reads below 50, NXT says “Dark”
Switches: Now it’s your turn…
Objective… using a switch, teach your robot to make a choice
between two actions
Using a switch, we’re going to:
 Create a program that requires a if/then statement, dependent
upon sensor input.
Data Wires: Playing Telephone with Your
Programming

Data Wires are:


Data wires send information from one block to one or more
blocks later in a program
Three types of Data Wires:




Numeric: integers (whole numbers), positive or negative
Logic: one of two possible values, true or false
Text: a string of letters “Hello”, “turn right”, “643cheese”
Why use them?



Could send a light reading to a variable block
Could send a touch sensor reading to a move block
Could send text to the NXT screen letting you know what a
specific condition is (a light sensor reading)

Must use a text block to convert a reading to text
Data Blocks: Information Overload

Logic, Math & Compare Blocks:


Range & Random Blocks:


Blocks in which math calculations or comparisons are
performed
Looks for values in a given range or randomly selects a value
Variable & Constant Blocks:




Carry and hold information for later use
Variable Blocks get information from other blocks
Constant Blocks must have values, like numbers or a true/false,
input manually by the programmer
Why use them?

So we can reference values later in a program
Data Wires and Data Blocks: Putting it all
together
Uses math to
calculate distance
Constants
Data Hub
Data Wires

See the Help section for specific color coding
and other helpful information about data wires
My Blocks: Space Saving Miracles

My Blocks are:


Why use a My Block?



Customized collection of blocks condensed into a single block
Saves screen space & simplifies look of your program
Creates a “program” that can be used multiple times within a
single block or program.
Hints:


If you change anything within a My Block, it changes that My
Block throughout your programming.
Double click the My Block to see what’s inside it.
My Blocks: Now it’s your turn…


Objective: Learn
to create a My
Block
We’re going to…
Create a simple
program and
make it into a My
Block
Telling your NXT where to go…

Using the information that we’ve already learned…



How can you use a loop to determine your NXT’s location on
the board?
Would it be more accurate if your robot had multiple Touch
and Light Sensors? Why or why not?
Hints:


If you tell your robot to “square” to a wall or a line, is it in a
more accurate position on the board than telling your robot to
move X number of rotations?
How does the position of the Light/Touch Sensor on the robot
affect the programming?
Telling your NXT where to go…

Using the information that we’ve already learned…

How can you use a Touch Sensor with a loop to:


Find a wall
How can you use a Light Sensor with a loop to:

Find a line
Telling your NXT where to go…

Find a wall

Find a line
Telling your NXT where to go…

Using the information that we’ve already learned…

Using 2 Touch Sensors can you modify your “Find a Wall”
program to:

Square to Wall
Telling your NXT where to go…

Square to wall
Telling your NXT where to go…

Using the information that we’ve already learned…

Using 2 Light Sensors can you modify your “Find a Line”
program to:

Square to Line
Telling your NXT where to go…

Square to line
Telling your NXT where to go…

Using the information that we’ve already learned…

How can you use a Light Sensor with a switch to:

Follow a line
Telling your NXT where to go…

Follow a line
Master Programs: The King of the NXT-G
World (insert evil laugh here)…

Master Programs are:

A program that runs all the table top missions as a single
mission


It breaks the missions into individual sections, pausing between each,
waiting for input from the NXT brick before proceeding to the next
one.
Why use a Master Program?


Saves space
Eliminates stressful searching for programs on NXT brick
during competition
Kudos and credit where it’s due: We
couldn’t do it without you…




Cindy Bryden
Dan Monroe
Cougar FLL Team
Programming Lego Mindstorms NXT by Owen Bishop

http://www.amazon.com/gp/product/1597492787/ref=oss_prod
uct

Created October 2010 by:

Nick and Sherri Behr
Download