Figure 1. Terminal window.
Step Two: Do some UNIX command line stuff to install
the tools.
Since you are going to be doing some command line
work with Makefiles (don’t panic) and stuff, you’ll want to
be able to work with the command line. It is now time to
open a Terminal Window. You will find this application
here: Applications/Utilities/Terminal.app. When you start
Listing 1: Simple Makefile.
#################################################
# NBC Makefile for first.nxc
#################################################
Project name and flags (if any)
PROJ = first
this app, you get a terminal window
with a command line that looks a
bit like Figure 1. It won’t look exactly
like that because I’ve customized
mine to a font, size, and color scheme
that I like.
You will have to learn some UNIX
commands. Fear not, they are few and
simple for our purposes. The terminal
will be set to your login directory which
is just your login name (as mine is). To
get back to this directory, type: cd .
(The cd command means change
directory in case you were wondering.)
To find out where you currently are use
the command pwd — which stands for
Print Working Directory, again, if you
are curious.
To see the files in this directory,
type: ls. You’ll see a bunch of
directories. That’s nice, but this isn’t
where we want to be; we want to
be in the directory you created and moved the NXC folder
to. To get there, type cd /applications/nxc/nbc*. In
OS X, you don’t have to worry about letter case when
just moving around, so I left everything lower case. The
“*” at the end of that command is called a wildcard and
we use it here so that we don’t have to type out
nbc-1.2.1.r3.osx. In this directory, you will find two
files: one is nbc which is the NBC assembler; the other is
called nxtcom_scripts.zip. You want to “unzip” this file to
get the program that will allow you to communicate with
the NXT brick. Type: unzip nxtcom_scripts.zip. You’ll
find lots more files in this directory now, including some
other directories. (To tell the difference between files and
directories, use ls –F. The –F will cause directories to
have a trailing “/” and executable programs will have a
trailing “*”.)
Tool locations
NBC = /applications/nxc/nbc-1.2.1.r3.osx/nxt/nbc
NXTCOM = /applications/nxc/nbc-
1.2.1.r3.osx/nxt/nxtcom_scripts/nxtcom
INCS = /applications/nxc/nbc-1.2.1.r3.src/NXT
Default stuff to make
all: rxe install
Compile
rxe:
$(NBC) -v=105 -Z1 -I=$(INCS) -
O=$(PROJ).rxe -nbc=$(PROJ).nbc -w+ $(PROJ).nxc
Listing 2: SONAR program.
#include “NXCDefs.h”
// Very simple implementation, everything is
placed in the main task.
task main(){
short ultra;
SetSensorLowspeed(S4);
while(true){
ultra = SensorUS(S4);
ClearScreen();
Upload to device
install:
$(NXTCOM) $(PROJ).rxe
TextOut(0, LCD_LINE4, “Range”);
NumOut(0, LCD_LINE5, ultra);
Clean target
clean:
rm -rf $(PROJ).rxe $(PROJ).nbc
Wait(500);
}
}
16 SERVO 09.2010