NQC is a programming language which is a subset of the popular full-featured language 'C'.
Instead of a block diagram, like in the "Robotics Invention System", NQC is text-based code.
All commands must be places in a function (task) named main, i.e.,
task main()
{command1
command2}
Commands are similar to the lower-level commands in the other system. In programming, a command is called a 'function call'.
The curly brackets denote the beginning and end of the 'main' task.
Function calls (commands) have parameters, which are placed within parenthesis after the function name, e.g.,
functionName(param1,param2)
For banking software, we might make a function call like the following:
deposit(accountNo, 100000); // accountNo is a variable with the user's account number in it.
With the NQC language, we have functions which control the robot. These functions are similar to the "Blocks" from the block diagram system.
For instance, to start one of the motors in the forward direction, we call the function:
OnFwd(motor)
Motors are named OUT_A and OUT_C
So the following calls can be made:
OnFwd(OUT_A) // sets just the left motor
OnFwd(OUT_C) // sets just the right motor
OnFwd(OUT_A+OUT_C) // sets both motors.If you only do OUT_A, the robot will veer right, OUT_C left. The following is the way to turn right.
OnFwd(OUT_A)
OnRev(OUT_C)
Other important functions:
OnRev(motor)
Off(motor)
OnFor(motor,time) -- time is in 1/100 seconds, so 100 is one second
Wait(time)
Off(motor)
In-Class Tutorial
Please work alone on the following programs, saving them to your personal H: directory or a subdirectory within. When you have completed a program, go to a station with a tower and download it to a robot for testing.
1. Choose Start | All Programs | Bricx Command Center.
2. Make sure brick is near tower, then choose USB 1 as the port.
3. Choose File | New to open a new file. Then enter the following code:
task main ()
{
OnFwd(OUT_A+OUT_C);
}
4. Save the program in the file "fwd.nqc" on your H: directory under an NQC Subdirectory.
5. Choose Compile and then download the program to your robot. What does the program do?
6. Write a program that causes the robot to go forward for one second, wait for one second, then turn left and go that direction for one second. Save this program in "forwardLeft.nqc"