Book Image

Learning Lego Mindstorms EV3

By : Gary Garber
Book Image

Learning Lego Mindstorms EV3

By: Gary Garber

Overview of this book

Table of Contents (19 chapters)
Learning LEGO MINDSTORMS EV3
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
10
Other Programming Languages
Index

Preface

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.

What this book covers

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.

What you need for this book

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:

  • EV3 rechargeable battery (Part # 45501), which is $60

  • EV3 Ultrasonic Sensor (Part # 45504), which is $30

  • EV3 Infrared Sensor (Part # 45509), which is $30

  • EV3 Infrared beacon (Part # 45508), which is $30

  • EV3 Gyro Sensor (Part # 45505), which is $30

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/.

Who this book is for

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.

Conventions

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."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

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 , 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.

Customer support

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.

Downloading the example code

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.

Downloading the color images of this book

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.

Errata

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

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 with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.