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

The CHK My Block


The CHK My Block is used to make a check to see if the robot is upright or has fallen down. If the pwr variable block has an absolute value that is less than 100, timer 2 is reset. When the timer switch block measures a reading less than 1, then the state of the ok variable block is not touched and the balance loop keeps running. The initial state of the ok variable block was false. If the pwr variable block has an absolute value that is equal to 100 (we know it cannot be greater), timer 2 is not affected (thus having a larger value), and the ok variable writes a true statement, which causes the balance loop to end.

Looking in more detail, if the logic switch block receives a true value, then Timer Sensor block 2 is reset. Lastly, you saw a Timer Sensor block 2 during the RST My Block. So timer 2 was reset at the beginning of the main programming loop. The compare switch block will change the logic variable block ok to a true condition if timer 2 is greater than 1. If you...