Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
worldmags<br />
This time, we’ll take a look at dynamic variables <strong>and</strong><br />
data wires:<br />
• Just what are dynamic variables?<br />
• Why are they so darned important?<br />
After that, we’ll build a new attachment for Eddie,<br />
then get to programming!<br />
Just what are dynamic variables?<br />
We mentioned dynamic variables last month, but didn’t go<br />
into much depth beyond describing the different types. We know<br />
that a variable can be binary, boolean, or string but what does it all<br />
mean? Well, it turns out that using dynamic or changing variables<br />
can be an incredibly powerful tool in our programming arsenal.<br />
Consider the following: Let’s say we wanted Eddie to move<br />
faster if he saw a bright light, or slower if he didn’t see any<br />
light. There is a variable for motor power (speed) that is set<br />
to 75 by default in the NXT software. This number means<br />
that 75% of the maximum motor power will be given to<br />
the designated motor, <strong>and</strong> the number can be anywhere<br />
Replicate the<br />
attachment in<br />
reverse — this will<br />
attach to the other<br />
side of the robot.<br />
www.servomagazine.com/index.php?/magazine/article/december2010_Intermaggio<br />
Start with a single<br />
4 x 6 angular<br />
studless beam.<br />
Testing a Dynamic Variable<br />
We’ve built the attachment. Now, let’s create a<br />
program that uses a dynamic variable. This program will<br />
make Eddie move forward faster if he sees a bright light,<br />
slower if he sees little light, <strong>and</strong> stop if he sees no light.<br />
between 0 (no power) <strong>and</strong> 100 (full power). You can adjust<br />
it manually, or you can get fancy <strong>and</strong> use dynamic variables<br />
to adjust the motor every time the light value changes.<br />
This is even cooler because the light sensor’s variable is<br />
also a percentage (0-100). So, the brighter the light, the higher<br />
the variable which means that if we correspond that variable<br />
to motor power, we don’t have to do any math! We’ll learn<br />
more about how to do this once we get to programming.<br />
Why are they so darned important?<br />
Think of the possibilities! Dynamic variables can be used in<br />
just about everything — from calculating interest rates on bank<br />
accounts based on how much money the bank has in reserves,<br />
to determining the average amount of toxic chemicals in the<br />
air after an explosion before sending humans into the rubble.<br />
Dynamic variables are one of the fundamental building<br />
blocks of advanced programming, <strong>and</strong> today we’ll be<br />
getting ourselves very comfortable with them.<br />
First, let’s build a new attachment for Eddie that will<br />
aim his light sensors outward so he can see the light<br />
around him, instead of under him.<br />
Building Instructions<br />
Light Seeker<br />
Attachment<br />
1. 2.<br />
4.<br />
3.<br />
Attach the light<br />
sensor to the<br />
shorter end.<br />
This is the finished product.<br />
Plug the sensor on Eddie’s left<br />
into port 1 <strong>and</strong> the one on the<br />
right into port 2. 5.<br />
Add two black<br />
friction pegs <strong>and</strong><br />
two blue hybrid<br />
pegs as indicated.<br />
Let’s take a moment to think about what we just did:<br />
• We connected the “intensity” variable output of the<br />
light sensor to the “power” variable input of the<br />
motor block.<br />
• We’ve set the motor movement to backwards, which<br />
SERVO 12.2010 47<br />
worldmags