NQCtutorial - Programming Lego Robots using NQC (Version...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
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
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
- 2 - 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.
Background image of page 2
- 3 - Contents Preface____________________________________________________________2 Acknowledgements_____________________________________________________________________________2 Contents ___________________________________________________________3 I. Writing your first program ____________________________________________5 Building a robot________________________________________________________________________________5 Starting RCX Command Center__________________________________________________________________ 5 Writing the program ____________________________________________________________________________6 Running the program ___________________________________________________________________________7 Errors in your program __________________________________________________________________________7 Changing the speed_____________________________________________________________________________8 Summary ______________________________________________________________________________________8 II. A more interesting program___________________________________________9 Making turns __________________________________________________________________________________9 Repeating commands ___________________________________________________________________________9 Adding comment ______________________________________________________________________________ 10 Summary _____________________________________________________________________________________ 11 III. Using variables __________________________________________________12 Moving in a spiral _____________________________________________________________________________ 12 Random numbers ______________________________________________________________________________ 13 Summary _____________________________________________________________________________________ 13 IV. Control structures_________________________________________________14 The if statement _______________________________________________________________________________ 14 The do statement ______________________________________________________________________________ 15 Summary _____________________________________________________________________________________ 15 V. Sensors_________________________________________________________16 Waiting for a sensor ___________________________________________________________________________ 16 Acting on a touch sensor _______________________________________________________________________ 16 Light sensors _________________________________________________________________________________ 17 Summary _____________________________________________________________________________________ 18 VI. Tasks and subroutines _____________________________________________19 Tasks ________________________________________________________________________________________ 19
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/01/2010 for the course ENG 100 taught by Professor Wang during the Spring '10 term at University of Washington.

Page1 / 43

NQCtutorial - Programming Lego Robots using NQC (Version...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online