Programmable controller ((extra) large)
- 1 Symbol and connections
- 2 Writing code
- 2.1 Controller syntax
- 2.1.1 Syntax
- 2.1.2 Input/output assignment
- 2.1.3 Initialisation
- 2.1.4 Built-in simulation variables
- 2.2 Example code
- 2.3 Most Common errors
- 2.1 Controller syntax
Symbol and connections
These blocks can be programmed to your liking. On the top side connections all inputs can be connected, on the bottom sides, all the outputs can be connected. The coding languange that is compatible with the programable controlers is Javascript. However, Hysopt evaluates the writen code in these programmable controllers every simulation step. This results that not all off the functionalities of Javascript are possible to be implemented. For instance:
While and with statements.
String inputs or outputs
….
There are 3 options:
Controller with 8 in/outputs
Controller with 16 in/outputs
Controller with 32 in/outputs
Writing code
Controller syntax
Syntax
In these controllers, code can be written to translate certain controls.
this can include things like:
assignment statements
if and if-else statements (if, else if, else)
switch statements
comments : single line (//) and multiline (/*...*/)
operators :
increment operators (++ and --)
unary operators (- and !)Â
binary operators : power (^), multiply (*), modulo (%), divide (/), sum (+), min (-)
ternary operator (a = x ? b : x)Â see Ternary Operator in C Explained
Example: Switch command
If Switch = 1 : Output= a , else output = b
Output = (Switch ==1) ? a: b;
conditional operators (|| and &&)
comparison (<=', >=, >, <, ==, '!=)
mathematical functions :Â
exp
,ln
,sin
,cos
,tan
,sqrt
,min(x1, x2)
,max(x1, x2)
,abs
,floor
,ceil
,sgn
(signum)
Input/output assignment
The controller needs to interact with the hydronic system. For this purpose, we can feed inputs to the controller and can give outputs to the system.
To assign a variable to an input in the programmeable controller, you can use: parameterName=in1;
Following the same logic, you can provide outputs as: out1=parameterName;
Initialisation
When using a variable that has not been defined before, the controller will equal the new variable to 0. This functionality can be used for initialisation purposes with the following topology:
Â
Built-in simulation variables
The following built-in variables can be used in the code withour prior assignment in the programmeable controller:
time : the time variable of the simulation
timestep: the timestep of the simulation
Example code
here is an example with code :Â example.txt
Note that the inspiration library is filled with written code like this, so be sure to look here for inspiration.
Most Common errors
A non-parseable code will cause the simulation to fail. Below, you can find a list of the most common errors when writing code in the programmeable controller:
No semicolon ( ; ) at the end of a line
Incorrect usage of ‘==’ (for if-statement) and '='
Not closing { } or ( ) brackets properly
Instead of having semicolon at the front of the comment, accidentally put // ;
Usage of an underscore ( _ ) is not allowed in parameter naming
Spelling mistake in parameter names. Code is case-sensitive
Â