35,99 €
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 247
Veröffentlichungsjahr: 2015
Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: January 2015
Production reference: 1200115
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78398-502-9
www.packtpub.com
Cover image by Gary Garber
Author
Gary Garber
Reviewers
Barbara Bratzel
Michael duPont
Jeroen Hartsuiker
David Lechner
Diego "Kartones" Muñoz
Geoff Shannon
Commissioning Editor
Akram Hussain
Acquisition Editor
Neha Nagwekar
Content Development Editor
Susmita Sabat
Technical Editor
Vivek Arora
Copy Editor
Laxmi Subramanian
Project Coordinator
Neha Thakur
Proofreaders
Simran Bhogal
Stephen Copestake
Maria Gould
Ameesha Green
Paul Hindle
Indexers
Hemangini Bari
Mariammal Chettiyar
Monica Ajmera Mehta
Graphics
Valentina D'silva
Production Coordinator
Shantanu N. Zagade
Cover Work
Shantanu N. Zagade
Gary Garber teaches physics, math, and engineering at Boston University Academy. Gary is the president of the New England Section of the American Association of Physics Teachers and has led dozens of professional development workshops in education at both the local and national levels.
Gary runs the Boston University FIRST Robotics program. He has run and hosted numerous robotics workshops in VEX, Tetrix, and LEGO platforms. He has run dozens of LEGO robotics tournaments and spoken on robotics education at both local and national conferences. His robotics team has worked with Engineers Without Borders, NASA, and the National Science Teachers Association on a variety of engineering and education projects.
He is currently an educational consultant, working to develop new software tools for the classroom, at the Tufts Center for Engineering Education and Outreach, which is a pioneer in LEGO Robotics Education. He is the author of Instant LEGO MINDSTORMS EV3, Packt Publishing. He currently resides in Massachusetts, US. When he is not playing with LEGO, robots, or toy trains, he enjoys spending time with his wife, Catalina, and their two children, Alejandro and Leonardo.
I would like to thank the people of the Tufts Center for Engineering Education and Outreach for teaching me about LEGO robotics and helping make this book possible, including Chris Rogers, Ethan Danahy, Barbara Bratzel, and Bill Church. I would like to thank the students of Boston University Academy, in particular, the class of 2016, who remind me of how much fun students of all ages can have with LEGO. I would also like to thank Alejandro and Leonardo for reteaching me how to play with LEGO and making me watch the LEGO movie over and over again.
Barbara Bratzel is a science teacher at the Shady Hill School, a PreK-8 independent school in Cambridge, Massachusetts. In addition, she is a consulting teacher at the Center for Engineering Education and Outreach at Tufts University. Her most recent book, STEM by Design, a collection of classroom activities using the LEGO EV3, was published in February 2014.
Michael duPont is a maker, pilot, and theatre technician based in Central Florida. He recently graduated from Centre College in Danville, Kentucky. His specialties include microcontrollers such as the Raspberry Pi and Arduino, robotics, wearables, and other small electronics. You can find many of his open source projects on GitHub and on his website (http://mdupont.com/).
Jeroen Hartsuiker (born in 1971) played with LEGO Technic until his early teens. His dark ages (time when a person stops collecting and using the Danish bricks) ended while visiting LEGOLAND Billund in 1998, when he attended a workshop exploring the first generation of the MINDSTORMS Robotics Invention System. Since then, he has owned and used every generation of the LEGO robot, and he wrote courseware and delivered a presentation on how to control the MINDSTORMS NXT robot using Microsoft® Robotics Developer Studio. He occasionally contributes a module to the Great Ball Contraption (GBC) at LEGO WORLD in the Netherlands. Furthermore, a MINDSTORMS robot is sometimes used to make the software-development classes he teaches even more interesting. You can visit his blog at www.dotnetjes.nl.
David Lechner works mostly as a freelance computer programmer and occasionally as a "Mad Scientist" teaching robotics as an after-school program in elementary schools. He also just completed his rookie year, coaching a FIRST LEGO League team, and has devoted much of his time to reverse engineering the EV3 as a core contributor to the ev3dev project. Prior to being self-employed, he spent 8 years doing industrial automation in the water and wastewater industry. He has a bachelor's degree in electrical and computer engineering from Oklahoma State University.
Diego "Kartones" Muñoz, more commonly known by his nickname, Kartones, is a multidisciplinary developer who lives in Madrid, Spain. Having worked for more than 12 years with all kinds of desktop, mobile, and web applications, he has used quite a few languages such as C++, C#, PHP, and more recently, Ruby and JavaScript.
Regarding LEGO MINDSTORMS, he fell in love with RCX and then the NXT, both of which he liked to code in C instead of the default firmware and brick system. Now, with MINDSTORMS EV3, he seeks to code robot logic in Node.js. He's also been a technical reviewer for LEGO Mindstorms EV3 Essentials, Packt Publishing.
He loves learning about anything he comes across and keeps a few blogs. He sometimes speaks at events or user groups, and he would love to do more open source work. He can be reached at http://portfolio.kartones.net.
I'd like to acknowledge my girlfriend and my cats, for without their patience with my endless hours around computers and technology, I wouldn't be so happy.
Geoff Shannon has been an enthusiastic hardware hacker from a young age; his first job was building automated production equipment with Provel Inc. He has a bachelor's degree in computer science and recently attended a batch at Hacker School in New York City. In late 2013, he started working with LEGO robots by exploring the leJOS project and using it to run a Clojure REPL on his EV3. He currently lives in Seattle, WA, working as a software engineer.
To see what Geoff is currently working on and thinking about, check out his blog at www.zephyrizing.net. You can also follow him on Twitter at @RadicalZephyr.
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.
Welcome to Learning LEGO MINDSTORMS EV3.
The LEGO MINDSTORMS EV3 is a programmable LEGO brick that can control motors and receive feedback from a wide range of sensors. In this book, you will learn how to write programs in the LEGO MINDSTORMS EV3 software. This book is a practical guide that will show you how to advance beyond the basic lessons included in your EV3 kit, combine core programming commands, and implement tested design principles when building your own robot using the LEGO MINDSTORMS EV3 kit. You will become familiar with resources beyond your EV3 kit and enhance your robot designs.
The MINDSTORMS EV3 kit contains over 500 plastic interlocking parts. These parts are made with high-precision moulds. The LEGO Technic bricks in your kit include beams, axles, pines, gears, shafts, and bushings that will allow you to design a wide variety of robots. The LEGO bricks in your LEGO MINDSTORMS kit are compatible with all LEGO bricks made over the past 50 years.
The LEGO MINDSTORMS EV3 Intelligent Brick contains an ARM9 processor running Linux. This allows you to program the brick with a wide variety of languages, such as C, C++, Java, Python, and LabVIEW, but we will focus on the official LEGO MINDSTORMS EV3 software. This software is a visual programming language. Programming in the LEGO MINDSTORMS EV3 software consists of dragging-and-dropping blocks onto a programming canvas. You draw wires to connect the command blocks, such as command flow wires and data wires. There are blocks that store data, control motors, acquire sensor data, and initiate flow structures such as loops and switches. The beauty of a visual programming language is that with a programming hierarchy, you can create easy-to-follow programs where you can visually see the entire program at once.
The EV3 Intelligent Brick connects to motors and a wide variety of sensors, which LEGO builds via electrical wires, including Touch Sensors, Ultrasonic Sensors, Light Sensors, Infrared Sensors, and Gyro Sensors. The motors have built-in shaft encoders, which allow you to control exactly how far they turn. There is an even larger array of sensors produced by third-party vendors that you can use with your EV3. You can download and run your computer programs on the EV3 via a USB cable, Bluetooth, or Wi-Fi. All these features will take your LEGO MINDSTORMS EV3 beyond the category of a simple toy into an impressive robotics kit, which can be used to explore your environment and navigate a complex set of obstacles.
Chapter 1, Engineering Notebook, covers how to use the Content Editor to keep a multimedia record of your work building robots.
Chapter 2, Mechanical Design, covers how to use gears to increase either speed or torque in your robots.
Chapter 3, Drive Train and Chassis, explains how to build a chassis and attach either wheels or treads to create a moving robot.
Chapter 4, Sensors and Control, covers how to use sensors to receive feedback from your environment.
Chapter 5, Interacting with EV3, explains how to control your EV3 via the brick buttons, the infrared beacon, Bluetooth, and Wi-Fi.
Chapter 6, Output from EV3, covers how to send output from the EV3 brick using the display screen, lights, and the speaker.
Chapter 7, Advanced Programming, covers topics such as loops, switches, arrays, My Blocks, and navigation using sensor feedback.
Chapter 8, Advanced Programming and Control, covers advanced navigation techniques, including proportional controllers, PID controllers, course correction, and triangulation.
Chapter 9, Experiment Software and Data Logging, explains how to use the data logging features of the Educational Edition of the LEGO MINDSTORMS software.
Chapter 10, Other Programming Languages, provides a brief overview of RobotC and LabVIEW, which are the next steps up from using the LEGO MINDSTORMS software.
Chapter 11, Communication between Robots, explains how to send messages via Bluetooth to allow two EV3 robots to communicate, send commands, and collaborate.
Chapter 12, Advanced Robot – Gyro Boy, reviews and explains in depth the Gyro Boy program written by LEGO.
You will need a LEGO MINDSTORMS EV3 kit to build the robots in this book. There are two versions of the kit: the LEGO MINDSTORMS EV3 Home Edition (Lego Set # 31313) and the LEGO MINDSTORMS EV3 Education Core Set (Lego Set # 45544). Both of these kits can be purchased for about $350. I have provided build instructions in this book, so you can build your robots no matter which set you have. The hardware differences include the type of wheels, treads, and casters. Between the kits, most of the pieces are the same but of different colors. The Home Edition has a Touch Sensor, Color Sensor, Infrared Sensor, and Infrared beacon. The Education Edition has a Touch Sensor, Color Sensor, Gyro Sensor, Ultrasonic Sensor, and a rechargeable battery. You can buy all of these parts at http://shop.lego.com/en-US/ or any general toy supplier.
If they did not come with your kit, you may want to buy the following:
You will need the LEGO MINDSTORMS EV3 software. There are two versions of the software. The Home Edition of the software is free and can be downloaded from www.lego.com/mindstorms. The Education Edition of the software needs to be purchased from LEGO Education for $100 from https://education.lego.com. The main differences between the software editions are that the Education Edition includes data logging software and the aesthetics of the splash page. This book was written with version 1.1.1 of the LEGO MINDSTORMS EV3 software. At the time of publication, version 1.1.1 is only available for the Home Edition. The Education Edition is currently available in version 1.1.0. As a caution, in version 1.1.0 of the LEGO MINDSTORMS software, Bluetooth communication for the EV3 brick is not compatible with newer versions of Mac OS X.
You will receive the most bang-for-your-buck by purchasing the Education Edition of the hardware kit from LEGO Education and downloading the Home Edition of the software. Besides http://www.amazon.com/, you will find the best secondary market to purchase LEGO bricks at http://bricklink.com/.
The LEGO MINDSTORMS software has built-in tutorials that explain very basic usage of the software. The tutorials also provide high-end examples of what can potentially be built with the MINDSTORMS kits. The programs written to accompany these high-end examples are wonderfully complex, but lacking in documentation. A major gap in the materials provided by LEGO is that they do not help you past those first simple steps to build and program advanced robots.
This book is for anyone who wants to develop his or her LEGO MINDSTORMS EV3 robots past those first simple steps. I assume you have gone through the basic tutorials provided by LEGO. I provide build instructions for a base robot to which you can add sensors and work through the advanced programming algorithms provided in this book. Students and coaches working with FIRST LEGO League teams and World Robot Olympiad teams will benefit from using the techniques described in this book to develop their ability to navigate a playing field using sensors.
In this book, you will find a number of styles of text that distinguish between different kinds of information.
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Do not press the Finish button yet."
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from: https://www.packtpub.com/sites/default/files/downloads/5029OS_ColoredImages.pdf.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.
As described by LEGO, the EV3 MINDSTORMS software Content Editor is a digital workbook into which you can enter text, images, sound, and videos. There are a lot of great features that are described in brief by LEGO in the EV3 software help menus. In this chapter, we will look at the following topics:
Without using those words, with the Content Editor, LEGO has created a digital engineering notebook. An engineering notebook is more than just a record of your work. An engineering notebook allows you to record (and communicate) your initial designs, construct the model, and iterate your building and programming. In the engineering design process, it is important to record your mistakes so that you have a record of what didn't work. You should always put dates on the work you have done.
According to the U.S. Next Generation Science Standards, we can present a simplified version of the engineering process in the following diagram:
The process of iteration and optimization is critical to building good models. Particularly when it comes to programming, you will find you need to make numerous revisions to your program so that your robot has the desired performance. The preceding image is an abbreviated version of what is often presented as the engineering design process. There is no single engineering design process. There are many variations on the preceding theme, starting with a problem and ending with a solution. The common steps include the following:
The iterative nature of the engineering design process is important. Often, if will not follow a straightforward path between these steps. With this number of steps, you need to document your work and record successes and distresses. Additionally, the evolution of thought and the solutions for one challenge might easily be translated to another. The Content Editor built into the EV3 software easily fulfills the task of a multimedia-based engineering notebook.
When you start a new project in the EV3 software, the Content Editor will automatically open up on the upper right-hand side of the Programming Canvas.
The Content Editor will automatically open up in View mode, as shown in the preceding screenshot. If you click on the Pencil icon (encircled in the preceding screenshot), you can switch from View mode to Edit mode; this allows you to enter information.
When entering Edit mode, the EV3 software limits the icons displayed to five basic functions such as Text and Image. You can access the full range of the Content Editor functions by clicking on the red cross sign in the upper right-hand corner:
The basic features of the Content Editor, shown in the preceding screenshot, include (going clockwise from the top) Text, Image, Building Instructions, Video, Table, Webcam, Document, and Sound. If you want to return to the abbreviated version of this menu, you can click on the Document icon. By themselves, many of these entries might seem limited. However, using the selections in Page Setup, you can combine these features into a powerful record of your work.
When you create a new page in the Content Editor (by clicking on the plus sign), it will open up the templates shown in the following screenshot:
I particularly like to have text on the bottom panel to describe to the reader what they are looking at in any videos and images, or building instructions on the top panel. If you click on the icon I have circled in red in the previous screenshot, you will see two panels appear as shown in the following screenshot:
Next, let's insert an image into the top window in the Content Editor. Click on the Image icon. When working with the image, you will find that you can only upload JPG and PNG images. Then try typing some text into the bottom window after clicking on the Text icon, as shown in the following screenshot:
You will see that the Text Toolbar allows you to set the fonts and the formatting. When working with text, I like to add text actions. If you click on Add Action, encircled in the following screenshot, several options are presented:
A drop-down menu will appear with these options as shown in the following screenshot. The actions are similar to a hyperlink. They allow you to open programs or a website with the page or move to a different page. This is particularly useful if you have numerous pages in the Content Editor for your program. For example, you could create a table of contents at the beginning.
After you have created several pages, you should try to use the function Go To Named Page. A good use for naming your pages is to create dates so that you know when you did your work. You might choose to name your pages with the date you created it on. I also like the Go To Program option. At this point, the EV3 software Version 1.1 doesn't allow you to choose programs that are part of a different project. You can also use a Text Button to emphasize the text action, as shown in the following screenshot:
Embedded into the EV3 software are model instructions for several different robots. These instructions are presented in the Content Editor and follow a certain format spread out over three pages.
However, the program does not appear until you reach the third page. The mechanism to allow this is called Page Action. By moving to the next page, you can trigger actions such as opening a program or project. This is useful if you don't want your reader to be distracted by what is coming next, or you want it to be a surprise. In order to trigger the release of a program, follow the steps shown in the following screenshots. First open the Page Action menu.
If you select Go To Program, then you will be asked to choose a program, as shown in the following screenshot, so that, when the page is opened, the program will open simultaneously. This can also be useful if you are using different programs for the same model. For instance, you could include a video and/or text description of the execution of that program in a page of the Content Editor, but not open the program until the page is selected.
Using Computer-aided Design (CAD) software can be useful on several fronts. Once you learn how to use this kind of software, you will find it can be quicker to build models digitally than with real bricks. Real engineers always design their robots virtually before building the actual product. This is because the process of trial and error involved with trying to fit parts together can be time consuming and expensive. If you have a large inventory of (unorganized) LEGO bricks beyond those included in your EV3 kit, you might build something digitally before you go searching for the bricks. At this point, it is worth mentioning the two most common CAD programs: LEGO Digital Designer and LDraw.