In this example, the objective is to find a design such that the RMS values of displacement, velocity, and acceleration are minimized. The RMS signals are computed as:(1)
$\begin{array}{l}R1=\underset{0}{\overset{T}{\int }}{x}^{2}dt\\ R2=\underset{0}{\overset{T}{\int }}{\stackrel{˙}{x}}^{2}dt\\ R3=\underset{0}{\overset{T}{\int }}{\stackrel{¨}{x}}^{2}dt\end{array}$

Three responses of type RMS2 are created for defining these values. The objective to minimize the sum of these three responses (R1 + R2 + R3).

We also create a constraint (based on response type ResponseExpression) to make sure that the gain of PID controller would not increase infinitely. The constraint has the form:(2)
$\phi \triangleq \text{1}-{k}_{P:}^{\text{2}}-{k}_{I}^{\text{2}}-{k}_{D}^{\text{2}}<0$

The addResponses method for this model is shown below:

  def addResponse(self, time):
"""
We minimize the influence of disturbance on the block
R1: Integral(acceleration**2,time)
R2: Integral(velocity**2,time)
R3: Integral(Displacement**2,time)
R4: Constraint (1 - kp**2 - ki**2 - kd**2 < 0)
"""
# Define the desired profile
zero_vector = [0.0 for i in time]
targetValue = zip(time,zero_vector)

# Measure the RMS acceleration deviation from desired
expr = 'ACCZ({I},{J})'.format(I=self.block.cm.id, J=self.rm.id)
self.R1 = RMS2 (
label         ='acceleration',
targetValue   = targetValue,
measuredValue = expr,
)

# Measure the RMS velocity deviation from desired
expr = 'VZ({I},{J})'.format(I=self.block.cm.id,J=self.rm.id)
self.R2 = RMS2 (
label         = 'velocity',
targetValue   = targetValue,
measuredValue = expr,
)

# Measure the RMS displacement deviation from desired
expr = 'DZ({I},{J})'.format(I=self.block.cm.id,J=self.rm.id)
self.R3 = RMS2 (
label         = 'displacement',
targetValue   = targetValue,
measuredValue = expr,
)

# The constraint
self.R4 = ResponseExpression(
label='sum of squares',
function = '1 - kp**2 - kd**2 - ki**2',
symbols = ["kp", "kd", "ki"],
variables = [self.dv_kp, self.dv_kd, self.dv_ki]
)