| NIST Interschool Tactical Robotics Organization | ||||||||||||||||||||||||||||||||
| < -------------------------------------------------------------------------------------------------------------------> | ||||||||||||||||||||||||||||||||
| Page Navigation | ||||||||||||||||||||||||||||||||
| TRS NQC Guide 1 | ||||||||||||||||||||||||||||||||
| Homepage | ||||||||||||||||||||||||||||||||
| Guide 1: Basic Commands Guide 1: Basic Commands An introduction to NQC NQC is a powerful programming language based on the C++ programming environment. NQC stands for (Not Quite C), and was designed by Dave Baum (some guy in the US). It is a text-based programming environment, which may scare a lot of people, but if you learn to follow the rules, you�ll easily understand and can develop your skills quickly. BricxCC is a program that allows you to write and send NQC programs. It also does the function of checking your code, so your robot can run it correctly. NQC code has a special set of rules (lexicon) that I will outline below: 1.) Tasks: task main() { //whatever your code is } Every program written in NQC is made up of �tasks�. This task is called �main�, and it is the task that the RCX will run automatically after you press the little green button. It will do everything inside the curly brackets. Note that anything you put after �//� the program does not read, so it�s a good habit to explain what your commands mean. 2.) �OnFwd�: task main() { OnFwd(OUT_A + OUT_C); // } As you may have guessed �OnFwd� turns motors on. You have to say which two outputs to turn on. If you look at your RCX, you see that there are three outputs: A, B and C. OnFwd(OUT_A + OUT_C); turns on the motors connected to outputs A and C. Note that you need to put the �;� at the end of the command to tell the program that you�re done with the command and make it move on. 3.) �Wait� task main() { OnFwd(OUT_A + OUT_C); Wait(300); // } The �Wait� command tells the program to (surprise, surprise) wait for a while. The time you want it to wait is put into the brackets. Note that �Wait(300)� makes the robot wait for 3 seconds. The number (geek-speak: the CONSTANT) inside the brackets tells it how long to wait in hundredths of a second. The program will keep doing whatever it was doing before while it�s waiting. When it�s done waiting, it moves down the line to the next command. 4.) �OnRev� task main() { OnFwd(OUT_A + OUT_C); Wait(300); OnRev(OUT_A + OUT_C); // } The �OnRev� command tells the program to reverse the motor outputs you tell it to reverse. In the example, it�s going to reverse motors A and C. Remember that if you just put �OnRev(OUT_A)�, it will only reverse motor A, while letting motor C doing whatever it was doing. 5.) �Off� task main() { OnFwd(OUT_A + OUT_C); Wait(300); OnRev(OUT_A + OUT_C); Wait(300); Off(OUT_A + OUT_C); // } Well, it�s kinda obvious what the �Off� command tells your robot to do. It turns off whatever you put into the brackets. �Off(OUT_A + OUT_C)� will turn off motors A and C. By now, can you predict what this program will do? You can test it by copying it into BricxCC (into a new file), and sending it to the RCX by pressing �Compile� which is the little BLUE triangle. Fixing errors: There are many common mistakes a beginner NQC programming (including me) often make. They include: n Not putting the �;� on the end of command lines n Typos, typing mistakes (commands should turn blue, constants turn red and motor names turn green) n Capitalization is important! Make sure commands are typed correctly n Typing in something stupid like (OUT_D) which doesn�t exist n Typing in something that is not used on your robot, like (OUT_B) n Not waiting for the program to execute command Briefing for Challenge: �Pirates!� Now that you know how to make robots move forwards, backwards and stop, can you figure out how to make a robot turn? Note that there is no �Turn� command, because if you�re a RCX, you don�t really know what turning is. You only know how to turn on or turn off motors and you know how to wait. So what do we do? Think about how we can use OnFwd and OnRev on different motors at different times to make your robot turn. Can you write a program that will make your robot go forwards for 4 seconds, turn for 2 seconds, and then go forwards again, stopping after another 4 seconds? task main() { |
||||||||||||||||||||||||||||||||
| Proposed Events | ||||||||||||||||||||||||||||||||
| NQC Guides | ||||||||||||||||||||||||||||||||
| Sign the NITRO WebBoard | ||||||||||||||||||||||||||||||||
| Last Updated: August 19th 2004 | ||||||||||||||||||||||||||||||||
| Contact the Organizer | ||||||||||||||||||||||||||||||||
| Name: | ||||||||||||||||||||||||||||||||
| Frank (Tha-An) Lin | ||||||||||||||||||||||||||||||||
| Email: | ||||||||||||||||||||||||||||||||
| [email protected] | ||||||||||||||||||||||||||||||||
| You are Roboteer number: | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
| < -------------------------------------------------------------------------------------------------------------------> | ||||||||||||||||||||||||||||||||