Spec:sec control

Overview
The secondary controller object has a structure illustrated in Figure 1, and is very similar to textbook examples like Figure 2.

The basic idea is that the frequency error $$\Delta f$$ is
 * 1) Converted to a power error via bias factor $$B$$
 * 2) Adjusted with respect to the current deviation from schedule of participating units (and potentially intertie flows) via $$\epsilon_{\text{unit}}$$
 * 3) Integrate the error via a PID controller, where by default only the integrator branch is non-zero.
 * 4) Distribute the output $$\Delta P$$ to participating units via participation factor $$\alpha_i$$.

Additionally, sampling blocks are added to allow for different information input and output rates. A low pass filter is also possible on each unit channel to smooth out the signal to individual units.

Inter-Tie Modelling
Inter-tie modeling is incorporated into the unit error input, as illustrated in Figure 3. The scheduled flow, $$P^{\star}_i$$, and actual flow $$P_i$$, on this inter-tie are positive if they correspond with the definition and negative otherwise. A multiplier $$c_i$$ is introduced to account for this directionality, and is equal to 1 for all generators. Considering Microgrid A:
 * When $$P^{\star}_i - P_i$$ is positive, either not enough power is exported ($$P^{\star}_i > 0$$) or too much power is imported ($$P^{\star}_i<0$$). Either way, more generation from the units in Microgrid A is needed, which is achieved by increasing its error signal, $$P_{\text{err}}^A$$. Therefore, $$P^{\star}_i - P_i$$, should be multiplied by $$c_i = -1$$, to negate the minus sign in the summation point.
 * When $$P^{\star}_i - P_i$$ is \emph{negative}, either too much power is exported ($$P^{\star}_i > 0)$$, or too little power is imported ($$P^{\star}_i<0$$). Either way, less generation from the units in Microgrid A is needed, which is achieved by decreasing its error signal, $$P_{\text{err}}^A$$. This is similarly achieved by setting multiplier $$c_i = -1$$.

The logic for Microgrid B is equal and opposite to that of Microgrid A, and therefore $$c_i=1$$. These rules are summarized in the following table:

Anti-Windup
Since the secondary controller predominantly works as an integrator and various sampling intervals are also involved, some anti-windup functionality is important. A few different options are considered.

Zero In Deadband
This option simply zeros the integrator state,  when the the frequency is within its deadband and all tie-line flows are within tolerance.

Feedback PID Output
This is a common feedback mechanism used on sampled outputs, and is shown in Figure 1. The difference of the PID output, $$\text{PID}_{\text{output}}$$ and the sampled output $$\Delta P$$ is fed back to the weighted error signal prior to the integration stage. If we consider $$K_d = K_p = 0$$ then there are two cases: $$x_i[t+1] = \text{PID}_{\text{output}}[t+1] = \text{PID}_{\text{output}}[t] + \Delta t \cdot (K_i\epsilon[t])$$ $$x_i[t+1] = \text{PID}_{\text{output}}[t+1] = \text{PID}_{\text{output}}[t] + \Delta t \cdot (K_i\epsilon[t] - \text{PID}_{\text{output}}[t])$$
 * 1) Sampling: In this case $$\text{PID}_{\text{output}} = \Delta P$$, the feedback signal is 0 and the the integration step is
 * 1) No Sampling: In this case $$\Delta P = 0$$ and the feedback signal is $$-\text{PID}_{\text{output}}$$, leading the integration step to be:

Note the the no-sampling case looks very similar to a low pass filter, which helps keep the integrator output from increasing too rapidly between sample instances. In a more general case where $$K_d \neq K_p \neq 0$$, the integrator output and PID output don't line up as neatly, but the concept behind the method remains the same.

Feedback Integrator
This is the same as the Feedback PID Ouput except that the integrator output is fed back rather than the whole PID output. The relationship to a low pass filter will therefore be preserved even if $$K_d \neq K_p \neq 0$$, however, the feedback might not be as effective if the integrator gain is relatively small compared to the other two PID gains.

Requirements/Limitations

 * 1) The secondary control object operates in  deltamode only, but will transition back to QSTS.
 * 2) Currently only inverter_dyn and  diesel_dg are supported as generators. Any power flow  link object can be used as an inter-tie.
 * 3) The frequency is currently only measured at the parent node of the secondary controller object.

Global Secondary Controller Object Parameters
The following parameters are general to the secondary controller object.

Unit Specific Parameters
The unit specific parameters are provided via the  parameter (access via player). Properties are provided in a specific order, which is listed below in column Pos (1 indexed).

There are three different key words that can be specified when passing unit specific parameters:
 * : is used to add new objects to the secondary controller
 * : is used to modify parameters of objects already participating in secondary control
 * : is used to to remove an object from the secondary controller

To pass information to the secondary controller:
 * 1) Specify the appropriate key word
 * 2) List the unit name and relevant properties (to skip a property simply leave it blank)
 * 3) List additional units, separated by a line in csv or   in glm.
 * 4) Repeat steps 1-3 for more key words as necessary

There are two possible input formats: The csv method is recommended in general as it is more robust, easy to read, and does not risk exceeding the allotted array buffer of 1024 characters.
 * 1) glm
 * 2) csv

The syntax is demonstrated using the following example. Initially (at ) the secondary controller contains:

At  gen2 is removed from secondary control. In response gen1's $$\alpha_i = 1$$ and $$ P_{\text{max}} = 1 $$, and the tie line tolerance is changed to $$\pm 15\%$$

glm syntax
The syntax for direct glm input is: t0 ADD gen1, 0.7,, , 0.9, 0.3; gen2, 0.3, 0.5, 0.5, , , 1; tie1, -1, , , 0.1, 0.1; t1 REMOVE gen2; MODIFY gen1, 1,, , 1; tie1, , , , 0.15, 0.15;

csv syntax
For the csv input two files would be needed:

ADD gen1, 0.7,, , 0.9, 0.3 gen2, 0.3, 0.5, 0.5,, , 1 tie1, -1,, , 0.1, 0.1

which looks something like:

and REMOVE gen2 MODIFY gen1, 1,, , 1 tie1,, , , 0.15, 0.15

which looks something like:

The player would then have contain: t0 t0.csv t1 t1.csv

Generator Properties
The following properties are implemented in the inverter_dyn and  diesel_dg models to allow interaction with the secondary controller. Note: Any future object that should also be capable of interaction with the secondary object will likely need these properties.

The current set point, $$ P^{\star} $$, is calculated as $$ P^{\star} = P_{\text{set}} + \Delta P^{\star} $$

Link Properties
The following properties are implemented in the link object to allow interaction with the secondary controller as a tie-line.

Initialization
Since QSTS mode is a steady state formulation there is no frequency error. Therefore, all states are initialized to zero.

Return to QSTS Operation
The controller keeps track of two conditions:
 * 1) Frequency within deadband: $$ -\epsilon \leq \Delta f \leq \epsilon $$
 * 2) Tie-lines within tolerance: $$ P_{\text{min}} \leq (P^{\star}_i - P_i)/P^{\star}_i \leq P_{\text{max}} \forall i$$

When both of these conditions are met for the length of two output sampling periods ($$ 2T_s$$) then the secondary controller requests to return to QSTS mode.

Multiple Secondary Controllers With Inter-Ties
The following glm snippet shows how to set up a controller including inter-ties as shown in Figure 4. Only the controller for Microgrid 2 is shown for brevety.

Main : // Controller Parametrization object sec_control { name secondary_controller_MG2; flags DELTAMODE; parent meter_50; deadband 0.001; //1 mHz deadband B 1.7476; //MW/Hz kiPID 0.04; // pu/s; kpPID 0; //pu Ts 0.2; // 200ms output sample time Ts_f 0.1; // 100ms frequency sample time Ts_P 0.2; // 200ms unit error and inter-tie sample time anti_windup FEEDBACK_PIDOUT; participant_input "sec_cntrl_MG2_part_init.csv"; }; //Triggers to set the tie-line schedules object player{ name MG1_MG2_tie_set; flags DELTAMODE; parent microgrid_switch1; file "tielineset.player"; property set_pdispatch; }; object player{ name MG2_MG3_tie_set; flags DELTAMODE; parent microgrid_switch4; file "tielineset.player"; property set_pdispatch; };

Inv2, 1 microgrid_switch1, 1 microgrid_switch4, -1



Low Pass Filter
The following example uses the low pass filter option via a default value. The  also shows a custom value for $$P_{\text{min}}$$ for Gen4.

Main : object sec_control { name secondary_controller; flags DELTAMODE; parent node_150; deadband 0.001; //1 mHz deadband B 12.1187; //MW/Hz kiPID 0.2; // pu/s; kpPID 0; //pu Ts 1; Tlp 1; anti_windup FEEDBACK_PIDOUT; participant_input "sec_cntrl_part_init.csv"; };

Gen1, 0.3 Gen4, 0.2,,,,0.3 Inv1, 0.2 Inv3, 0.3