Introduction to NXC and Bricx Command Center
(PDF file from the GaETC 2010 BYOL Session)

Objectives:
Use NXC Language and Bricx Command Center to write Basic Movment programs for the Lego NXT Robot

Standards:
M5P3:  Students will communicate mathematically
M5P1: Students will solve problems using appropriate technology

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 Bricx Command Center before the Robot will perform the program.  (Scratch and Python are "Interpreted Languages.")

The website for NXC and Bricx Command Center:

http://bricxcc.sourceforge.net/

More Online Resources:

http://www.legoeducation.us/store/
http://www.ortop.org/NXT_Tutorial/

Training Robot: (Building Plans)
I use a basic, easy to build robot to teach programming. When I introduce students to robotics, we isolate the building and the programming into different lessons.  First we learn to program with a standard robot model.  Then we rebuild the robot to accomplish more complicated tasks as needed.




Two motors that control the drive wheels are connected to the B and C ports.  The Touch, Ultrasonic, and Light Sensors are plugged into their default positions.

Touch Sensor:       Port 1
Ultrasonic Sensor: Port 4
Light Sensor:         Port 3

Overview of Bricx Command Center IDE:




Basic Bricx / NXC Commands:

Motor (Output) Commands:

OnFwd("ports", "pwr");
OnRev("ports", "pwr");
Off("ports");
OnFwdSync(“ports”, “pwr”, “turnpct”);
RotateMotor(“ports”, “pwr”, “angle”);

Flow Commands:

Wait(4000);     (milliseconds)
until (“condition”);
repeat (“value”)
{
   “body”
}

Task and Sub Commands:

Sub methodName()
{
    “body”
}

task main()
{    
     “body”
}



Process and Tutorial:

1. Getting Started:

  • Start Bricx Command Center
  • Select “usb” and “NXT”
  • Turn On Robot
  • Plug Robot Into Computer
  • Wait short time for computer to recognize Robot
  • Click “OK”

2. Take a test drive!

Click “Joystick” Tool
Set Motors to C Left and B Right
Try the Arrows! (Make sure the robot does not drive off the table!)



3.   First Robot Program: Out and Back



4.  Compile and Download!
  • Save Your Program (File -> Save)
  • Select “Compile->Compile” from menu bar. (Or “F5”)
  • Turn On Robot
  • Select Compile -> Download
  • Wait for Beep
  • Unplug Robot and Test! (Use Orange Button)
    • Robot: Software -> My Files -> Your Program
    • Select Program with Orange Button

5.  Second Robot Program: Simple Square with Synchronized Motors:



6.  Rectangle Using Rotation Sensors



8.  Zig Zag with Wait Block



9.  Touch Stop Using Touch Sensor



10.  Simple Line Follow with Light Sensor