Modelica Assignment
|
Practical Information
GoalsIn this assignment, you will use the Modelica Language to create a simple motor yacht autopilot. You will learn how Ordinary Differential Equations (ODE) can be used to facilitate the modeling and simulation of Cyber-Physical Systems (CPS). Furthermore, you will learn how a generic model must be calibrated to fit real-world data and how it can be tuned to optimize some goal function. This solution will be made with OpenModelica. MacOS users can install OpenModelica from the binaries (make sure to use the latest version). Also ensure that you clearly indicate how your solution can be executed and which files implement which models in your report! Assignment Overview
This assignment consists of four main parts:
Plant Model CreationIn this part of the assignment, we will create a simple ODE for modelling the yacht movement, based on nautical physics. This ODE will be controlled such that the yacht may use cruise control. For the sake of simplicity, we shall represent this movement in one dimension (i.e., no steering shall be done). In figure 1, you can see a free body diagram of this system. The yacht moves towards the right (positive direction). Figure 1: Free body diagram of the yacht. The yacht moves forward with a throttle force of $\vec{F}_T$. Additionally, it receives some resistance $\vec{F}_R$ from the water. Hence, the total force can be computed as $F = F_T - F_R$. Newton's second Law of Motion states $F = m\cdot a$, with $m$ the mass of the yacht and $a$ its acceleration. This implies (if the mass does not change): $$\begin{align} F = m\cdot a = m\cdot \dot{v} = m\cdot \dfrac{d v}{dt} &= F_T - F_R\\ \dfrac{d v}{dt} &= \dfrac{F_T - F_R}{m}\\ \end{align}$$ This results in an Ordinary Differential Equation (ODE) Initial Value Problem (IVP). An IVP typically has a time-based derivative of a variable $x$ on the left hand side (LHS) and a function in terms of that $x$ on the right hand side (RHS). Given an initial value $x(0)$, it is sometimes possible to analytically compute a solution for such an equation. Luckily, in the case no analytical solution may exist, a Modelica-based numerical simulation tool such as OpenModelica is able to provide a good approximation of the actual function. The above equation can be represented in Modelica and solved numerically. However, we do need more information abot $F_R$ and $F_T$. From nautical physics, it is known that $$\begin{cases} F_R &= \dfrac{1}{2}\cdot\rho\cdot v^2\cdot S\cdot C_f\\ C_f &= \dfrac{0.075}{\left(\log_{10}(Re) - 2\right)^2}\\ Re &= \dfrac{v\cdot L}{k} \end{cases}$$ Where $\rho$ identifies the density of the water, $v$ the yacht's velocity, $S$ the submerged area of (the full hull of) the yacht, $C_f$ the friction value, $Re$ Reynolds number, $L$ the length of the yacht and $k$ the kinematic viscosity of the water. Most of these parameters are known. The waters in which the yacht is sailing has salt water of about $15^{\circ}C$. This implies $\rho = 1025\ kg/m^3$ and $k = 1.188\cdot 10^{-6}\ m^2/s$. The yacht's length $L$ is $21.54\ m$ and its dry mass $m$ is $32,000\ kg$. TasksYour task is to model the yacht's plant (i.e., the equation(s)) in Modelica.
Plant Model CalibrationWhile this plant model may appear to be realistic, we have made an assumption on the value of $S$. Truth be told, we have no idea about what is going on underneath the surface of the water. Even if we would know the shape of the hull, there is no guarantee on how deep the yacht lies in the water (this is also known as the draft of the yacht). All we do know for certain is that $S$ lies between $150\ m^2$ and $300\ m^2$. We do have a physical yacht and thus we are able to run some experiments, as shown in figure 2. Figure 2: Two experiments done with the yacht. The first experiment is an acceleration from approximately $0\ m/s$ to just over $1\ m/s$, using a throttle force of $400\ N$. Every $5$ seconds, we looked at the GPS-based speedometer on board and we have written down the value. The experiment results can be found in this CSV file. Similarly, we have released the throttle ($F_T = 0\ N$) at $10\ m/s$ and wrote down the values for the next $400$ seconds. These results can be found in this CSV file. Note that the speedometer is not fully accurate, resulting in quite some noise on the data. Calibration is the process of estimating parameters of a model. Those parameter values are chosen which result in the closest match between simulated and measured values of pertinent, measurable variables, over time, over an entire experiment run. Such a match is often quantified in terms of a sum of squares of differences between measured and simulated values. In this case, we would like to estimate the submerged area of the yacht, the parameter $S$. An exhaustive way of finding optimal parameter values (note that in this case, there is only one parameter) is to loop over possible values for the parameters to find the one that gives the closest match mentioned above. This is known as a parameter sweep. TasksThe main purpose of this part is finding the submerged area of the yacht $S$, based on experimental data (i.e., observations/measurements on the real system).
Controller Model CreationIn this part of the assignment, we will create the yacht's cruise control system. In a typical execution, the yacht receives the desired velocity from a centralized coordinator, based on its current GPS signal. Where a human skipper would have to manually adapt the yacht's velocity based on experience, the automated controller will use this received data to accelerate or decelerate. The centralized coordinator is represented by a pre-defined ideal velocity profile. The velocity $v$ is given in meters per second ($m/s$) and always positive (or zero). Additionally, in the bay where the yacht is sailing, it is illegal to go faster than $20\ knots$ (which is approximately $10.28\ m/s$). From practice, we know that the yacht's engine cannot provide a speed variation faster than $1.5\ m/s^2$. For instance, the controller can never be asked to accelerate from $1\ m/s$ to $3\ m/s$ in one second. While this is mathematically possible in our system, it will be impossible in reality. Figure 3 shows an example velocity profile. Figure 3: Example ideal velocity profile of the yacht. The control system must ensure a correct and optimal execution. This implies:
Figure 4: Velocity of the yacht using an automated (Bang-Bang) controller.
As you can guess, the controler has a single output $F_T$; and a single input $u$ (which is the difference between the ideal velocity $v_{ideal}$ and the actual velocity $v$). Ideally, we would like $v_{ideal} - v$ to be small, as this implies the yacht is close to the desired velocity. A simple implementation of such a system would be a so-called Bang-Bang controller.
Here, an upper bound $d_{max}$ and a lower bound $d_{min}$ is set around the $v_{ideal}$. When $v$ exceeds (from below) $v_{ideal}+d_{max}$, the acceleration stops, such that the ship can decelerate due to the water resistance. Alternatively, some implementations help this by providing a "braking" force (for a ship this happens by making the engine propeller(s) turn backwards). But when $v$ goes below (from above) $v_{ideal}-d_{min}$, the ship needs to accelerate again, with a given (acceleration) force $g$.
In the real world, the passenger could feel the sudden changes in acceleration, hence the name: "Bang-Bang". A better controller is a Proportional-Integral-Derivative (PID) Controller (see lecture slides). Instead of setting $d_{min}$ or $d_{max}$, $F_T$ will be related to $v_{ideal} - v$. This relationship is obtained by computing the sum of three different controller actions:
TasksModel the yacht's controller in Modelica.
Controller Model TuningSimilar to the calibration of the plant, the controller also needs to be tuned for the most ideal solution. Instead of fitting a curve to existing experiment data, we shall try to find the controller parameters such that the given velocity profile is followed as closely as possible. Figure 6 shows an adaptation of the previous plant and controller system that also allows the computation of a cost. Figure 6: Plant and controller system for the yacht with cost computation. TasksTune the yacht's controller.
Practical Issues
|
Maintained by Hans Vangheluwe. | Last Modified: 2023/10/24 15:05:43. |