The Art of LEGO Mindstorms EV3 Programming
Terry Griffin
Published by No Starch Press
To my family, who make all the work worthwhile.
And to Bella, who gives me a reason to get up in the morning.
about the author
Terry Griffin has been a software engineer for more than 20 years and has spent most of that time creating software to control various types of machines. He earned a masters degree in Computer Science from the University of Massachusetts and has taught programming at the college and adult education levels. A lifelong LEGO enthusiast, he wrote The Art of LEGO MINDSTORMS NXT Programming (No Starch Press) to help his wife, a dynamic middle school science and math teacher, learn how to use these incredible robots in her classroom. He works for the Ion Microscopy Innovation Center division of Carl Zeiss, writing software to control charge particle microscopes.
about the technical reviewers
Daniele Benedettelli is known worldwide for his original LEGO robots, including his Rubiks Cube solvers and his humanoid robots. As a LEGO MINDSTORMS Community Partner (MCP), he helped to test and develop new MINDSTORMS products. He earned a masters degree in Robotics and Automation from the University of Siena in Italy. He holds educational presentations and workshops on Robotics and Information and Communications Technology around the world, teaches robotics at the high school level, and designs LEGO models as a freelancer for LEGO educational programs. Hes the author of The LEGO MINDSTORMS EV3 Laboratory (No Starch Press).
Rob Torok is a teacher in Tasmania, Australia, and has been using LEGO robotics with his students since 2001. He has mentored teams in RoboCup Junior and the FIRST Robotics Competition, and teaches an online robotics class called SmartBots. In 2010, Rob spent six months based at the Tufts Center for Engineering Education and Outreach (CEEO) in Boston and continues to work closely with the center. He is currently the content editor for both http://LEGOengineering.com/ and http://LEGOeducation.com.au/ .
acknowledgments
Id like to thank my family for all their patience while I wrote this book. Special thanks to my wife, Liz, who spent countless hours reviewing the text and tolerated the robots inhabiting the dining room table.
This work would not have been possible without the help and support of Bill Pollock and the staff at No Starch Press. It was a pleasure to work with Seph Kramer, Laurel Chun, and Jennifer Griffith-Delgado. Their knowledge and expertise were instrumental in the completion of this project.
Id also like to thank my tech reviewers, Daniele Benedettelli and Rob Torok. Their knowledge of the EV3, and robotics in general, was a big help in keeping the material relevant and technically correct.
introduction
This book is about learning how to write programs for LEGO MINDSTORMS EV3 robots. The EV3 software is a powerful tool, and this book will teach you how to get the most out of it as you acquire the programming skills necessary to create your own programs.
who this book is for
This book is for anyone who wants to learn how to create programs to control their EV3 robot, whether youre a young robotics enthusiast; an adult teaching children about robotics; a parent; a FIRST LEGO League coach; or a teacher using the EV3 in a classroom. One of my goals in writing this book was to make the material accessible to young learners while going into enough depth to help students and teachers understand the hows and whys of EV3 programming.
prerequisites
This book can be used with either the Home or Education Edition, and youll use a single general purpose robot for testing your programs. There are only a few relevant differences between the programs for each edition, and I point them out as appropriate. Almost all the material presented here applies to either edition.
No previous programming experience is required. The EV3 software is powerful but easy to use, and makes a great introductory tool for first-time programmers.
what to expect from this book
This book focuses on programming EV3 robots rather than on the mechanical aspects of building them. All of the programs in this book are designed to work with one general-purpose robot or with just the EV3 Intelligent Brick. Youll learn how to work with the core parts of the EV3 software, such as blocks, data wires, files, and variables, and how these pieces work together. Youll also learn some good programming practices, bad habits to avoid, and debugging strategies that will help you have fun while programming and keep your frustration level low.
In this book youll find step-by-step instructions and explanations for many EV3 programs, including small examples designed to help you understand exactly how EV3 programs work, as well as complete, sophisticated programs designed to perform complex behavior. Along the way, youll also see programming challenges, which will prompt you to explore EV3 programming on your own to practice the concepts youve learned.
The book begins with an introduction to the EV3 set and the software youll be using to create your programs. This is followed by the building instructions for the test robot. The next few chapters cover the basics of the EV3 software, culminating in a maze-solving program in . Thats followed by several chapters covering the more advanced language features, and the book finishes up with a sophisticated line-following program using a PID controller. Heres an overview of what youll learn in each chapter.
: LEGO and robots: a great combination
This chapter gives a tour through the features of the EV3 software. Two simple programs demonstrate how to create programs and run them on the EV3. This chapter also covers the basics on changing block parameters, adding comments, and using Port View.
: TriBot: the test robot
: sensors
This chapter covers the EV3 sensors: the Touch, Color, Ultrasonic, Infrared, Gyro and Rotation Sensors. Youll build an example program for each sensor and learn how to use Port View to monitor a sensors value while developing or running a program.
With all the basic features of EV3 programming covered, at this point youll be ready to start tackling more complex problems. In this chapter youll learn how to design, create, and debug a large wall-following program to make your robot solve a maze.