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

Loop and the Gyro Sensor


Now we will repeat this exercise using the Gyro Sensor that comes with the Educational Version of the EV3 kit. If you have the Home version, you might consider buying the LEGO Gyro Sensor or the Gyro or Compass sensor from HiTechnic or other third-party vendors. You can buy the LEGO EV3 Gyro Sensor directly from LEGO, part number 45505, for about $30. In the following screenshot, you can see that the loop is the same except we will use a move to turn while steering until the Wait block is triggered by a change in state of the Gyro Sensor by 90 degrees:

Before you run the program, you need to make sure the robot is absolutely still. It is critical to calibrate the Gyro Sensor. You can do this either by unplugging it and plugging it back in while the robot is stationary, or by changing the mode of the Gyro Sensor. You can change the mode using Port View or by writing this into your program. We can now run this program. If you notice that your Gyro values keep changing...