[PDF version of this document] | [CS522 homepage] | [HV homepage]

Time Slicing Assignment

Time Slicing Assignment

 

Hans Vangheluwe

Fall Term 2001


The Tool

Implement (in Python) a modelling and simulation (experimentation) environment composed of:

The design and implementation of your tool must be documented. This is an important part of the deliverable. Use UML notation for your design.

Your tool must be thoroughly tested. Though you may include a test suite of your own making, you are strongly advised to use the PyUnit unit testing framework for Python. A short overview of PyUnit is found in the Python Library Reference.

The ``Circle Test''

Test your time-slicing simulator by means of the equation [(d2 x)/(d t2)]=-x. When x and [d x/d t] are plotted in function of one another (a phase plot), a circle should result.

  1. Re-write the equation in the form of a set of first order equations.
  2. Draw the corresponding block-diagram in the graphical editor.
  3. Run the simulation and plot the data in time and phase plots.
  4. Do the above for a ``good'' (sufficiently small) integrator step-size as well as for a ``bad'' (large) step-size (which should not result in a circle plot). Explain. The ``good'' step-size will give you an idea of what step-size to use for the rest of the assignment. Explain why it should be smaller than the value you used for the circle test.

Mass-spring: simulation and calibration

MassSpring.gif

Figure 1: Mass-spring system

The above mechanical system consists of a mass m which glides without friction over a surface. The mass is connected to a rigid wall by means of an ``ideal'' spring. In the absence of external forces, the system is in ``rest'' state and the distance of the centre of gravity of the mass object to the wall is RestLength. At any instant in time, the position (distance from the wall) of the mass is x.

An experiment has been carried out whereby the mass m was measured as well as the RestLength of the spring. m = 0.23 kg, RestLength = 0.2 m. To determine the spring constant K[kg/s2] of the ideal spring, the spring is extended to bring the mass at initial position x(t=0) with initial velocity v(t=0). x(t=0) = 0.3 m, v(t=0) = 0 m/s. (note: in many cases, in a simulation, one may have to set x(t=0) and/or v(t=0) to a small, non-zero value to avoid the simulator providing a trivial (zero) solution to the system equations).

This experiment whereby the mass is released and observed during the time interval [0,4[ yields the following measurement data xmeasured in function of time.

MassSpring_measured_x_gnuplot.png

Figure 2: Measured displacement (noisy)

Note: this plot was produced in gnuplot from the xmeasured data file (after removal of the first line) with the following commands:

 set xlabel "time t [s]"
 set ylabel "position x [m]"
 plot "data" title 'measured position x'

When you want a smooth curve rather than points, append with lines to the plot command. To plot column B of the data file in function of column A, append using A:B to the plot command.

With this ``noisy'' data, we need to ``estimate'' spring constant value K which, when used in a simulation of the dynamics of the system x(t) optimally ``fits'' the measured data. Notice how we start with parameter estimation directly and we skip the ``structure characterization phase'' in which the most appropriate mathematical model for this system is determined. This, as we have the a-priori knowledge that this is a frictionless system and the spring is ``ideal''.

Assignment:

  1. Describe the mathematical equations for the dynamics of this system (given the above a-priori knowledge).
  2. As this will yield a higher order differential equation, rewrite this as a set of first order differential equations.
  3. Represent this set of differential equations as a causal block diagram in your block diagram modelling environment.
  4. Use this in your time-slicing simulator.
  5. Run multiple simulations, varying (with a small enough step-size) K value in [1, 10].
  6. Check which of the K values gives the ``best fit''. Fit is defined in the ``sum of squared errors'' sense. Hereby, for each measured point in time, the difference between the measured value and the simulated value is taken and squared. The sum of all squared errors is a measure for the fit.

    Note: to give accurate results, the simulator may need a small step-size. To compare with measured data which is quite far apart, you simulator will have to implement a ``communication interval'' which allows the user to specify how often simulated values have to be output.

    Whether you use a very naive exhaustive search as described above or an advanced optimization algorithm (feel free to apply some of your optimization knowledge), an optimal K will result. Simulation with the ``true'' K value will yield a graph as below.

MassSpring_Plot_out.png

Figure 3: Calibrated model output

What's required

The full analysis, design (using UML notation), implementation (in Python) and simulation results should be documented and put on the web. Explicit links to code and data must be present.

You can work in groups of upto 3 people. Individual work must be indicated. All must understand and be able to explain the whole assignment (discuss your design together before implementing and do a peer review of your code).

The due date is September 26 (before midnight).


Translated from TEX by TTH, version 2.89 (minor customizations by HV). On 17 Sep 2001, 11:24.