Commit 26eeaff9 authored by hazrmard's avatar hazrmard
Browse files

added cleanup modelica commands

parent 41388b83
......@@ -10,3 +10,4 @@
*.exe
*_info.json
.ipynb_checkpoints/
dygraph-combined.js
......@@ -12,32 +12,48 @@
```
conda env create -f env.yml
```
## Architecture
```
Modelica ->(compiler)-> Functional Mockup Unit ->(pyFMI)->(gym wrapper) -> RL
```
%% Cell type:code id: tags:
``` OpenModelica
class Pendulum "Pendulum"
constant Real PI=3.141592653589793;
parameter Real m=1, g=9.81, L=0.5;
Real F; // External force tengential to motion
output Real x(start=0.5),y(start=0);
output Real vx,vy; // x and y velocities
constant Real PI=3.141592653589793;
parameter Real m=1, g=9.81, L=0.5;
Real F; // External force tengential to motion
output Real x(start=0.5),y(start=0);
output Real vx,vy; // x and y velocities
equation
m*der(vx)=-(x/L)*F; // Force equation in x direction
m*der(vy)=-(y/L)*F-m*g; // Force equation in y direction
der(x)=vx; // Relating x position to x velocity
der(y)=vy; // Relating y position to y velocity
x^2+y^2=L^2; // Constraining x, y to string length
// 5 variables, 5 equations
m*der(vx)=-(x/L)*F; // Force equation in x direction
m*der(vy)=-(y/L)*F-m*g; // Force equation in y direction
der(x)=vx; // Relating x position to x velocity
der(y)=vy; // Relating y position to y velocity
x^2+y^2=L^2; // Constraining x, y to string length
end Pendulum;
```
%% Cell type:code id: tags:
``` OpenModelica
simulate(Pendulum)
// generates C code and complies an exe
// that produces a result file
buildModel(Pendulum fileNamePrefix="pendulum-")
```
%% Cell type:code id: tags:
``` OpenModelica
// builds model & runs it
simulate(Pendulum, fileNamePrefix="pendulum-")
```
%% Cell type:code id: tags:
``` OpenModelica
......@@ -45,27 +61,42 @@
```
%% Cell type:code id: tags:
``` OpenModelica
// remove artifacts
remove("pendulum-*")
```
%% Cell type:code id: tags:
``` OpenModelica
class Spring "Damped Spring"
// mass, gravity, spring constant, air, contact resistance
parameter Real m=0.5, g=9.81, k=3, r_a=0.1, r_c=0.0;
output Real x(start=0.0); // x position
output Real vx(start=0.2); // x velocity
equation
// 2 variables, 2 equations
m*der(vx)= -k*x - r_a*vx - r_c*m*g; // force equation
der(x)=vx; // relating position to velocity
der(x)=vx; // relating position to velocity
end Spring;
```
%% Cell type:code id: tags:
``` OpenModelica
simulate(Spring)
simulate(Spring, fileNamePrefix="spring-*")
```
%% Cell type:code id: tags:
``` OpenModelica
plot(der(x), x)
```
%% Cell type:code id: tags:
``` OpenModelica
// remove artifacts
remove("spring-*")
```
......
......@@ -12,4 +12,10 @@ To install:
conda env create -f env.yml
```
On Windows, set the environment variable `OPENMODELICAHOME` to point to the installation directory for OpenModelica.
\ No newline at end of file
Set the environment variable `OPENMODELICAHOME` to point to the installation directory for OpenModelica.
## Learn
* [Modelica by Example](https://mbe.modelica.university/)
* [Modelica Reference](https://webref.modelica.university/)
* [OpenModelica User Guide](https://www.openmodelica.org/useresresources/userdocumentation)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment