None W02B_Modeling_Fundamentals

Challenge:

A friend, who is a successful Lafayette graduate and engineer, likes mountain getaways, fast cars and wants to be proactive about preserving the environment. So they drive an all-electric Tesla Model S roadster and own property in the Catskills.

The problem is that they love to take long winding routes to and from their mountain home. By the time they arrive, Tesla roadster is usually nearly depleted of charge. Because of the rustic existence at the cabin, there is no power provided by an electric utility, so it is not possible to install a traditional charging station for the car.

So, after a thorough environmental impact study and after obtaining the proper permits, they decide to build their own small hydroelectric power station to provide electricity to the cabin. They have enlisted your help with the design of some of the control system that can provide DC power for lights and small electronics, but still have enough voltage (450V) to charge the car at steady state. When the system is completely finished, it should display a number for the "time to charge" on a screen based on the current water level in the dam, and control the dam's operation to achieve an efficient charge.

Your first step towards completing this challenge is to design a control system to perform a step response test on your friend's dam system, and interpret the data to determine what sort of mathematical model may be appropriate to model the dam's behavior.

Being an ME480 student, you will use the same overall process as you normally would to help your friend:

image.png

Because you have never designed a control system for a hydroelectric dam before, you need to gather some information about how these systems operate. Some basics of hydroelectric dams are provided in the YouTube video below:

Because your friend is interested in predicting how long their car will need to be plugged in to the dam power system in order to charge, you decide that it is important to build a detailed mathematical (ME352-style) model for the Dam system your friend built.

Model Development: Mathematical Models

There are many strategies for developing equations of motion that describe the dynamics (motion) of a system. You've been exposed to several in your career as an engineering student. In this course, the dynamic models you will see are differential equations that relate a model's inputs to its outputs. In this course, we will use one of two general approaches to develop a system's governing differential equation:

  1. Data-driven approach: Conduct one or more experiments, and allow the experiments' results to guide model assumptions, complexity and structure. Validate the model using a different set of experiments that show the model has predictive power.
  2. Bottom-up approach: Begin with physics-based models of each component using appropriate assumptions. Build a model by connecting the system's components and capturing their interactions using the principles of continuity and compatibility.

Both of these approaches can be valid. Often, some combination of both strategies is necessary before a model is complete. Today, we will focus on the first steps towards building a model using a Data-driven approach.

Model Validation: Dam Simulator

Since we can't collect data from an actual dam, we'll use the simulator below to get the information we need to model your friend's dam behavior.

In order to determine what may be required of your mathematical model, you wish to collect data from the dam to get a more precise idea of how it acts. The simulator provides you with a sufficient set of Boolean variables you can use to interace with the system. Initially you will design a control system for the dam that simply allows you to collect data.

As part of your efforts to collect data from the dam, you instrumented the generator, turbine, and reservoir. A data logger you bought records data any time a "true" boolean input is given to one of its digital pins. The data logger will stop capturing and save the data when the pin sees a falling edge of the voltage (transition from true to false) on this pin. Once a falling edge is detected, the system automatically prompts you for a location where the data can be saved as a text file. The simulator shows the format for the columns of the collected data file.

Your code goes above.

Use only variable names you see in the simulator as well as the variables that are declared below. These variables are already declared as global variables in the simulator, as they would need to be in Arduino code, so you do not have to re-declare them. Their data types are shown for reference only.

boolean VALVE //When true valve is open
int VAVLEPERCENT //How far the valve will open when VALVE is true

boolean REC// when true data will be recorded
//when REC goes from true to false (the "falling" edge), data will be saved to a file

The data file will contain a series of data columns using the format below

column 1 2 3 4 5 6
data time gauge height (ft) turbine pressure (kPa) turbine speed (RPM) generator volts house volts

Exercise 1: Due at MIDNIGHT on Monday, September 13

Controller Design and Validation: Data collection

Design and implement a finite state machine that will collect data for 5 seconds using one single unique press on button X1. You should not have to hold button X1 during the recording. Data collection should begin with the turbine at rest and the dam overflowing. When you press X1, Your system should automatically open the penstock valve and begin data collection. Finally, the light Y1 should be illuminated during data collection so you know the system is recording.

You may be wondering why we're doing a controller design when we're still trying to build a model for the dam. The reason is that even in the first "bubble" of the ME480 process, where we are still working towards a basic model of the "thing we wish to control," we often have to go through the entire disciplined process at a small scale, just to move through the first step.

Place your state transition diagram, variable 'key,' code, and state transition table in the cells below.

Diagram:

YOUR ANSWER HERE

Table and variable key:

YOUR ANSWER HERE

Code

Code must be properly formatted. You will not receive credit for code that cannot be pasted directly into the simulator. Please ask for help if you are having trouble with the formatting.

YOUR ANSWER HERE

Now that you have the ability to collect data from the dam system, what do we do with it?

In particular, how does it help us build a model for the system? How will it eventually help us predict how long the Tesla will need to charge?

The following sections present the relevant portions of a disciplined process you can use to help interpret results from a dynamic test like the one your FSM performs on the Dam system. We will add to this toolset as the semester progresses! This is just to get us started.

Model Development: Constructing Models From Dynamic Tests

One of the most common ways to investigate a system's behavior when beginning to develop a model for its dynamics is to perform a test that involves changing the system's inputs and watching how its outputs evolve over time. By observing the relationships between the system's inputs and its outputs, we can often make determinations about what sort of mathematical model might be required to describe the system's behavior.

Step Response Tests

A "step input" is a common type of input used to investigate a system's dynamics. Colloquially, providing a system with a "step input" means that the system begins at an equillibrium defined by a steady-state input and a steady-state output. Then, the input is changed suddenly.

The unit step function (sometimes called the Heaviside step function after Oliver Heaviside) is defined mathematically as:

\begin{equation} u_s(t-t_0)=\left\{ \begin{matrix} 1 & \forall t\geq t_0 \\ 0&\forall t<t_0 \\ \end{matrix} \right. \end{equation}

Applying a step change in a system's input is often represented mathematically by applying a scaled version of the heaviside unit step function, which by definition has a magnitude of 1. Generally speaking, a step function of magnitude $U$ that occurs at time $t_0$ can be written:

$$\Delta u(t) = U\cdot u_s(t-t_0)$$

True Heaviside step functions represent instantaneous change in a system's input. Instantaneous changes are impossible in a physical system because they would require infinite power to achieve, but step functions are often a good approximation for "sudden" changes in a system's inputs. Step response tests are tests in which an approximate step change in a system's input is applied while the system's output(s) is/are measured.

A step response test is shown below, where the magnitude of the step input $\Delta u(t) = U = u_{ss}-u_0$.

image-3.png

While the response above is generic, it has properties that many physical systems have. The output of the system changes, and eventually settles to a steady state or final value.

So what can we learn from a step response test?

Experimentally determining local system stability from a step response test

There are several mathematical definitions of "Stability" for a dynamic system. In this course, when we say that a system is stable, we generally mean that it is "Bounded Input Bounded Output (BIBO)" stable. What does this mean? It means that for any finite input, the system will produce a finite output.

Technically, "proving" that a system is globally stable in this way using experimental data would require giving the system every possible input and watching to make sure that its output stays finite. However, most systems are only subjected to a relatively small range of inputs. Consider your zumo or your lab rig's motor: you can only provide voltage inputs between 0 and 5V to the lab rig, so why worry about how the lab rig acts when it is fed 4,000 volts?

This is the concept of local stability, and without mathematical tools (which we will get to shortly), it's about all we can do to say that if a system is given step inputs with magnitudes within the range of interest, and the system reaches a steady state, it is likely stable. The figure below shows some examples of systems responding to step inputs:

image.png

Steady State in a step response test

For this purposes of this course, we define "steady state" behavior of a system in response to inputs that are nonperiodic (such as a step input) to occur when the output of the system is no longer changing. This definition changes slightly for periodic inputs (like sine waves).

Steady State Gain in a step response test

If a system reaches a steady state (if it is BIBO stable), a dynamic test can also give us information about the steady state ratio of output to input for the system. Think of this like a "calibration:" it tells us "how much output" we get "per unit input" for the system. Mathemtatically, we can define steady state gain for a step response test as the ratio of the change in output over the change in input for a step input as:

$$K_{ss} = \frac{y_{ss}-y_0}{u_{ss}-u_0} = \frac{\Delta y_{ss}}{\Delta u_{ss}}$$

For other types of inputs, such as sinusoids, ramps, or impulse functions, the definition is slightly different, but the conceptual definition of steady state gain remains the same. It always tells us how much a system amplifies or attenuates its input.

Linearity: the principle of superposition

A system is linear if it satisfies the principle of superposition:

If an input change $\Delta u_1(t)$ produces an output change $\Delta y_1(t)$ and an input change $\Delta u_2(t)$ produces an output change $\Delta y_2(t)$, then

input change $\Delta u(t) = c_1\Delta u_1(t) + c_2 \Delta u_2(t)$ produces an output change $\Delta y(t) = c_1\Delta y_1(t)+c_2\Delta y_2(t)$ for all pairs of input changes $\Delta u_1(t),\Delta u_2(t)$ and constants $c_1,c_2$.

This means that the system satisfies the principle of superposition.

One key consequence of the principle stated above is that if one doubles the input change $\Delta u(t)$ for a system, a linear system will produce exactly double the output change $\Delta y(t)$ at every time $t$.

Unfortunately, essentially all physical systems known to humans are both nonlinear and of essentially infinite order. However, given that we're often only concerned with the behavior of a system within certain small regions of inputs and initial conditions, many physical systems are approximately linear in a particular region of interest to an engineer.

Knowing whether a system behaved linearly for your expected range of inputs is very important beceause it tells us what type of mathematical model we should be thinking of constructing for our system. If the system behaves approximately linearly, we can use the rich set of tools in Ordinary Linear Differential Equations (ODE)s to build and analyze our model, including the Laplace Transform and the Transfer function.

2% Settling Time

Settling time gives us an idea of how long the transients (changing behavior) of a dynamic system last. We use settling time to classify a system's dynamics as "fast" or "slow" relative to our control system's design goals, or when comparing one configuration of a system to another.

We will link settling time to mathematical models and their properties, but it is an empirical concept that can be obtained simply by analyzing a dataset. The 2% settling time is defined as the last time at which the system's output change $\Delta y(t) = y(t) - y_0$ has an absolute value that is greater than 2% away from $\Delta y_{ss} = y_{ss}-y_0$. This is illustrated graphically below for two systems, one of which is oscillatory, and another which reaches its steady state value asymptotically.

image-3.png

Exercise 2: Due at MIDNIGHT on Monday, Sept 13

Model Development: Interpret the Dam's behavior

Using your data-collection state machine above, modifying as necessary, collect two datasets from the dam system:

  1. Dam begins overflowing. VALVEPERCENT begins at zero, and the turbine begins at rest. When X1 is pressed, VALVEPERCENT is increased to 25%. Data are collected for 5 seconds.
  2. Dam begins overflowing. VALVEPERCENT begins at zero, and the turbine begins at rest. When X1 is pressed, VALVEPERCENT is increased to 50%. Data are collected for 5 seconds.

Save these datasets with descriptive names. Then, upload them to this assignment folder using the Jupyterhub files interface. This way, you can load them in an Octave (code) cell using something like:

data = load('myfilename.txt');

For plotting, manipulation, and analysis.

In the octave code cell below, load and plot relevant data from your two tests on the same plot, labeling axes appropriately.

In [3]:
% YOUR CODE HERE
error('No Answer Given!')
error: No Answer Given!
  1. What is the steady state gain from valve percentage to house voltage for the 25% test?

YOUR ANSWER HERE

  1. Is the dam system linear when considering the valve position as an input and the house voltage as an output? How do you know?

YOUR ANSWER HERE

  1. Does the settling time of the house voltage depend on the valve position setting?

YOUR ANSWER HERE

  1. Does the dam system appear to be BIBO stable for these tests?

YOUR ANSWER HERE

Now, run a third test with a VALVEPERCENT setting of 100%, keeping all other variables the same. Use the code cell to plot your data from this third test on the same plot as the previous tests.

In [4]:
% YOUR CODE HERE
error('No Answer Given!')
error: No Answer Given!

Does this test change any of your conclusions above? Explain.

YOUR ANSWER HERE