IfA 1.3 Lab Manual
by Oliver Kaiser, Urs Baumann, Tobias Geyer,
Urban Mader, Ioannis Lymperopoulos, Akin Sahin, Stefan Richter
Chügelimat Process Control
In this experiment different balls are moved through a "ball exchange machine".
The control logic which has to be developed is coded in Stateflow. Stateflow is a development tool based on Matlab/Simulink where state charts are drawn graphically
and subsequently directly compiled. This allows a shorter control development time
as compared with direct procedural logic languages (C/C++).
Figure 1: "Ball Exchange Machine" - Chügelimat
The automation of industrial processes can often be accomplished through structural logic design or "rule" control.
With Stateflow a tool is available in which it is possible to create state charts in an intuitive, graphical way and compile them directly. Stateflow is running in the Matlab/Simulink environment. In order to complete the lab practice efficiently, it's advisable to first read the "Introduction to Stateflow" and the "Getting Started with Simulink" manuals available on internet.
Stateflow is used in this experiment to control a model of a "coin exchange machine" named Chügelimat (Chügeli is swiss German and means little ball), where balls are used instead of coins. Balls with values of 1, 2, 5 and 10 are acceptable and appropriate exchange stock is handed out, however Chügelimat should ignore invalid balls.
The electromechanical setup of the Chügelimat is shown in Figure 1. During the exchange procedure the ball must go through different stations of Chügelimat: the entrance, the diameter measurement station, the weight measurement station (balance) and the sorting bins station. In the sorting bins station a valid ball is stored in one of the four magazines (1, 2, 5 and 10) and if possible exchange stock is handed out (see table 1). If insufficient exchange stock is available in the magazines or an invalid ball is thrown in, then the ball is ejected.
In the experiment, the processes for the entrance and the specification of the ball (diameter and weight measurement) should be coded in Stateflow. The remaining processes (sorting and exchanging the ball) to complete the control of Chügelimat already exist and have to be synchronized with the written processes. In the following sections the processes are explained more precisely. After this lab practice you will:
- have designed a control for a simple process and
- know the possibilities and limits of modern, graphical software tools.
|Value of thrown in ball||Value of ejected ball|
|1 x 1er||1 x 1er|
|1 x 2er||2 x 1er|
|1 x 5er||2 x 2er + 1 x 1er|
|1 x 10er||2 x 5er|
Table 1: Ball classification at sorting bins
2. Description of Chügelimat
The electromechanical setup of the Chügelimat, shown in Figure 1, consists of the following functional groups:
- diameter measurement (DMS)
- weight measurement (balance)
- sorting bins
The processes for the first three functional groups, namely, the entrance, DMS and balance sections should be coded in Stateflow. These functional groups are described in detail in the following sections.
The notations used in this chapter are the same as those in the prepared Stateflow model. All digital signals to and from Chügelimat work with logic levels where 0 = off and 1 = active.
Your task is to implement the following three functional groups and synchronize them to the existing ones as described in the following chapters.
The slot where balls can be entered into Chügelimat is called "Entrance". A light barrier is used to detect when a ball is present and can be entered into the system.
Tables 2 and 3 illustrate the relationship between sensor and actuator signals of Chügelimat and the corresponding Stateflow variables.
|Light barrier located at entrance||inEntrance||Activated approx. 1 sec. after ball is detected by light barrier. Deactivated as soon as ball is thrown out of entrance.|
Table 2: Sensors at Entrance
|Entrance gate||ejectEntrance||By activation the ball is sent to DMS section.|
Table 3: Actuators at Entrance
The entrance gate should open when there is
- a ball in front of the entrance, and
- there is no ball in the diameter measurement station.
Hint: You should introduce a variable to determine if there is a ball in the DMS section, which may be set to 1 if there is a ball and reset to 0 if there is no ball.
2.2 Diameter Measurement Station (DMS)
This section describes the diameter measurement station. In figure 5 the setup of the DMS station is illustrated schematically. Three inductive sensors and two motors are used in this station. The sensors are on as soon as they are in the same height with a metal plate. The ball diameter is measured in terms of time.
Initially the lower plate of the bar driven by the stepper motor is at the level of the sensor at bottom and hence the sensorBottom is on. When the ball enters the DMS section the stepper motor moves the ball upwards. The sliding frame is pushed upwards until the sensorMeasure is turned on by the upper plate of the sliding frame. The time elapsed from the start of the stepper motor's operation to the instance when sensorMeasure is on should be assigned as the diameter of the ball. As soon as the sensorMeasure is on stepper motor moves downwards until the sensorBottom is on again. When the sensorBottom is on the ball is ejected by the ejection motor. SensorTop is used to stop the stepper motor in case it moves upwards without a ball.
In order to take correct measurements, the motor must always be switched off when the sensorBottom is on. Tables 4 and 5 illustrate the relationship between sensor and actuators signals of Chügelimat and the corresponding Stateflow variables.
Ejection out of the diameter measurement station is allowed, when:
- a ball is in the diameter measurement station,
- the sensorBottom is on and
- there is no ball in the balance area.
Hint: You should introduce a variable to determine if there is a ball in the balance section, which may be set to 1 if there is a ball and reset to 0 if there is no ball.
Figure 5: Side view of the diameter measurement station
|SensorBottom||sensorBottom||Activated when a metal plate is detected|
|SensorTop||sensorTop||Activated when a metal plate is detected|
|SensorMeasure||sensorMeasure||Activated when a metal plate is detected|
|Diameter||diameter||The time elapsed from the start of the motor's upwards motion until the sensorMeasure is on should be assigned as the diameter of the ball|
Table 4: Sensors of DMS Station
|Ejector DMS||ejectDMS||Activation causes the ball to be ejected.|
|Stepper motor on/off||motorEnable||0 <=> motor off, 1 <=> motor on|
|Stepper motor direction||motorDirection||0 <=> upwards, 1 <=> downwards|
Table 5: Actuators of DMS Station
Here the weight of the ball is determined. The value can be read in by Stateflow via the "analog" variable weightMeasured.
Tables 6 and 7 illustrate the relationship between sensor and actuator signals of Chügelimat and the corresponding Stateflow variables.
|Weight||weightMeasured||This analog input can be read in by Stateflow as soon as a ball is on the balance.|
Table 6: Sensors of Balance
|Ejector balance||ejectBalance||Activation causes the ball to be ejected.|
Table 7: Actuators of Balance
Ejecting a ball is allowed, when
- a ball is in the balance,
- the sorting transaction of the last ball is finished and
- the sorting flaps in the next section are set.
To fulfill the last two conditions the program has to communicate with the sort algorithms already implemented in Stateflow. This communication is treated in the next section.
3. Interface to Chügelimat Framework
A part of the flow chart to control Chügelimat, containing the sorting and the balance sensor and stepper motor initialization algorithms is already prepared (see figure 6). For communication with the corresponding processes the following variables and events have been globally predefined in the Stateflow chart.
- setFlaps (event): Must be generated, as soon as the ball weight is determined. Required by the sort algorithm, i.e. initiates the setting of the sort flaps.
- flapsPositioned (event): Generated by the sort algorithm as soon as the sort flaps are positioned for a measured ball in the balance.
- diameter (variable): Diameter determined in the DMS station must be stored in this variable.
- weight (Variable): Weight determined in the balance must be stored in this variable.
Figure 6: Prepared framework in Stateflow with initialization and simple sort algorithms.
4. Problem formulation
- Read the "Introduction to Stateflow". Users unpracticed in Simulink should read "Getting Started with Simulink" too.
- Make yourself familiar with the framework (see Figure 6). Try to understand the flow of a ball passing through Chügelimat (i.e. which signals occur, what commands must be generated). The framework can be downloaded from here.
- Sketch a possible state chart for control of the entrance, the diameter and the weight measurement. Consider the specifications in the previous chapters. Additional hints:
- The three processes should run parallel.
- Ensure that the sensorBottom is ON in the DMS station when a ball is rolling in (especially for the first ball).
- Be careful to overwrite the values for diameter and weight of the old ball with the values of the new ball.
- Use the variables and events defined in chapter 3 to communicate with the framework.
- Stateflow syntax:
*Place conditions and comparisons on transitions
*Place assignments inside the states of the flow chart
The opposite is not implicitly prohibited but in practice causes errors.
4.2 Lab Practice
- Turn on the PC.
- Double click the desktop link called "Ifa 1.3 Chuegelimat". This will start Matlab, and download all the necessary framework files to C:/Scratch/Chuegelimat. Open the Simulink model "chuegelimat.mdl" which contains the control blocks. This is the file in which you will write your new control algorithms (beside the existing ones Sort/, Balanceinit/ and Motorinit). If Matlab crashes, run the script "Ifa 1.3 Chuegelimat restart" on your desktop.
- Before implementing your algorithm run the Simulink model "chuegelimat" to initialize the balance sensor and the stepper motor. TURN ON THE DAQ CARD BEFORE YOU RUN THE SIMULINK FILE "chuegelimat.mdl"!
- Implement your processes for the entrance, the diameter and the weight measurement. How to define new variables is described in the "Introduction to Stateflow". Build the model after each coded process to eliminate errors subsequently (how is described in the next point).
- While implementing your algorithm the stepper motor may get stuck, which may damage the motor severely. Whenever that happens you should run the Simulink file "initialize.mdl", which first brings the motor back to sensorBottom position and then stops it.
- Put different balls at the entrance of Chügelimat and check if they are sorted properly.