La lecture en ligne est gratuite
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres
Télécharger Lire

Tutorial NQC

De
43 pages
using NQC (Version 3.03, Oct 2, 1999) by Mark Overmars Utrecht University P.O. Box 80.089, 3508 TB Utrecht the NetherlandsDepartment of Computer ScienceProgramming Lego Robots Preface The Lego MindStorms and CyberMaster robot s are wonderful new toys from which a wide variety of robots can be constructed, that can be programmed to do all sorts of complicated tasks. Unfortunately, the software that comes with the robots is, although visually attractive, rather limited in functio nality. Hence, it can only be used for simple tasks. To unleash the full power of the robots, you need a different programming environment. NQC is a programming language, written by Dave Baum, that was especially designed for the Lego robots. If you have n ever written a program before, don't worry. NQC is really easy to use and this tutorial will tell you all about it. Actually, programming the robots in NQC is a lot easier than programming a normal computer, so this is a chance to become a programmer in an To make writing programs even easier, there is the RCX Command Center. This utility helps you to write your programs, to send them to the robot, and to start and stop the robot. RCX Command Center works almost like a text processor, but with some extras. This tutorial will use RCX Command Center (version 3.0 or higher) as programming environment. You can download it for free from the web at the address http:/ ...
Voir plus Voir moins

Vous aimerez aussi

   
     
 
Programming Lego Robots using NQC
(Version 3.03, Oct 2, 1999)      
 by Mark Overmars             Department of Computer Science Utrecht University P.O. Box 80.089, 3508 TB Utrecht the Netherlands
Preface  The Lego MindStorms and CyberMaster robots are wonderful new toys from which a wide variety of robots can be constructed, that can be programmed to do all sorts of complicated tasks. Unfortunately, the software that comes with the robots is, although visually attractive, rather limited in functionality. Hence, it can only be used for simple tasks. To unleash the full power of the robots, you need a different programming environment. NQC is a programming language, written by Dave Baum, that was especially designed for the Lego robots. If you have never written a program before, don't worry. NQC is really easy to use and this tutorial will tell you all about it. Actually, programming the robots in NQC is a lot easier than programming a normal computer, so this is a chance to become a programmer in an easy way.  To make writing programs even easier, there is the RCX Command Center. This utility helps you to write your programs, to send them to the robot, and to start and stop the robot. RCX Command Center works almost like a text processor, but with some extras. This tutorial will use RCX Command Center (version 3.0 or higher) as programming environment. You can download it for free from the web at the address  http://www.cs.uu.nl/people/markov/lego/  RCX Command Center runs on Windows PC’s (’95, ’98, NT). (Make sure that you ran the software that comes with the Lego set at least once, before using RCX Command Center. The Lego software installs certain components that RCX Command Center uses.) The language NQC can also be used on other platforms. You can download it from the web at address  http://www.enteract.com/~dbaum/lego/nqc/  Most of this tutorial also applies to the other platforms (assuming you use NQC version 2.0 or higher), except that you loose some of the tools and the color-coding.  In this tutorial I assume that you have the MindStorms robot. Most of the contents also applies to the CyberMaster robots although some of the functionality is not available for those robots. Also the names of e.g. the motors are different so you will have to change the examples a little bit to make them work. Acknowledgements I would like to thank Dave Baum for developing NQC. Also many thanks to Kevin Saddi for writing a first version of the first part of this tutorial.
 
- 2 -   
Contents  Prf_________________________________________________________________2 e ace ledgemen Acknow ts 2 ____________________________________________________________________ Contents 3 ________________________________________________________________ I. Writing your first program ________________________________________________ 5 Building a _______________________________________________________________________  robot 5  ngCX Command C___________________________________________________________ Starti R enter 5 Writing the program____________________________________________________________________6  ng the prog___________________________________________________________________ Runni ram 7 your program _______ ___________________________________________________________ Errors in 7 Changing the speed 8 ____________________________________________________________________  Sumry____________________________________________________________________________  ma 8 II. A more interesting program_______________________________________________ 9 Making turns_________________________________________________________________________9  Repeatingmman___________________________________________________________________ co ds 9  ddingcomment_____________________________________________________________________ A 10 ry___________________________________________________________________________11 Summa III. Using variables _____________________________ 12 __________________________ Moving in a spiral____________________________________________________________________12  _____________________________________________________________________ Random numbers 13 Summay___________________________________________________________________________13 r ________________________________ _____________________ IV. Control structures 14 The if statement 14  ______________________________________________________________________  _____________________________________________________________________ The do statement 15 Summary_____________________________________________________________________15 ______ ________________________________ ______________________________ V. Sensors 16 ngor a___________________________________________________________________16 Waiti f sensor g _______________________________________________________________16 Actin on a touch sensor Light sensors________________________________________________________________________17 ummay___________________________________________________________________________18 S r _________________________________________________ VI. Tasks and subroutines 19 Tasks 19  ______________________________________________________________________________ Subroutines 20 __________________________________________________________________________   _______________________________________________________________________ Inline functions 20  Defining macros________________________________________________21 _______ ______________ y___________________________________________________________________________22 Summar VII. Making music ________ 23 _ ______________________________________________  Built-in sounds 23 _______________________________________________________________________ Playing sic________________________________________________________________________23 mu y___________________________________________________________________________ Summar 24  VIII. More about motors 25 __________________________________________________ Stopping gently __ ________ 25  ____________________________________________________________  Advanced commands 25 __________________________________________________________________ Varying motor sp__________________________________________________________________26 eed Summary ________________ 26 ___________________________________________________________ IX. More about sensors 27 ___________________________________________________ Sensor mode and type__________________________________________________________________27  ____________________________________________________________________ The rotation sensor 28 Putting multiple sensors on one input______________________________________________________28 Making a proximity sensor______________________________________________________________29 
 
- 3 -
Un pour Un
Permettre à tous d'accéder à la lecture
Pour chaque accès à la bibliothèque, YouScribe donne un accès à une personne dans le besoin