-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* updated readme * FIX: compatability with [email protected] (#23) Co-authored-by: Henning Scheufler <[email protected]> * re-added test (bouncing ball), refactor for FMICore 0.16.0 * Update Test.yml --------- Co-authored-by: Henning Scheufler <[email protected]> Co-authored-by: Henning Scheufler <[email protected]>
- Loading branch information
1 parent
a235b06
commit 2d048db
Showing
9 changed files
with
163 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "FMIExport" | ||
uuid = "31b88311-cab6-44ed-ba9c-fe5a9abbd67a" | ||
authors = ["TT <[email protected]>", "LM <[email protected]>"] | ||
version = "0.1.12" | ||
version = "0.1.13" | ||
|
||
[deps] | ||
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" | ||
|
@@ -11,5 +11,5 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" | |
|
||
[compat] | ||
EzXML = "1.1.0" | ||
FMICore = "0.14, 0.15" | ||
FMICore = "0.16" | ||
julia = "1.6" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name = "BouncingBall" | ||
uuid = "a60229a6-2119-4702-9088-6d2bb886a221" | ||
authors = ["TT <[email protected]>"] | ||
version = "0.1.0" | ||
|
||
[deps] | ||
FMIBuild = "226f0e26-6dd6-4589-ada7-1d32f6e1d800" | ||
FMIExport = "31b88311-cab6-44ed-ba9c-fe5a9abbd67a" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# | ||
# Copyright (c) 2021 Tobias Thummerer, Lars Mikelsons | ||
# Licensed under the MIT license. See LICENSE file in the project root for details. | ||
# | ||
|
||
using FMIExport | ||
|
||
FMU_FCT_INIT = function() | ||
m = 1.0 # ball mass | ||
r = 0.0 # ball radius | ||
d = 0.7 # ball collision damping | ||
v_min = 1e-1 # ball minimum velocity | ||
g = -9.81 # gravity constant | ||
|
||
s = 1.0 # ball position | ||
v = 0.0 # ball velocity | ||
a = 0.0 # ball acceleration | ||
|
||
t = 0.0 | ||
x = [s, v] | ||
ẋ = [v, a] | ||
u = [] | ||
p = [m, r, d, v_min, g] | ||
|
||
return (t, x, ẋ, u, p) | ||
end | ||
|
||
FMU_FCT_EVALUATE = function(t, x, ẋ, u, p) | ||
m, r, d, v_min, g = (p...,) | ||
s, v = (x...,) | ||
_, a = (ẋ...,) | ||
|
||
if s <= r && v < 0.0 | ||
s = r | ||
v = -v*d | ||
|
||
# stop bouncing to prevent high frequency bouncing (and maybe tunneling the floor) | ||
if v < v_min | ||
v = 0.0 | ||
g = 0.0 | ||
end | ||
end | ||
|
||
a = (m * g) / m # the system's physical equation | ||
|
||
x = [s, v] | ||
ẋ = [v, a] | ||
p = [m, r, d, v_min, g] | ||
|
||
return (x, ẋ, p) | ||
end | ||
|
||
FMU_FCT_OUTPUT = function(t, x, ẋ, u, p) | ||
m, r, d, v_min, g = (p...,) | ||
s, v = (x...,) | ||
_, a = (ẋ...,) | ||
|
||
y = [s] | ||
|
||
return y | ||
end | ||
|
||
FMU_FCT_EVENT = function(t, x, ẋ, u, p) | ||
m, r, d, v_min, g = (p...,) | ||
s, v = (x...,) | ||
_, a = (ẋ...,) | ||
|
||
z1 = (s-r) # event 1: ball hits ground | ||
|
||
if s==r && v==0.0 | ||
z1 = 1.0 # event 1: ball stay-on-ground | ||
end | ||
|
||
z = [z1] | ||
|
||
return z | ||
end | ||
|
||
# this function is called, as soon as the DLL is loaded and Julia is initialized | ||
# must return a FMU2-instance to work with | ||
FMIBUILD_CONSTRUCTOR = function(resPath="") | ||
fmu = fmi2CreateSimple(initializationFct=FMU_FCT_INIT, | ||
evaluationFct=FMU_FCT_EVALUATE, | ||
outputFct=FMU_FCT_OUTPUT, | ||
eventFct=FMU_FCT_EVENT) | ||
|
||
# states [2] | ||
fmi2AddStateAndDerivative(fmu, "ball.s"; stateDescr="Absolute position of ball center of mass", derivativeDescr="Absolute velocity of ball center of mass") | ||
fmi2AddStateAndDerivative(fmu, "ball.v"; stateDescr="Absolute velocity of ball center of mass", derivativeDescr="Absolute acceleration of ball center of mass") | ||
|
||
# outputs [1] | ||
fmi2AddRealOutput(fmu, "ball.s"; description="Absolute position of ball center of mass") | ||
|
||
# parameters [5] | ||
fmi2AddRealParameter(fmu, "m"; description="Mass of ball") | ||
fmi2AddRealParameter(fmu, "r"; description="Radius of ball") | ||
fmi2AddRealParameter(fmu, "d"; description="Collision damping constant (velocity fraction after hitting the ground)") | ||
fmi2AddRealParameter(fmu, "v_min"; description="Minimal ball velocity to enter on-ground-state") | ||
fmi2AddRealParameter(fmu, "g"; description="Gravity constant") | ||
|
||
fmi2AddEventIndicator(fmu) | ||
|
||
return fmu | ||
end | ||
|
||
### FMIBUILD_NO_EXPORT_BEGIN ### | ||
# The line above is a start-marker for excluded code for the FMU compilation process! | ||
|
||
tmpDir = mktempdir(; prefix="fmibuildjl_test_", cleanup=false) | ||
@info "Saving example files at: $(tmpDir)" | ||
fmu_save_path = joinpath(tmpDir, "BouncingBall.fmu") | ||
|
||
fmu = FMIBUILD_CONSTRUCTOR() | ||
using FMIBuild: fmi2Save # <= this must be excluded during export, because FMIBuild cannot execute itself (but it is able to build) | ||
fmi2Save(fmu, fmu_save_path) # <= this must be excluded during export, because fmi2Save would start an infinte build loop with itself | ||
|
||
### some tests ### | ||
# using FMI | ||
# comp = fmiInstantiate!(fmu; loggingOn=true) | ||
# solution = fmiSimulateME(comp, 0.0, 10.0; dtmax=0.1) | ||
# fmiPlot(fmu, solution) | ||
# fmiFreeInstance!(comp) | ||
|
||
# The following line is a end-marker for excluded code for the FMU compilation process! | ||
### FMIBUILD_NO_EXPORT_END ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2d048db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
2d048db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/79062
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: