Conversion of units
Physical units
Although in smartCORE all channels with physical variables, measured or calculated, have usually been assigned a physical unit in the configuration, these are not taken into account in the calculation and further processing.
It is the author's responsibility to convert and standardize the physical values himself by making appropriate corrections.
Frequently used conversions are provided by the following functions:
Function | Description |
---|---|
rad2deg(alpha) | Conversion of the angle alpha from radians to degrees |
deg2rad(alpha) | Conversion of the angle alpha from radians to radians |
kph2mph(speed) | Conversion of speed from km/h to mph |
mph2kph(speed) | Conversion of speed from mph to km/h |
C2K(temperature) | Converting a temperature from °Celsius to Kelvin |
K2C(temperature) | Conversion of a temperature from Kelvin to °Celsius |
C2F(temperature) | Conversion of a temperature from °Celsius to °Fahrenheit |
F2C(temperature) | Conversion of a temperature from °Fahrenheit to °Celsius |
F2K(temperature) | Conversion of a temperature from °Fahrenheit to Kelvin |
K2F(temperature) | Conversion of a temperature from Kelvin to °Fahrenheit |
If the required conversion function is not available here, the commented definition of scaling factors at the beginning of the formula text has proved useful.
// Constants for unit conversion
uConv_Ws2kWh = 1e-3 / 3600; // Ws -> kWh
...
Example 1 shows the application in the energy calculation.
The following examples show the need:
Example: Power and energy
The electrical power is the product of current and voltage:
and the energy from the integral over the power:
The SI base units A (ampere), V (volt), W (watt) and J (joule) are assumed. If the measurement data is not available in the SI base units or if the results are not to be output in these units, correction factors must be incorporated.
If the current is measured in mA and the power is to be output in kW, it must be corrected in the form of an equation of the following dimensions:
in the commented formula text:
P_el = U_el * I_el / 1000 / 1000; // I in mA, P_el in kW
To output the energy in kWh, the following equation must be formed using the relationship :
and in the commented formula text:
W_el = integrate(P_el * 1000) / 1000 / 3600; // P_el in kW, W_el in kWh
It is important to ensure that function blocks that can be provided with a persistent memory are filled in SI base units. This makes it easier to subsequently implement corrections in the source and target units. In this example, the integrand must have the SI unit W. Therefore, the factor 1000 should not be removed from the integral and shortened.
W_el = integrate(P_el * 1000, {storage:'energy_Ws'}) / 1000 / 3600;
In this example, the definition of constants for conversion suggested at the beginning was not implemented. You can see how the readability of the formulas deteriorates. For what and why does it say * 1000
or / 1000
?
Example: Thermodynamics
In thermodynamic formulas, temperatures are used in the SI base unit Kelvin (K). For example, in the thermal equation of state
The following SI base units are to be used:
-
p in (Pascal)
-
V in
-
m in
-
R in
-
T in (Kelvin)
In addition to the scaling factors for the volume, mass or pressure, the offset of must be taken into account in the formula text when converting the temperature from °Celsius to Kelvin. The conversion from °Fahrenheit to Kelvin is even "worse".
The size equation is then, for example
Even if the scaling factors can be summarized well here, good documentation of the units used and expected is essential due to the complexity!