Note: The Load State... and Save State... commands are not working. Code was written for them but due to time constraints, they were not debugged. We chose to spent our time on more important part of the assignment. All other functional components of the simulator should be working. It may be necessary to restart the GUI sometimes.
Files: editorApp.py simclasses.py MySimpleDialog.py - No changes. circletest.bd circletest.sim massspring.bd massspring.sim
Changes in editorApp.py consist in adding a menu item Export to exp env... and an action command. This function exports a diagram in a format understandable by the experimentation environment. In simclasses.py, we can find the implementation of the Export method. It generates code that will build classes in the experimentation environment. The BD editor does not need the classes of the solver environment, it just generates text strings that is python code.
We followed the following convention. Files ending in .bd are the files obtained by using the "Save as..." command, no change was done to the format of these files. Files ending in .sim are the model exported to the simulator format.
Working with GUI
To select variables to be plot. Click variable's name in list then click on the SetX or SetY buttons to set the x-axis and y-axis variables respectively. The SetToFile and ResetToFile buttons specifies the fields to save to a file (Simulator -> Save Results). If none selected, nothing is saved.
The set of first order equations:
The corresponding block diagram for the circle test:
Running result and plots
Two time plots were done, first one is Int1 vs time and the 2nd one is Int2 vs time (step size 0.1, comm_int 0.01, t = 0 to 10). Both are sine waves:
Circles from bad to good. All plot uses a communication interval of 0.01 and runs from time 0 to 10.
stepsize = 2 gives:
green uses stepsize 1.0, gray uses step size 0.5 and red uses a step size of 0.25:
Using a step size of 0.01, we get a nice circle:
A good step size is 0.01. We compute the integrals by approximation. A small step size gives a better approximation. By using a step size small enough (say 0.01), we know the integration will be well approximated.
The mathematical equations are:
dx2/dt2 = - K/M * x
x(t = 0) = 0.3
v(t = 0) = 0
mass = 0.23
restlength = 0.2
The set of first order differential equations
The casual block diagram
A class was written (findk.py) to estimate the parameter K. The command used to run the code is
python findk.py. The script runs the simulation several times with K values in [1,10]. A step size of 0.01 is used. It outputs the maximum value:
the optimal k is 3.1 the optimal error is 0.0777074355888Also, the k values and the corresponding errors were store in file ktest. Below is a plot of the sum of square errors versus the K value. Also note that we used our Plot from file... function to plot it!
Plot below used best K. Blue curve is computed by simulator and orange curve is the measurement data.
step size 0.001 comm int 0.06 start time 0 end time 4 K = 3.1