![]() |
Teamwork Creativity Excellence |
Nebo
Elementary School
Department of Fine Arts |
||||||||||||||||||||||||||
![]() |
||||||||||||||||||||||||||||
PTA Performances Fine Arts ASP Weekly Schedule Music Links Exercises Sub Plans Computer Help Nebo Music Curriculum Overview Recorder Nebo Specials Schedule Nebo Music Calendar Nebo Fine Arts Home Rhythm Composing Project 4th Grade Instrument Project Template 5th Grade Composer Project Template 5th Grade Listening Links for Composer Project |
Lego
MINDSTORMS NXT and NXC Programming Language: The Lego
MINDSTORMS NXT Robotics kit uses motors, sensors, Lego Mindstorms
building parts and a small computer called the "NXT Brick" to create
Robots that one can program using the MINDSTORMS NXT software.
Like Scratch, MINDSTORMS NXT-G uses icons
or
blocks that represent programming commands. Another way
to program the NXT Brick is to use a text based language such as NXC or
Robot C. Using a text based language gives the programmer finer
control of the Robot's computing power. In addition, NXC is an
open source program, thus one can save on the costs of the site license
for NXT-G. However,
text based programming presents a different set of challenges.
The programmer must compile and "de-bug" the program if it does not
compile or run properly on the Robot. In addition, two sets of
software, "NBC" and "T2N" must be used at the command line level to
transfer the program to the NXT Brick. Definition of a Robot: A Robot is a
machine that can be programmed to do a task without being directly
controlled by a human being. There are two parts to a
robotic system. 1. Hardware: This is the mechanical robot. The motors, gears, wheels, parts, computers that make up the machine. This is the part you build. 2. Software: This is the
instructions for the tasks and actions the robot will do. This is
the part you write. NXC Language
is used to create the software that controls the actions of the
robot hardware. NXC is a text based system of assembling
instructions for the machine. The flow of direction usually moves
sequencially from top to bottom. This software is an example of a
compiled
program. Programs you write in NXC must be compiled with NBC and
downloaded to the NXT Brick using T2N before the Robot will perform the
program. (Scratch and Python are "Interpreted Languages.") Example 1: Sample NXC Program Driving the
Robot Forward and Back
The above
program has a main task that drives motors B and C at 75% power.
The next line (wait(4000)) tells the Robot to wait 4 seconds. The
Off(OUT_BC); command tells the motors to stop. Next the robot
moves the B and C motors in reverse. The final line turns the
motor off. Here are
some basic rules of NXC:
Example 2: Movement Codes (Codes that
Control the Motors)
Example 3: Looping (Iteration) Repeat a task several times.
(The above example repeats the Robot moving forward and doing a point turn 4 times.) Infinite Loop. Keeps the task going and going . . .
(Keeps the motors on forever. Or at least until you stop the Robot.) Example 4: Conditional Statements Conditionals are good in interactive programs. For example, using the touch sensor to let the Robot know it has bumped into an object.
(If the Touch Sensor in port 1 is triggered, B and C motors move backwards to .3 seconds. Then Motor B turns forwards for .3 seconds. Then B and C motors move forward.) Example 5: Light Sensor The Light Sensor senses differences in light intensity (brightness). This value can be used to sense the light around the robot or differences in reflected light off of surfaces like the floor.
(The above program follows a black line a white surface. (Clockwise only) Example 6: Motion/Ultrasonic Sensor The Motion/Ultrasonic Sensor uses high frequency sound waves and echos to detect the distance between the sensor and other objects.
Example 7: Touch Sensor This button can sense in three modes, pressed, released, and pressed and released. This enables the robot to sense when it is touching or bumping another object.
Example 8: Sound Sensor This is a microphone that senses the intensity of sound near the Robot.
Example Programs for basic vehicle robots: 1. Move Forward and Back
2. Move Forward, Spin, and Back
3. Using Touch to allow the robot to move about the room and not bump into walls or other objects.
Writing a Program Using NXC: 1. Open your favorite Text Editor. (Click on K Menu. Select Debian->Apps->Editors->Kwrite) 2. Compose your program. 3. Save your program to your file area. Make sure you use the extension .nxc (Example: LastnameForward.nxc) Compiling an NXC Program 1. Navigate to Directory where you saved "filename.nxc" a. Click on the House (Home Directory) b. Click "NeboMusicWork" c. Click Your Grade d. Click Your Class e. Click on Your Name 2. Open a Bash Shell (Press F4) 3. Use following command to compile:
4. New file will appear in directory "filename.rxe" Sending (Uploading) the program to the NXT Brick. 1. In same directory as "filename.rxe" - open a Bash Shell. (Press F4) 2. Plug in Robot NXT brick to USB port of the computer. 3. Do following command:
4. Program should load into NXT brick. 5. Unplug the NXT brick and try the Robot! Sample Robot Projects
|
|||||||||||||||||||||||||||
![]() |
||||||||||||||||||||||||||||
|
![]() |
|||||||||||||||||||||||||||
Nebo
Fine Arts Home |
Nebo
Elementary Home
Paulding County
Public Schools |
|||||||||||||||||||||||||||
![]() |