write a Mathlab script where: The tanks manufactured by your company can have an
ID: 674310 • Letter: W
Question
write a Mathlab script where:
The tanks manufactured by your company can have an emergency discharge valve with a given constant volumetric flow rate (in gallons per minute)1 . Modify your script from Task 1 above to determine the time to empty a full tank that is connected to a given valve. Note: The design engineers want to experiment with valves of varying flow capacities for a given tank without having to reenter the dimensions of the tank. Idea: Separate the problem of defining the dimensions of the tank and the computation of the timetoempty into three scripts:
define_tank.m asks for the dimensions of the tank.
define_valve.m asks for the volumetric flow rate of the discharge valve.
discharge_time.m outputs the time it takes for the full tank to empty.
The Design engineer then calls define_tank whenever she needs to analyze a new tank. She then uses define_valve whenever she wants to change the valve. After the tank and the valve are defined, she can determine to discharge time by calling discharge_time.
Explanation / Answer
A1 = 0.0256; % Area of tank 1 (hunits^2)
A2 = 0.0477; % Area of tank 2 (hunits^2)
h2 = 0.241; % Height of tank 2, fixed by overflow (hunits)
fb = 3.28e-5; % Bias stream flow (hunits^3/sec)
fs = 0.00028; % Flow scaling (hunits^3/sec/funit)
th = 1.0; % Hot water supply temp (tunits)
tc = 0.0; % Cold water supply temp (tunits)
tb = tc; % Cold bias stream temp (tunits)
alpha = 4876; % Constant for flow/height relation (hunits/funits)
beta = 0.59; % Constant for flow/height relation (hunits)
he variable fs is a flow-scaling factor that converts the input (0 to 1 funits) to flow in hunits^3/second. The constants alpha and beta describe the flow/height relationship for tank 1:
h1 = alpha*f1-beta.
Nominal Tank Models
We can obtain the nominal tank models by linearizing around the following operating point (all normalized values):
The nominal model for tank 1 has inputs [ fh; fc] and outputs [ h1; t1]:
Figure 2: Step responses of Tank 1.
The nominal model for tank 2 has inputs [|h1|;|t1|] and output t2:
Figure 3: Step responses of Tank 2.
Actuator Models
There are significant dynamics and saturations associated with the actuators, so we'll want to include actuator models. In the frequency range we're using, we can model the actuators as a first order system with rate and magnitude saturations. It is the rate limit, rather than the pole location, that limits the actuator performance for most signals. For a linear model, some of the effects of rate limiting can be included in a perturbation model.
We initially set up the actuator model with one input (the command signal) and two outputs (the actuated signal and its derivative). We'll use the derivative output in limiting the actuation rate when designing the control law.
Figure 4: Valve actuator dynamics.
Anti-Aliasing Filters
All measured signals are filtered with fourth-order Butterworth filters, each with a cutoff frequency of 2.25 Hz.
Uncertainty on Model Dynamics
Open-loop experiments reveal some variability in the system responses and suggest that the linear models are good at low frequency. If we fail to take this information into account during the design, our controller might perform poorly on the real system. For this reason, we will build an uncertainty model that matches our estimate of uncertainty in the physical system as closely as possible. Because the amount of model uncertainty or variability typically depends on frequency, our uncertainty model involves frequency-dependent weighting functions to normalize modeling errors across frequency.
For example, open-loop experiments indicate a significant amount of dynamic uncertainty in the t1 response. This is due primarily to mixing and heat loss. We can model it as a multiplicative (relative) model error Delta2 at the t1 output. Similarly, we can add multiplicative model errors Delta1 and Delta3 to the h1 and t2 outputs as shown in Figure 5.
Figure 5: Schematic representation of a perturbed, linear two-tank system.
To complete the uncertainty model, we quantify how big the modeling errors are as a function of frequency. While it's difficult to determine precisely the amount of uncertainty in a system, we can look for rough bounds based on the frequency ranges where the linear model is accurate or poor, as in these cases:
This data suggests the following choices for the frequency-dependent modeling error bounds.
Figure 6: Relative bounds on modeling errors.
Now, we're ready to build uncertain tank models that capture the modeling errors discussed above.
Next, we randomly sample the uncertainty to see how the modeling errors might affect the tank responses
Figure 7: Variability in responses due to modeling errors (Tank 1).
Setting up a Controller Design
Now let's look at the control design problem. We're interested in tracking setpoint commands for t1 and t2. To take advantage of H-infinity design algorithms, we must formulate the design as a closed-loop gain minimization problem. To do so, we select weighting functions that capture the disturbance characteristics and performance requirements to help normalize the corresponding frequency-dependent gain constraints.
Here is a suitable weighted open-loop transfer function for the two-tank problem:
Figure 8: Control design interconnection for two-tank system.
Next, we select weights for the sensor noises, setpoint commands, tracking errors, and hot/cold actuators.
The sensor dynamics are insignificant relative to the dynamics of the rest of the system. This is not true of the sensor noise. Potential sources of noise include electronic noise in thermocouple compensators, amplifiers, and filters, radiated noise from the stirrers, and poor grounding. We use smoothed FFT analysis to estimate the noise level, which suggests the following weights:
The error weights penalize setpoint tracking errors on t1 and t2. We'll pick first-order low-pass filters for these weights. We use a higher weight (better tracking) for t1 because physical considerations lead us to believe that t1 is easier to control than t2.
Figure 9: Frequency-dependent penalty on setpoint tracking errors.
The reference (setpoint) weights reflect the frequency contents of such commands. Because the majority of the water flowing into tank 2 comes from tank 1, changes in t2 are dominated by changes in t1. Also t2 is normally commanded to a value close to t1. So it makes more sense to use setpoint weighting expressed in terms of t1 and t2-t1:
where w1, w2 are white noise inputs. Adequate weight choices are:
Finally, we would like to penalize both the amplitude and the rate of the actuator. We do this by weighting fhc (and fcc) with a function that rolls up at high frequencies. Alternatively, we can create an actuator model with fh and d|fh|/dt as outputs, and weight each output separately with constant weights. This approach has the advantage of reducing the number of states in the weighted open-loop model.
Building a Weighted Open-Loop Model
Now that we have modeled all plant components and selected our design weights, we'll use the connect function to build an uncertain model of the weighted open-loop model shown in Figure 8.
H-infinity Controller Design
By constructing the weights and weighted open loop of Figure 8, we have recast the control problem as a closed-loop gain minimization. Now we can easily compute a gain-minimizing control law for the nominal tank models:
The smallest achievable closed-loop gain is about 0.9, which shows us that our frequency-domain tracking performance specifications are met by the controller k0. Simulating this design in the time domain is a reasonable way to check that we have correctly set the performance weights. First, we create a closed-loop model mapping the input signals [ t1ref; t2ref; t1noise; t2noise] to the output signals [ h1; t1; t2; fhc; fcc]:
Now we simulate the closed-loop response when ramping down the setpoints for t1 and t2 between 80 seconds and 100 seconds:
Next, we add the simulated outputs to their steady state values and plot the responses:
In this code, we plot the outputs, t1 and t2, as well as the height h1 of tank 1:
Figure 10: Step response of H-infinity controller k0.
Next we plot the commands to the hot and cold actuators.
Figure 11: Actuator commands for H-infinity controller k0.
Robustness of the H-infinity Controller
The H-infinity controller k0 is designed for the nominal tank models. Let's look at how well its fares for perturbed model within the model uncertainty bounds. We can compare the nominal closed-loop performance gamma0 with the worst-case performance over the model uncertainty set. (see "Uncertainty on Model Dynamics" for more information.)
Figure 12: Performance analysis for controller k0.
The worst-case performance of the closed-loop is significantly worse than the nominal performance which tells us that the H-infinity controller k0 is not robust to modeling errors.
Mu Controller Synthesis
To remedy this lack of robustness, we will use dksyn to design a controller that takes into account modeling uncertainty and delivers consistent performance for the nominal and perturbed models.
As before, we can simulate the closed-loop responses with the controller kmu
Figure 13: Step response of mu controller kmu.
These time responses are comparable with those for k0, and show only a slight performance degradation. However, kmu fares better regarding robustness to unmodeled dynamics.
Figure 14: Performance analysis for controller kmu.
Note that wcgain also returns local sensitivities of the worst-case gain to the variability of each uncertain element. The sensitivities imply that the peak on the worst-case gain curve is most sensitive to changes in the range of delta2.
A1 = 0.0256; % Area of tank 1 (hunits^2)
A2 = 0.0477; % Area of tank 2 (hunits^2)
h2 = 0.241; % Height of tank 2, fixed by overflow (hunits)
fb = 3.28e-5; % Bias stream flow (hunits^3/sec)
fs = 0.00028; % Flow scaling (hunits^3/sec/funit)
th = 1.0; % Hot water supply temp (tunits)
tc = 0.0; % Cold water supply temp (tunits)
tb = tc; % Cold bias stream temp (tunits)
alpha = 4876; % Constant for flow/height relation (hunits/funits)
beta = 0.59; % Constant for flow/height relation (hunits)
he variable fs is a flow-scaling factor that converts the input (0 to 1 funits) to flow in hunits^3/second. The constants alpha and beta describe the flow/height relationship for tank 1:
h1 = alpha*f1-beta.
Nominal Tank Models
We can obtain the nominal tank models by linearizing around the following operating point (all normalized values):
The nominal model for tank 1 has inputs [ fh; fc] and outputs [ h1; t1]:
Figure 2: Step responses of Tank 1.
The nominal model for tank 2 has inputs [|h1|;|t1|] and output t2:
Figure 3: Step responses of Tank 2.
Actuator Models
There are significant dynamics and saturations associated with the actuators, so we'll want to include actuator models. In the frequency range we're using, we can model the actuators as a first order system with rate and magnitude saturations. It is the rate limit, rather than the pole location, that limits the actuator performance for most signals. For a linear model, some of the effects of rate limiting can be included in a perturbation model.
We initially set up the actuator model with one input (the command signal) and two outputs (the actuated signal and its derivative). We'll use the derivative output in limiting the actuation rate when designing the control law.
Figure 4: Valve actuator dynamics.
Anti-Aliasing Filters
All measured signals are filtered with fourth-order Butterworth filters, each with a cutoff frequency of 2.25 Hz.
Uncertainty on Model Dynamics
Open-loop experiments reveal some variability in the system responses and suggest that the linear models are good at low frequency. If we fail to take this information into account during the design, our controller might perform poorly on the real system. For this reason, we will build an uncertainty model that matches our estimate of uncertainty in the physical system as closely as possible. Because the amount of model uncertainty or variability typically depends on frequency, our uncertainty model involves frequency-dependent weighting functions to normalize modeling errors across frequency.
For example, open-loop experiments indicate a significant amount of dynamic uncertainty in the t1 response. This is due primarily to mixing and heat loss. We can model it as a multiplicative (relative) model error Delta2 at the t1 output. Similarly, we can add multiplicative model errors Delta1 and Delta3 to the h1 and t2 outputs as shown in Figure 5.
Figure 5: Schematic representation of a perturbed, linear two-tank system.
To complete the uncertainty model, we quantify how big the modeling errors are as a function of frequency. While it's difficult to determine precisely the amount of uncertainty in a system, we can look for rough bounds based on the frequency ranges where the linear model is accurate or poor, as in these cases:
This data suggests the following choices for the frequency-dependent modeling error bounds.
Figure 6: Relative bounds on modeling errors.
Now, we're ready to build uncertain tank models that capture the modeling errors discussed above.
Next, we randomly sample the uncertainty to see how the modeling errors might affect the tank responses
Figure 7: Variability in responses due to modeling errors (Tank 1).
Setting up a Controller Design
Now let's look at the control design problem. We're interested in tracking setpoint commands for t1 and t2. To take advantage of H-infinity design algorithms, we must formulate the design as a closed-loop gain minimization problem. To do so, we select weighting functions that capture the disturbance characteristics and performance requirements to help normalize the corresponding frequency-dependent gain constraints.
Here is a suitable weighted open-loop transfer function for the two-tank problem:
Figure 8: Control design interconnection for two-tank system.
Next, we select weights for the sensor noises, setpoint commands, tracking errors, and hot/cold actuators.
The sensor dynamics are insignificant relative to the dynamics of the rest of the system. This is not true of the sensor noise. Potential sources of noise include electronic noise in thermocouple compensators, amplifiers, and filters, radiated noise from the stirrers, and poor grounding. We use smoothed FFT analysis to estimate the noise level, which suggests the following weights:
The error weights penalize setpoint tracking errors on t1 and t2. We'll pick first-order low-pass filters for these weights. We use a higher weight (better tracking) for t1 because physical considerations lead us to believe that t1 is easier to control than t2.
Figure 9: Frequency-dependent penalty on setpoint tracking errors.
The reference (setpoint) weights reflect the frequency contents of such commands. Because the majority of the water flowing into tank 2 comes from tank 1, changes in t2 are dominated by changes in t1. Also t2 is normally commanded to a value close to t1. So it makes more sense to use setpoint weighting expressed in terms of t1 and t2-t1:
where w1, w2 are white noise inputs. Adequate weight choices are:
Finally, we would like to penalize both the amplitude and the rate of the actuator. We do this by weighting fhc (and fcc) with a function that rolls up at high frequencies. Alternatively, we can create an actuator model with fh and d|fh|/dt as outputs, and weight each output separately with constant weights. This approach has the advantage of reducing the number of states in the weighted open-loop model.
Building a Weighted Open-Loop Model
Now that we have modeled all plant components and selected our design weights, we'll use the connect function to build an uncertain model of the weighted open-loop model shown in Figure 8.
H-infinity Controller Design
By constructing the weights and weighted open loop of Figure 8, we have recast the control problem as a closed-loop gain minimization. Now we can easily compute a gain-minimizing control law for the nominal tank models:
The smallest achievable closed-loop gain is about 0.9, which shows us that our frequency-domain tracking performance specifications are met by the controller k0. Simulating this design in the time domain is a reasonable way to check that we have correctly set the performance weights. First, we create a closed-loop model mapping the input signals [ t1ref; t2ref; t1noise; t2noise] to the output signals [ h1; t1; t2; fhc; fcc]:
Now we simulate the closed-loop response when ramping down the setpoints for t1 and t2 between 80 seconds and 100 seconds:
Next, we add the simulated outputs to their steady state values and plot the responses:
In this code, we plot the outputs, t1 and t2, as well as the height h1 of tank 1:
Figure 10: Step response of H-infinity controller k0.
Next we plot the commands to the hot and cold actuators.
Figure 11: Actuator commands for H-infinity controller k0.
Robustness of the H-infinity Controller
The H-infinity controller k0 is designed for the nominal tank models. Let's look at how well its fares for perturbed model within the model uncertainty bounds. We can compare the nominal closed-loop performance gamma0 with the worst-case performance over the model uncertainty set. (see "Uncertainty on Model Dynamics" for more information.)
Figure 12: Performance analysis for controller k0.
The worst-case performance of the closed-loop is significantly worse than the nominal performance which tells us that the H-infinity controller k0 is not robust to modeling errors.
Mu Controller Synthesis
To remedy this lack of robustness, we will use dksyn to design a controller that takes into account modeling uncertainty and delivers consistent performance for the nominal and perturbed models.
As before, we can simulate the closed-loop responses with the controller kmu
Figure 13: Step response of mu controller kmu.
These time responses are comparable with those for k0, and show only a slight performance degradation. However, kmu fares better regarding robustness to unmodeled dynamics.
Figure 14: Performance analysis for controller kmu.
Note that wcgain also returns local sensitivities of the worst-case gain to the variability of each uncertain element. The sensitivities imply that the peak on the worst-case gain curve is most sensitive to changes in the range of delta2.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.