The purpose of this exercise is to 0) Answer questions regarding the automata not provided in the last exercise. 1) Set the event properties of all component automata. 2) Compose FSA of the physical system and the desired specifications. 3) Test whether the desired specifications can be achieved and correct the specifications as needed. 5) Build a supervisor automata that achieves the specifications. 6) Test whether the automata indeed achieves the specifications.

**Step 0**:
Everyone should have models of the following automata.
For the tap changer: *T_sensor, T_switch, T_timer, T_fail, T_con1, T_con2, T_con3*.
For the capacitor bank: *C_sensor, C_switch, C_timer, C_fail, C_con1, C_con2, C_con3*.
Note, the automata *T_con2, T_con3* (*C_con2, C_con3*, respectively) may be combined into a single automata depending on how you modelled the specifications described in lecture.

**Step 1:**
Copy and paste the command **par_comp** into your FSA directory. Use the command *par_comp* to construct the FSA of the physical system (T_3) and the FSA of the specifications (T_6) as follows. For the physical system,

- run par_comp
- enter 3 for the number of automata
- one by one enter FSA names: T_sensor, T_swtich, T_timer
- enter the name of the composite FSA: T_3

For the specification automata

- run par_comp
- enter 6 for the number of automata
- one by one enter FSA names: T_sensor, T_swtich, T_timer, T_con1, T_con2, T_con3
- enter the name of the composite FSA: T_6

Note that throughout we're ignoring the component automata T_fail. Addition of this automata significantly increases all the computation times without affecting the results.
You should now have two new automata in your FSA director called T_6 and T_3. *How many states do these automata have? Which automata has more states?*

**Step 2:**
Use Matlab function *setEvents.m* to ensure all events in your composed automata are set correctly and then export the automata back into UMDES format. In other words, for the tap changer, define the following structures Matlab:

- E_tap_c = {'tp' 'tm' 'tton' 'ttoff'};
- E_tap_o = {'vm' 'vp' 'vn' 'tf' 'ttstop'};

and for the capacitor bank

- E_cap_c = {'cp' 'cpp' 'cm' 'cmm' 'tcon' 'tcoff'};
- E_cap_o = {'qm' 'qp' 'qn' 'cf' 'tcstop'};

Next import T_6 and T_3 automata into Matlab. Then use the function script_setEvents.m to change the observability and controllability characteristics of the automata. Finally, use the previously provided Matlab function MATLAB2UMDES to export T_6 and T_3 back into UMDES.

**Step 3:**
Copy and paste the commands **ctrb** and **obs** into your FSA directory. In order for the specification automata to be achievable, the automata T_6 must be both controllable and observable with respect to the physical system automata T_3. To test controllability,

- run the command ctrb
- enter the name of the specification automata T_6
- enter the name of the physical system automata T_3
- enter 0 to use the event properties defined in T_3
- enter 'Yes' to see all states that violate controllability.

The output should say the system is controllable.

To test observability, first create two comma separated text files defining the set of controllable events (tp, tm, tton, ttoff) and observable events (vm, vp, vn, tf, ttstop), or download these files below (**T_Ec**, **T_Eo**) . Next do the following:

- run the command obs
- enter the name of the physical system automata T_3
- enter the name of the specification automata T_6
- enter the name of the file containing the controllable events T_Ec
- enter the name of the file containing the observable events T_Eo
- enter 0, we do not require the quadruple FSAS M

The output should confirm observability of T_6 with respect to T_3, T_Ec, T_Eo.

**Step 5:**
Download the Matlab script that converts an observer automata into a supervisor automata: BuildSupervisor.m. Copy and paste the UMDES command **obsvr** into your FSA directory.
First step in building a supervisor is to construct an observer of the specification automata.

- first, to keep the length of the state names short, renumber the states in the automata T_6, using the UMDES command
**rename_states**. You can save the output file under the original name T_6 and discard the mapping file. - run the command obsvr
- enter the name of the FSA for which you want to construct an observer T_6
- we do not need a .o file output, hence enter whatever name you want for the following question
- we do want an fsm file output, enter the name of the observer automata T_6obs
- we want to observer automata to concatenate the states, enter 2

You should now have a new automata in your FSA director called T_6obs. *How many states does this automata have?*
The second step in building an observer automata is to go through all the observer automata states and add self loops for all unobservable events allowed in the specification automata. Thankfully, we have a Matlab function that will do this for us.

- import T_6obs and T_6 into Matlab
- run the function BuildSupervisor.m (for instructions type help BuildSupervisor) to build the supervisor automata T_6sup
- export T_6sup back into UMDES format

You should now have a new automata in your FSA director called T_6sup. *How many states does this automata have?*

**Step 6:**
If the theory is indeed correct, then the supervisor automata we build in the previous step should define PLC logic that yields the specifications when applied to the physical system. To verify this

- construct a parallel composition of the supervisor T_6sup and the physical system T_3 to build an FSA of the supervised system T_S
- copy and paste the UMDES commands
**incl**and**equiv**into your FSA directory - run the command
*incl*to test whether the language generated by T_S is included in the specification language T_6

Of course T_S and T_6 should be equivalent. To test their equivalence

- run the command
*equiv*

The output should confirm the language equivalence.

That's it for today.