GPS Receiver Programming
program GPS for
the fake GPS Receiver. This program is designed to be
intentionally tricky and even misleading when you examine it. But
can you figure it out anyway? Here are some hints:
The stuff about "back
door" variables and system traps is all fake. The variables
with strange names are just regular NXT-G variables, and they behave
in the same way as all variables. Don't worry if you don't
know what a "thread", a "trap", or a "stack" is. This is all
The rebooting into
another operating system (a "debug micro-kernel") is fake.
Everything is done using normal NXT functionality. But can you
explain the results you see on screen?
Don't get bogged down
in the math calculations in the program. They don't do
The comments in the
program are designed to be intentionally misleading. Don't
believe what you read. Look at the what the program blocks are
And here are some general techniques to help you figure out how an unfamiliar program
works. You can also use these techniques when you are trying to
find a problem with ("debug") your own programs.
In a program that
contains Switch, Loop, and Sequence splits, it is not always obvious
where the program will go when. To help you figure this out,
you can add Sound or Display blocks to the program that will signal
to you when the program reaches that point. For example, if
you put a "Hello" sound block at the beginning of a loop, then you will
hear the "Hello" each time the loop repeats. And if you put
different sounds in different conditions of a Switch, you will be
able to hear which way the switch went.
To slow down the
normally rapid execution of blocks in a program, to help you trace
through it while it is running, you can add Wait blocks that wait
for a time delay, a touch sensor, or one of the NXT buttons (e.g.
orange Enter button) to be pressed. This works well combined
with the Sound and Display blocks suggested above. Try adding
a Display or Sound block immediately followed by a Wait for the
Enter button at a key point in the program. This will tell you
where the program is and give you a chance to notice and think about
it before the program continues.
To help figure out a
program that contains variables (most of the variables in the
program are not important, but a few are), try
this technique to trace through the program by just looking at the
blocks (not running it):
Get out a sheet of
paper and a pencil to write variables down on.
Start at the
beginning of the program and carefully follow the program flow
with the white sequence beams, etc., one block at a time.
Each time a new
variable in introduced, write down its name on the paper, and
next to it write down the value that was written to the
variable. Any variables that are read before being written
will start out with a zero/False/empty value.
Any time a variable
is used for a Switch, Math Block, etc., look at your paper to
determine the value for the variable.
Any time an
existing variable is re-written with a new value, erase or cross
out the old value on your paper and write the new value.
As an advanced way to
debug a program with variables in it while it is running, you can
add Display blocks to display the values of certain variables
(numbers will need to be converted to text with the Number to Text
block then wired into the Text input hub of the Display block),
followed by a Sound then a Wait for a button press to give you a
chance to notice and read it.