1001ICT Introduction To Programming Lecture Notes School of Information and Communication Technology Griffith University Semester 2, 2015 1
4 Lego Mindstorms 4.1 Robotics? Any programming course will set students programming problems. The problems have to be about something or the programs don t really do anything. We have selected robotics as a problem area, because: the problems are easy to describe and understand (e.g. Follow a line.); but the solutions are not always trivial; there is robotics research going on within our School; and it s more fun than most. 1001ICT Introduction To Programming 2015-2 2
4.2 Robotics theory All you need to know about robotics is three words: sense; plan; act. Sense Robots need sensors to detect their location or objects to act upon. Plan Robots need to decide what to to. This is the programming part. Act Robots need actuators (motors) to move within their environment and act upon objects. 1001ICT Introduction To Programming 2015-2 3
4.3 Lego? Lego Mindstorms are the commercial version of a project at the MIT Media Laboratory, The Programmable Brick. The problem with most mobile robotics research is the cost of designing, making and maintaining the physical robotic hardware. Lego Technics sets have a lot of interesting machine parts in a great variety of standard sizes. The addition of a computer and sensors is all that is required to make it good for prototyping new robots cheaply. A Sony AIBO (the discontinued dog) cost about $3000, and you only got one kind of robot. A Roboraptor/pet/sapien costs about $100-200, and does a lot less. A Mindstorms kit costs about $500 and can make as many kinds of robots as your creativity permits. 1001ICT Introduction To Programming 2015-2 4
4.4 The RCX The original Lego Mindstorms kits were comprised of a selection of Lego Technics components plus: the programmable brick, called the Robotic Command explorer (RCX); sensors; and motors. Programs are downloaded from a PC via a very slow infra-red interface. 1001ICT Introduction To Programming 2015-2 5
Programs are written for the RCX on a PC (Windows, Mac, Linux) and downloaded via infra-red to the RCX. Programming languages for the RCX include: Robolab Pilot graphical, but limited; Robolab Inventor graphical, fully featured; Lejos Java; Brick OS C; and Logo. Previously, for this course, we used Robolab Inventor and Lejos Java. 1001ICT Introduction To Programming 2015-2 6
4.5 The NXT The RCX has been superceded by the NXT (which does not seem to stand for anything). Robolab can be used with the NXT, though not as easily. There is a Lejos Java programming system. Though it is still under development, it is working well enough to use in this course. The NXT is much more capable than the RCX, and programs download much faster via a direct USB cable. 1001ICT Introduction To Programming 2015-2 7
4.6 NXT hardware The NXT can: receive information from sensors via 4 input ports (1, 2, 3, 4); receive information from its front panel buttons; make sounds; control motors (and/or lamps) via 3 output ports (A, B, C); receive information from motors; 1001ICT Introduction To Programming 2015-2 8
display graphics and text in its liquid crystal display (LCD); and communicate via Bluetooth. The 4 input ports: 1; 2; 3; and 4. The USB port and the 3 output ports: A; B; and C. 1001ICT Introduction To Programming 2015-2 9
The buttons: ENTER (orange); ESCAPE; LEFT; and RIGHT. Press ENTER to turn the NXT on. The Lejos start-up screen. If it starts any other way, then the NXT needs to have the Lejos firmware installed. 1001ICT Introduction To Programming 2015-2 10
The Lejos main menu screen. To find a program to run, select Files. Press ESCAPE to turn the NXT off. The file list. Program files have the extension.nxj. Select a file and press ENTER to see the options for that file. 1001ICT Introduction To Programming 2015-2 11
File options. Choose Execute program to run it. If you hear a buzz and see this screen your program has crashed because of a programming error. Press ENTER and ESCAPE together to turn the NXT off. 1001ICT Introduction To Programming 2015-2 12
If you hear a buzz and see a screen like this, the nxt programming environment has detected a programming error. Press ESCAPE to terminate the program. You will have plenty of time to explore the other menu options in labs. 1001ICT Introduction To Programming 2015-2 13
4.7 Actuators 4.7.1 Motors Both RCX (left) and NXT (right) motors may be used with the NXT. They can be run forward or backwards at power levels 0 to 100. 4.7.2 Lamps Tiny lamps may be powered at levels 0 to 100. 1001ICT Introduction To Programming 2015-2 14
4.8 Sensors 4.8.1 Touch sensors Both RCX (left) and NXT (right) touch sensors may be used with the NXT. They are simple switches. 4.8.2 Light sensors Both RCX (left) and NXT (right) light sensors may be used with the NXT. Light sensors measure brightness, they are not cameras. They have a floodlight built-in so that they can illuminate a surface to measure the brightness of reflected light. The NXT light sensor s floodlight can be turned off. 1001ICT Introduction To Programming 2015-2 15
4.8.3 Sound sensors The NXT sound sensor measures sound volume. 4.8.4 Ultrasonic proximity sensors The NXT ultrasonic proximity sensor measures the distance to a solid object. 1001ICT Introduction To Programming 2015-2 16
4.8.5 Rotation sensors Rotation (or angle) sensors measure how much an axle rotates. An RCX rotation sensor (left) registers 16 counts per full 360 degree rotation of the axle. An NXT rotation sensor is built into every NXT motor. It registers 360 counts per full 360 degree rotation of the axle. Both can count up or down, depending on the direction the axle is turning. 1001ICT Introduction To Programming 2015-2 17
4.9 Programming NXT robots To program a robot, you need to know: what sensors it has and which ports they are plugged into; what actuators it has and which ports they are plugged into; and which direction to turn motors on (forward or backward) to cause desired actions. This information will be posted on the course web site for each robot you will program. 1001ICT Introduction To Programming 2015-2 18
4.10 Section summary This section covered: why we are learning programming using robotics problems; how robots sense, plan, and act; a brief description of the RCX; an introduction to the NXT, its inputs, outputs, and buttons; how to run a program using the Lejos firmware s menus; the kinds of motors, lamps and sensors; and what you need to know about a robot to program it and where to find it. 1001ICT Introduction To Programming 2015-2 19
4.11 End of section feedback questions Send us your answers to these questions any time you like by clicking on them. What was the most useful topic in this section? What was the least useful topic in this section? What was the least clear topic in this section? What topic in this section would you like to know more about? Did you find an error in this section? 1001ICT Introduction To Programming 2015-2 20