Page 91 - Ai Robogenius
P. 91

Logic–Control

                 Control blocks are used to decide when, how and how often the robot should carry out an action.
                 They enable the robot to make choices, repeat tasks and pause at the right times.
                 Some of the important Control blocks are as follows:

                             Block                                          Description

                   repeat  10                    This block repeats the enclosed code a fixed number of times,
                                                 allowing the robot to execute actions repeatedly for a specified
                                                 count.



                   forever                       This block repeats the enclosed code endlessly until the program
                                                 stops. It’s ideal for tasks that should run without interruption, like
                                                 maintaining movement or sensors.


                   while                         The code  inside  this  block  keeps  looping  as  long as  the  given
                                                 condition is true. It’s useful for continuous actions that depend on
                                                 real-time conditions.


                                                 This block  pauses  the  program  until  a  specified  condition
                   wait until                    becomes true. Once the condition is met, the program resumes
                                                 its execution.


                   if       then                 This block runs the code only when a specific condition is true. It’s
                                                 used to make the robot perform actions based on conditions that
                                                 must be met.


                   if      then
                                                 This block checks a condition; if the condition is true, it runs one set

                   else                          of instructions. If false, it runs a different set, offering a decision-
                                                 making path.




                    if         then

                                                 This block checks multiple conditions in order. It first checks if the
                    else if    then              first condition is true and runs the corresponding code. If not, it
                                                 checks  the next condition  and continues  until all  options  have
                                                 been evaluated, running the final set of instructions if none are
                    else
                                                 true.









                                                                         Sensors, Logic and Maze Navigation
                                                                                                                    89
   86   87   88   89   90   91   92   93   94   95   96