Page 864 - Mechatronics with Experiments
P. 864

850   MECHATRONICS
                              of the iteration set, the block executes. After each execution, “Condition” is checked. The
                              “IC” port condition is checked only at the beginning. If the “IC” condition is FALSE, the
                              block is not executed.
                                   Again, as many inports and outports can be added in the sub-system and the desired
                              logic can be defined. There is a parameter for this block named “maximum number of
                              iterations.” It is advisable to set this parameter to a finite value. Simulink ®  executes the
                              block endlessly as long as the “while (condition)” is TRUE. Unless it is certain that the
                              “while (condition)” will become FALSE at some point in the simulation, a maximum
                              number of iterations should be specified to avoid endless loops in this block.

                              3.
                                 do                         % See "Do-while" block
                                     ...
                                     ...
                                 while(condition)

                              The sub-system block is executed at least once. After that, the status of the “Condition”
                              input port is checked. If true, the sub-system block is executed again, until the “Condition”
                              is false. As many input ports and output ports can be defined, as well as any desired logic
                              defined inside the sub-system block. The number of iterations (execution) within a sampling
                              period follow the same rules for the “while block.”


                              4.
                                 if (condition)       % See "if" and "if-action" blocks
                                     ...
                                 elseif
                                     ...
                                 elseif
                                     ...
                                 else
                                     ...
                                 end

                              5.
                                 switch case (variable)        % See "Switch case" and "Action
                                                                  blocks"
                                      case 1:
                                        ....
                                      case 2:
                                        ....
                                      case 3:
                                        ....
                                      default:
                                        ....
                                 end

                              “If” and “Switch” statement blocks allow us to select a block from a set of blocks to execute.
                              Each “If” and “Switch” block is accompanied by “Action” blocks. There must be as many
                              action blocks as there number of sections to “if - elseif - elseif - else” and “Switch case”
                              statements.


                              Example    Let us consider the pendulum problem and its nonlinear differential equation
                              which describes the relationship between the torque at the base and the angular position of
                              the pendulum (Figure A.26). We will simulate the response of the pendulum as a result of
   859   860   861   862   863   864   865   866   867   868   869