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 control program


The second part of the program, the control loop BHV, has its own Start block, which allows this part of the program to run in parallel to the main programming loop. At the beginning, the st Variable block sets the robot state to 0 or resting. The program then enters the BHV Loop block or the robot behavior loop.

A numeric switch block examines which of the three robot states the robot is in, with 0 for resting state, 1 for waking state, and 2 for the active state. The resting state (state 0) is the default case of the switch block. In this state, the variables blocks Cdrv and Cstr are set to 0. The Cdrv variables block (Control drive) is used to control the speed at which the robot drives either forward or backwards. The Cstr variable block (Control steering) is used to control in which direction the robot steers. Setting both to 0 will result in no motion by the robot.

After the Gyro Sensor has been calibrated by the gOS My Block in the main program, the control state...