Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
model:creating_a_model_in_python [2023/03/12 23:13]
optrix
model:creating_a_model_in_python [2025/02/18 05:02] (current)
optrix
Line 6: Line 6:
  
 <code> <code>
-import ardimodel+import ardimodel as mdl
  
-host = ardimodel.ModelHost()+host = mdl.ModelHost(5225#This is the port number that OPC-UA will run on
  
 # Add Models Here # Add Models Here
Line 31: Line 31:
  
 <code> <code>
 +#My Tank Model
 +@mdl.part("Online Tank Model")
 def TankModel(mod): def TankModel(mod):
    pass    pass
 </code> </code>
  
-Once we've created the model function, we can add it to the [[host]] object we created earlierat the bottom of our code.+The '@part' decorator marks the function defines a **model**. Inside the function, we can define which specific inputsoutputs, constants and calculations we need.
  
-<code> +The human readable name for our model is 'Online Tank Model'.
-# Add Models Here +
-host.Add(ardimode.Create("Tank",TankModel)) +
-</code> +
- +
-This defines our (currently empty) model, and adds that model to our running system with the name 'Tank'.+
  
 ===Filling in the Inputs=== ===Filling in the Inputs===
Line 91: Line 88:
 For example, the function here will be... For example, the function here will be...
  
-<code>(LevelPerc.num() / 100) * Capacity.num()</code>+<code>(float(LevelPerc) / 100) * float(Capacity)</code>
  
-//Note that the 'numfunction converts a DataPoint to a floating-point number. Some points will be strings, so it's important to always cast the value to a number if you're using it as one.//.+//Note that data points aren't simple numbers you'll need to cast them to floats or integers if you want to use them as numeric values. If you need to access the raw value, use **.value**.//.
  
 ==Used Points== ==Used Points==
Line 125: Line 122:
  
 <code> <code>
-import ardimodel+import ardimodel as mdl
  
 host = ardimodel.ModelHost() host = ardimodel.ModelHost()
  
 +@mdl.part("Tank Model")
 def TankModel(mod): def TankModel(mod):
     Outflow = mod.AddInput("Outgoing Flow",10)     Outflow = mod.AddInput("Outgoing Flow",10)
Line 137: Line 135:
     Volume = mod.AddOutput("Tank Volume", lambda: (LevelPerc.num() / 100) * Capacity.num(), [LevelPerc,Capacity])     Volume = mod.AddOutput("Tank Volume", lambda: (LevelPerc.num() / 100) * Capacity.num(), [LevelPerc,Capacity])
     mod.AddOutput("Time-To-Empty", lambda: Volume.num() / Outflow.num(), [Outflow,Volume])     mod.AddOutput("Time-To-Empty", lambda: Volume.num() / Outflow.num(), [Outflow,Volume])
- 
-# Add Models Here 
-host.Add(ardimodel.Create("Tank",TankModel)) 
  
 host.ardiurl = "localhost" host.ardiurl = "localhost"