SEAL Functions: Difference between revisions

From DiLab
Jump to navigation Jump to search
Content deleted Content added
Atis (talk | contribs)
No edit summary
Atis (talk | contribs)
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Overview ==
== Overview ==


The following functions are available and can be called from SEAL code.
All of the following functions are available from SEAL code.


Naming convention used in this document:
Naming convention used in this document:
* Sensor value -- name of a SEAL sensor.
* Sensor value – name of a SEAL sensor, including user-defined sensors.
* A scalar -- a predefined constant, a variable, or an integer literal.
* Scalar value – a predefined constant, a variable, or an integer literal.


== Calling the functions ==

Functions can be '''called''' from SEAL code by specifying the name of the function, followed by arguments enclosed in brackets.

Some of the functions have '''synomyns'''. The they can be called from either of those names.

Optional arguments can be <b>skipped</b>; then they take default values. In contrast, some arguments can be '''repeated'' one or more times. The description of the functions mention which arguments are optional, and which can be repeated.

Functions parameters can also be '''named'''. For example, to call <code>contrast</code> function on 20 samples of light sensor readings, using the weight coefficient 2.0 you can write <code>contrast(Light, numSamples 20, weight 2.0)
</code>.

The meaning is the same as for <code>contrast(Light, 20, 2.0)</code>, but the former approach leads to self-documenting code.

If named, the parameetrs can also be written in mixed order, for example, <code>contrast(numSamples 20, weight 2.0, value Light)</code>.


== Arithmetic functions ==
== Arithmetic functions ==
Line 12: Line 26:
=== sum(value, ...) ===
=== sum(value, ...) ===


Sum of one or more values.
Sum.


'''Argument:''' a sensor value or a scalar.
'''Argument:''' a sensor value or a scalar.
Line 21: Line 35:


'''Example syntax:'''
'''Example syntax:'''
# <code>sum(Light, Humidity, -12)</code> -- calculates sum of last light sensor reading with last humidity sensor reading and -12 (i.e. subtracts 12).
# <code>sum(Light, Humidity, -12)</code> – calculates sum of last light sensor reading with last humidity sensor reading and -12 (i.e. subtracts 12).
# <code>sum(take(Light, 10))</code> -- calculates sum of last 10 light sensor readings
# <code>sum(take(Light, 10))</code> – calculates sum of last 10 light sensor readings


=== plus(value1, value2) ===
=== plus(value1, value2) ===
Line 32: Line 46:
'''Synonym:''' <code>add</code>
'''Synonym:''' <code>add</code>


'''Example syntax:''' <code>plus(Light, Humidity)</code> -- calculates sum of light and humidity sensor readings
'''Example syntax:''' <code>plus(Light, Humidity)</code> – calculates sum of light and humidity sensor readings


=== minus(value1, value2) ===
=== minus(value1, value2) ===
Line 42: Line 56:
'''Synonym:''' <code>subtract</code>
'''Synonym:''' <code>subtract</code>


'''Example syntax:''' <code>minus(Light, Humidity)</code> -- calculates value of the expression: light sensor reading - humidity sensor reading.
'''Example syntax:''' <code>minus(Light, Humidity)</code> – calculates value of the expression: light sensor value minus humidity sensor value.


=== times(value1, value2) ===
=== times(value1, value2) ===
Line 52: Line 66:
'''Synonym:''' <code>multiply</code>
'''Synonym:''' <code>multiply</code>


'''Example syntax:''' <code>times(Light, 3)</code> -- calculates value of light sensor reading multiplied by three.
'''Example syntax:''' <code>times(Light, 3)</code> – calculates the value of light sensor reading multiplied by three.


=== divide(value1, value2) ===
=== divide(value1, value2) ===
Line 60: Line 74:
'''Arguments:''' sensor values or scalars.
'''Arguments:''' sensor values or scalars.


'''Example syntax:''' <code>divide(Light, 3)</code> -- calculates value of light sensor reading divided by three and rounded down to the nearest integer.
'''Example syntax:''' <code>divide(Light, 3)</code> – calculates the value of light sensor reading divided by three and rounded down to the nearest integer.


=== modulo(value1, value2) ===
=== modulo(value1, value2) ===
Line 68: Line 82:
'''Arguments:''' sensor values or scalars.
'''Arguments:''' sensor values or scalars.


'''Example syntax:''' <code>modulo(Random, 3)</code> -- calculates the remainder of a random number value divided by three.
'''Example syntax:''' <code>modulo(Random, 3)</code> – calculates the remainder of a random number value divided by three.


=== difference(value1, value2) ===
=== difference(value1, value2) ===
Line 80: Line 94:
=== abs(value) ===
=== abs(value) ===


Absolute value
Absolute value.


'''Argument:''' a sensor value or a scalar.
'''Argument:''' a sensor value or a scalar.


'''Example syntax:''' <code>abs(Temperature)</code> -- calculate the absolute valute of temperature sensor reading
'''Example syntax:''' <code>abs(Temperature)</code> – calculate the absolute valute of temperature sensor reading


=== neg(value) ===
=== neg(value) ===
Line 92: Line 106:
'''Argument:''' a sensor value or a scalar.
'''Argument:''' a sensor value or a scalar.


'''Example syntax:''' <code>neg(Humidity)</code> -- calculate the negation valute of humidity sensor reading
'''Example syntax:''' <code>neg(Humidity)</code> – calculate the negation valute of humidity sensor reading


=== invert(value) ===
=== invert(value) ===


Return the Boolean inverse of the value passed: True if the value zero, False otherwise.
Return the Boolean inverse of the value passed: True if the value is zero, False otherwise.


'''Argument:''' a sensor value or a scalar.
'''Argument:''' a sensor value or a scalar.


'''Example syntax:''' <code>invert(Random)</code> -- evaluates to true if the last random number is zero.
'''Example syntax:''' <code>invert(Random)</code> – evaluates to true if the last random number is zero.


=== square(value) ===
=== square(value) ===


Square -- second power.
Calculate square (second power) of a value.


'''Argument:''' a sensor value or a scalar.
'''Argument:''' a sensor value or a scalar.


'''Example syntax:''' <code>square(Random)</code> -- calculate the square of the last random number.
'''Example syntax:''' <code>square(Random)</code> – calculate the square of the last random number.


=== sqrt(value) ===
=== sqrt(value) ===


Calculate square root of a value.
Square root.


'''Argument:''' a sensor value or a scalar.
'''Argument:''' a sensor value or a scalar.


'''Example syntax:''' <code>sqrt(Random)</code> -- calculates the square root of the last random number rounded to the nearest integer. Depending on the implmentation, approximate values may be returned!
'''Example syntax:''' <code>sqrt(Random)</code> – calculates the square root of the last random number rounded to the nearest integer. Depending on the implmentation, approximate values may be returned!


=== power(base, exponent) ===
=== power(base, exponent) ===
Line 124: Line 138:
'''Arguments:''' base is a sensor value or a scalar, exponent must be scalar.
'''Arguments:''' base is a sensor value or a scalar, exponent must be scalar.


'''Example syntax:''' <code>power(Random, 3)</code> -- calculate the cube of the last random number.
'''Example syntax:''' <code>power(Random, 3)</code> – calculate the cube of the last random number.



== Data aggregation functions ==
== Data aggregation functions ==
Line 139: Line 154:


'''Example syntax:'''
'''Example syntax:'''
# <code>min(Light, 10)</code> -- calculate the minimum of light sensor reading and the number 10;
# <code>min(Light, 10)</code> – calculate the minimum of light sensor reading and the number 10;
# <code>min(take(Light, 100))</code> -- calculate the minimum of the last 100 light sensor readings.
# <code>min(take(Light, 100))</code> – calculate the minimum of the last 100 light sensor readings.


=== max(value, ...) ===
=== max(value, ...) ===
Line 153: Line 168:


'''Example syntax:'''
'''Example syntax:'''
# <code>max(Light, 10)</code> -- calculate the maximum of the light sensor reading and the number 10;
# <code>max(Light, 10)</code> – calculate the maximum of the light sensor reading and the number 10;
# <code>max(take(Light, 100))</code> -- calculate the maximum of the last 100 light sensor readings.
# <code>max(take(Light, 100))</code> – calculate the maximum of the last 100 light sensor readings.


=== average(value) ===
=== average(value) ===
Line 167: Line 182:


'''Example syntax:'''
'''Example syntax:'''
# <code>average(Light)</code> -- calculate the average of light sensor readings during program's execution;
# <code>average(Light)</code> – calculate the average of light sensor readings during program's execution;
# <code>average(take(Light, 100))</code> -- calculate the average of the last 100 light sensor readings.
# <code>average(take(Light, 100))</code> – calculate the average of the last 100 light sensor readings.


=== stdev(value) ===
=== stdev(value) ===
Line 181: Line 196:


'''Example syntax:'''
'''Example syntax:'''
# <code>stdev(Light)</code> -- calculate the standard deviation of light sensor readings during program's execution;
# <code>stdev(Light)</code> – calculate the standard deviation of light sensor readings during program's execution;
# <code>stdev(take(Light, 100))</code> -- calculate the standard deviation of the last 100 light sensor readings.
# <code>stdev(take(Light, 100))</code> – calculate the standard deviation of the last 100 light sensor readings.


=== variance(value) ===
=== variance(value) ===
Line 189: Line 204:


'''Argument:''' a sensor value or a scalar
'''Argument:''' a sensor value or a scalar

Aggregate function (i.e. can have <code>take()</code> as parameter).


'''Example syntax:'''
'''Example syntax:'''
# <code>variance(Light)</code> -- calculate the variance of light sensor readings during program's execution;
# <code>variance(Light)</code> – calculate the variance of light sensor readings during program's execution;
# <code>variance(take(Light, 100))</code> -- calculate the variance of the last 100 light sensor readings.
# <code>variance(take(Light, 100))</code> – calculate the variance of the last 100 light sensor readings.


=== ewma(value, alpha) ===
=== ewma(value, alpha) ===
Line 201: Line 218:


'''Example syntax:'''
'''Example syntax:'''
# <code>ewma(Light, 0.5)</code> -- calculate the exponential moving average of light sensor readings during program's execution with coefficient 0.5;
# <code>ewma(Light, 0.5)</code> – calculate the exponential moving average of light sensor readings during program's execution with coefficient 0.5;
# <code>ewma(take(Light, 100), 0.5)</code> -- calculate the same, but for the last 100 light sensor readings.
# <code>ewma(take(Light, 100), 0.5)</code> – calculate the same, but for the last 100 light sensor readings.


=== changed(value) ===
=== changed(value) ===


Boolean value that describes whether the value has changed.
Calculate a Boolean value that describes whether the value has changed.


'''Argument:''' a sensor value or a scalar
'''Argument:''' a sensor value or a scalar


'''Example syntax:'''
'''Example syntax:'''
#<code>changed(Light)</code> -- true if light sensor reading have changed during program's execution.
#<code>changed(Light)</code> – true if light sensor reading have changed during program's execution.
#<code>changed(take(Light, 100))</code> -- true if light sensor reading have changed during last 100 readings.
#<code>changed(take(Light, 100))</code> – true if light sensor reading have changed during last 100 readings.
#<code>changed(13)</code> -- always false, because the value is constant.
#<code>changed(13)</code> – always false, because the value is constant.



== Signal processing functions ==
== Signal processing functions ==


=== map(value, fromRangeLow, fromRangeHigh, toRangeLow, toRangeHigh) ===
=== map ===


Do mapping.
'''Argument:'''


'''Arguments:''' 'value' is a sensor value or a scalar. The arguments 'fromRangeLow' and 'fromRangeHigh' are scalars that define the lower and upper bound of the range from which to map; the arguments 'toRangeLow' and 'toRangeHigh' are scalars that define the range to which to map.
'''Example syntax:'''


'''Example syntax:''' <code>map(Light, 0, 1023, 0, 255)</code> – map light sensor reading from range [0..1023] (10 bit range, e.g. ADC) to range [0..255] (eight bit range, e.g. for a variable of <code>char</code> type).
=== sharpen ===


=== sharpen(value, numSamples, weight) ===
'''Argument:'''

Add contrast.

'''Arguments:''' 'value' is a sensor value or a scalar. 'numSamples' (optional, default value 3) – a scalar value that describes the number of samples to take. 'weight' (optional, default value 1) – a scalar value (can be florating point) that describes the amplitude of the sharpening.


'''Synonym:''' <code>contrast</code>
'''Synonym:''' <code>contrast</code>


'''Example syntax:''' <code>sharpen(Light)</code> – add contrast to light sensor readings using the default values.
'''Example syntax:'''




=== smoothen ===
=== smoothen(value, numSamples, weight) ===


Remove contrast.
'''Argument:'''

'''Arguments:''' 'value' is a sensor value or a scalar. 'numSamples' (optional, default value 3) – a scalar value that describes the number of samples to take. 'weight' (optional, default value 1) – a scalar value (can be florating point) that describes the amplitude of the bluring.


'''Synonym:''' <code>blur</code>
'''Synonym:''' <code>blur</code>


'''Example syntax:''' <code>smoothen(Light)</code> – add blur to light sensor readings using the default values.
'''Example syntax:'''



== Filtering functions ==
== Filtering functions ==


=== match ===
=== match(value, pattern) ===


Match sensor readings against a predefined patter.
'''Argument:'''


'''Arguments:''' 'value' is a sensor value or a scalar. 'pattern' is the name of a predefined pattern in the source file.
'''Example syntax:'''


'''Example syntax:''' <code>pattern P (0, 0, 0, 0); ...; match(Light, pattern)</code> – compare last four light sensor reading with four consecutive zeros and evaluate to True in case of match, False otherwise.
=== filterRange ===


=== filterRange(value, thresholdMin, thresholdMin) ===
'''Argument:'''


Threshold sensor readings against predefined lower and upper bounds.
'''Example syntax:'''


'''Arguments:''' 'value' is a sensor value or a scalar. 'thresholdMin' and 'thresholdMin' are scalars that define the range [thresholdMin..thresholdMin].
=== filterEqual ===


'''Example syntax:''' <code>filterRange(Light, 1000, 2000)</code> – read only those light sensor values that are between 1000 and 2000, inclusive, and ignore the rest.
'''Argument:'''


=== filterEqual(value, threshold) ===
'''Example syntax:'''


'''Arguments:''' 'value' is a sensor value or a scalar. 'threshold' is a scalar.
=== filterNotEqual ===


'''Example syntax:''' <code>filterEqual(Light, 1000)</code> – read only those light sensor values that are equal to 1000, and ignore the rest.
'''Argument:'''


=== filterNotEqual(value, threshold) ===
'''Example syntax:'''


'''Argument:''' 'value' is a sensor value or a scalar. 'threshold' is a scalar.
=== filterLess ===


'''Example syntax:''' <code>filterNotEqual(Light, 1000)</code> – read only those light sensor values that are not equal to 1000, and ignore the rest.
'''Argument:'''


=== filterLess(value, threshold) ===
'''Example syntax:'''


'''Argument:''' 'value' is a sensor value or a scalar. 'threshold' is a scalar.
=== filterLessOrEqual ===


'''Example syntax:''' <code>filterLess(Light, 1000)</code> – read only those light sensor values that are less than 1000, and ignore the rest.
'''Argument:'''


=== filterLessOrEqual(value, threshold) ===
'''Example syntax:'''


'''Argument:''' 'value' is a sensor value or a scalar. 'threshold' is a scalar.
=== filterMore ===


'''Example syntax:''' <code>filterLessOrEqual(Light, 1000)</code> – read only those light sensor values that are less than or equal to 1000, and ignore the rest.
'''Argument:'''


=== filterMore(value, threshold) ===
'''Example syntax:'''


'''Argument:''' 'value' is a sensor value or a scalar. 'threshold' is a scalar.
=== filterMoreOrEqual ===


'''Example syntax:''' <code>filterMore(Light, 1000)</code> – read only those light sensor values that more than to 1000, and ignore the rest.
'''Argument:'''


=== filterMoreOrEqual(value, threshold) ===
'''Example syntax:'''


'''Argument:''' 'value' is a sensor value or a scalar. 'threshold' is a scalar.
=== invertFilter ===


'''Example syntax:''' <code>filterMoreOrEqual(Light, 1000)</code> – read only those light sensor values that are more than or equal to 1000, and ignore the rest.
'''Argument:'''


=== invertFilter(value) ===
'''Example syntax:'''

Invert the effect of any previosly applied filters, or filter out the value if there were none.

'''Argument:''' 'value' is a sensor value or a scalar

'''Example syntax:''' <code>invertFilter(filterRange(Light, 1000, 2000))</code> – read only those light sensor values that are NOT bewteen 1000 and 2000, inclusive, and ignore those that are.




== Subset selection &amp; special purpose functions ==
== Subset selection &amp; special purpose functions ==


=== if(conditionValue, ifValue, elseValue) ===
=== take ===


Logical IF function. If <code>conditionValue</code> is true (nonzero), then <code>ifValue</code> is returned. Else <code>elseValue</code> is returned.
'''Argument:'''


<code>elseValue</code> is optional, and has default value of zero.
'''Example syntax:'''


'''Arguments:''' sensor values.
=== tuple ===


'''Argument:'''
'''Example syntax:'''
* <code>if(True, Temperature, Humidity)</code> – if 'True' is true, then read light and humidity values.
* <code>when Light < 100: set ConditionValue True; end;</code>
&nbsp;&nbsp;&nbsp;&nbsp;<code>define BoundedLight if(ConditionValue, Light, 100);</code> – this is a more practical example that uses states (the <code>ConditionValue</code> variable) to achieve conditional behaviour. If Light sensor reads less than 100, then reading BoundedLight will return light value, else it will return the number 100.


'''Example syntax:'''


=== take(value, numberToTake, timeToTake) ===
=== sync ===


Take one or more sensor value. The values are read one at time, but the enclosing function is evaluated on all of them. At the start of program, the values that are not read yet are treated as zero.
'''Argument:'''

<code>take</code> can only be used in context of specific enclosing functions – those that are marked as aggregate.

'''Arguments:''' 'value' is a sensor value. 'numberToTake' is a scalar value that describes the number of sensor values to read. 'timeToTake' (optional, default value is not specified) is the time period in which to limit the values.


'''Example syntax:'''
'''Example syntax:'''
#<code>sum(take(Random, 100))</code> – calculate sum of 100 random numbers.
#<code>sum(take(Light, 600, 1h))</code> – calculate sum of light sensor readings sampled in the last hour, and limit their count to six hundred (600).

=== tuple(value, ...) ===

Read multiple, heterogenous sensor values.

<code>tuple</code> can only be used in context of specific enclosing functions – those that are marked as aggregate.

'''Argument:''' sensor values.

'''Example syntax:''' <code>tuple(Light, Temperature, Humidity)</code> – read a tuple of light, temperature, and humidity sensor values.

=== sync(value, ...) ===

Synchronize reading of multiple sensors.

'''Arguments:''' sensor values.

'''Example syntax:''' <code>sync(Light, Temperature, Humidity)</code> – synchronize light, temperature, and humidity sensor reading.

Latest revision as of 22:13, 8 October 2012

Overview

All of the following functions are available from SEAL code.

Naming convention used in this document:

  • Sensor value – name of a SEAL sensor, including user-defined sensors.
  • Scalar value – a predefined constant, a variable, or an integer literal.

Calling the functions

Functions can be called from SEAL code by specifying the name of the function, followed by arguments enclosed in brackets.

Some of the functions have synomyns. The they can be called from either of those names.

Optional arguments can be skipped; then they take default values. In contrast, some arguments can be 'repeated one or more times. The description of the functions mention which arguments are optional, and which can be repeated.

Functions parameters can also be named. For example, to call contrast function on 20 samples of light sensor readings, using the weight coefficient 2.0 you can write contrast(Light, numSamples 20, weight 2.0) .

The meaning is the same as for contrast(Light, 20, 2.0), but the former approach leads to self-documenting code.

If named, the parameetrs can also be written in mixed order, for example, contrast(numSamples 20, weight 2.0, value Light).

Arithmetic functions

sum(value, ...)

Sum of one or more values.

Argument: a sensor value or a scalar.

Argument can be repeated zero to many times.

Aggregate function (i.e. can have take() as parameter).

Example syntax:

  1. sum(Light, Humidity, -12) – calculates sum of last light sensor reading with last humidity sensor reading and -12 (i.e. subtracts 12).
  2. sum(take(Light, 10)) – calculates sum of last 10 light sensor readings

plus(value1, value2)

Addition.

Arguments: sensor values or scalars.

Synonym: add

Example syntax: plus(Light, Humidity) – calculates sum of light and humidity sensor readings

minus(value1, value2)

Subtraction.

Arguments: sensor values or scalars.

Synonym: subtract

Example syntax: minus(Light, Humidity) – calculates value of the expression: light sensor value minus humidity sensor value.

times(value1, value2)

Multiplication.

Arguments: sensor values or scalars.

Synonym: multiply

Example syntax: times(Light, 3) – calculates the value of light sensor reading multiplied by three.

divide(value1, value2)

Division.

Arguments: sensor values or scalars.

Example syntax: divide(Light, 3) – calculates the value of light sensor reading divided by three and rounded down to the nearest integer.

modulo(value1, value2)

The remainder in division.

Arguments: sensor values or scalars.

Example syntax: modulo(Random, 3) – calculates the remainder of a random number value divided by three.

difference(value1, value2)

Symmetrical difference.

Argument: sensor values or scalars.

Example syntax: difference(13, 14) calculates the absolute value of the difference between two values 13 and 14. Same as abs(minus(13, 14)).

abs(value)

Absolute value.

Argument: a sensor value or a scalar.

Example syntax: abs(Temperature) – calculate the absolute valute of temperature sensor reading

neg(value)

Negation.

Argument: a sensor value or a scalar.

Example syntax: neg(Humidity) – calculate the negation valute of humidity sensor reading

invert(value)

Return the Boolean inverse of the value passed: True if the value is zero, False otherwise.

Argument: a sensor value or a scalar.

Example syntax: invert(Random) – evaluates to true if the last random number is zero.

square(value)

Calculate square (second power) of a value.

Argument: a sensor value or a scalar.

Example syntax: square(Random) – calculate the square of the last random number.

sqrt(value)

Calculate square root of a value.

Argument: a sensor value or a scalar.

Example syntax: sqrt(Random) – calculates the square root of the last random number rounded to the nearest integer. Depending on the implmentation, approximate values may be returned!

power(base, exponent)

Exponentiation.

Arguments: base is a sensor value or a scalar, exponent must be scalar.

Example syntax: power(Random, 3) – calculate the cube of the last random number.


Data aggregation functions

min(value, ...)

Minimal value.

Argument: a sensor value or a scalar

Argument can be repeated one to many times.

Aggregate function (i.e. can have take() as parameter).

Example syntax:

  1. min(Light, 10) – calculate the minimum of light sensor reading and the number 10;
  2. min(take(Light, 100)) – calculate the minimum of the last 100 light sensor readings.

max(value, ...)

Maximal value.

Argument: a sensor value or a scalar

Argument can be repeated one to many times.

Aggregate function (i.e. can have take() as parameter).

Example syntax:

  1. max(Light, 10) – calculate the maximum of the light sensor reading and the number 10;
  2. max(take(Light, 100)) – calculate the maximum of the last 100 light sensor readings.

average(value)

Average value (the mean).

Argument: a sensor value or a scalar

Aggregate function (i.e. can have take() as parameter).

Synonym: avg

Example syntax:

  1. average(Light) – calculate the average of light sensor readings during program's execution;
  2. average(take(Light, 100)) – calculate the average of the last 100 light sensor readings.

stdev(value)

Standard deviation.

Argument: a sensor value or a scalar

Aggregate function (i.e. can have take() as parameter).

Synonym: std

Example syntax:

  1. stdev(Light) – calculate the standard deviation of light sensor readings during program's execution;
  2. stdev(take(Light, 100)) – calculate the standard deviation of the last 100 light sensor readings.

variance(value)

Signal variance.

Argument: a sensor value or a scalar

Aggregate function (i.e. can have take() as parameter).

Example syntax:

  1. variance(Light) – calculate the variance of light sensor readings during program's execution;
  2. variance(take(Light, 100)) – calculate the variance of the last 100 light sensor readings.

ewma(value, alpha)

Exponential moving average with coefficient alpha.

Arguments: 'value' is a sensor value or a scalar, 'alpha' is a scalar (including floating point) value.

Example syntax:

  1. ewma(Light, 0.5) – calculate the exponential moving average of light sensor readings during program's execution with coefficient 0.5;
  2. ewma(take(Light, 100), 0.5) – calculate the same, but for the last 100 light sensor readings.

changed(value)

Calculate a Boolean value that describes whether the value has changed.

Argument: a sensor value or a scalar

Example syntax:

  1. changed(Light) – true if light sensor reading have changed during program's execution.
  2. changed(take(Light, 100)) – true if light sensor reading have changed during last 100 readings.
  3. changed(13) – always false, because the value is constant.


Signal processing functions

map(value, fromRangeLow, fromRangeHigh, toRangeLow, toRangeHigh)

Do mapping.

Arguments: 'value' is a sensor value or a scalar. The arguments 'fromRangeLow' and 'fromRangeHigh' are scalars that define the lower and upper bound of the range from which to map; the arguments 'toRangeLow' and 'toRangeHigh' are scalars that define the range to which to map.

Example syntax: map(Light, 0, 1023, 0, 255) – map light sensor reading from range [0..1023] (10 bit range, e.g. ADC) to range [0..255] (eight bit range, e.g. for a variable of char type).

sharpen(value, numSamples, weight)

Add contrast.

Arguments: 'value' is a sensor value or a scalar. 'numSamples' (optional, default value 3) – a scalar value that describes the number of samples to take. 'weight' (optional, default value 1) – a scalar value (can be florating point) that describes the amplitude of the sharpening.

Synonym: contrast

Example syntax: sharpen(Light) – add contrast to light sensor readings using the default values.


smoothen(value, numSamples, weight)

Remove contrast.

Arguments: 'value' is a sensor value or a scalar. 'numSamples' (optional, default value 3) – a scalar value that describes the number of samples to take. 'weight' (optional, default value 1) – a scalar value (can be florating point) that describes the amplitude of the bluring.

Synonym: blur

Example syntax: smoothen(Light) – add blur to light sensor readings using the default values.

Filtering functions

match(value, pattern)

Match sensor readings against a predefined patter.

Arguments: 'value' is a sensor value or a scalar. 'pattern' is the name of a predefined pattern in the source file.

Example syntax: pattern P (0, 0, 0, 0); ...; match(Light, pattern) – compare last four light sensor reading with four consecutive zeros and evaluate to True in case of match, False otherwise.

filterRange(value, thresholdMin, thresholdMin)

Threshold sensor readings against predefined lower and upper bounds.

Arguments: 'value' is a sensor value or a scalar. 'thresholdMin' and 'thresholdMin' are scalars that define the range [thresholdMin..thresholdMin].

Example syntax: filterRange(Light, 1000, 2000) – read only those light sensor values that are between 1000 and 2000, inclusive, and ignore the rest.

filterEqual(value, threshold)

Arguments: 'value' is a sensor value or a scalar. 'threshold' is a scalar.

Example syntax: filterEqual(Light, 1000) – read only those light sensor values that are equal to 1000, and ignore the rest.

filterNotEqual(value, threshold)

Argument: 'value' is a sensor value or a scalar. 'threshold' is a scalar.

Example syntax: filterNotEqual(Light, 1000) – read only those light sensor values that are not equal to 1000, and ignore the rest.

filterLess(value, threshold)

Argument: 'value' is a sensor value or a scalar. 'threshold' is a scalar.

Example syntax: filterLess(Light, 1000) – read only those light sensor values that are less than 1000, and ignore the rest.

filterLessOrEqual(value, threshold)

Argument: 'value' is a sensor value or a scalar. 'threshold' is a scalar.

Example syntax: filterLessOrEqual(Light, 1000) – read only those light sensor values that are less than or equal to 1000, and ignore the rest.

filterMore(value, threshold)

Argument: 'value' is a sensor value or a scalar. 'threshold' is a scalar.

Example syntax: filterMore(Light, 1000) – read only those light sensor values that more than to 1000, and ignore the rest.

filterMoreOrEqual(value, threshold)

Argument: 'value' is a sensor value or a scalar. 'threshold' is a scalar.

Example syntax: filterMoreOrEqual(Light, 1000) – read only those light sensor values that are more than or equal to 1000, and ignore the rest.

invertFilter(value)

Invert the effect of any previosly applied filters, or filter out the value if there were none.

Argument: 'value' is a sensor value or a scalar

Example syntax: invertFilter(filterRange(Light, 1000, 2000)) – read only those light sensor values that are NOT bewteen 1000 and 2000, inclusive, and ignore those that are.


Subset selection & special purpose functions

if(conditionValue, ifValue, elseValue)

Logical IF function. If conditionValue is true (nonzero), then ifValue is returned. Else elseValue is returned.

elseValue is optional, and has default value of zero.

Arguments: sensor values.

Example syntax:

  • if(True, Temperature, Humidity) – if 'True' is true, then read light and humidity values.
  • when Light < 100: set ConditionValue True; end;

    define BoundedLight if(ConditionValue, Light, 100); – this is a more practical example that uses states (the ConditionValue variable) to achieve conditional behaviour. If Light sensor reads less than 100, then reading BoundedLight will return light value, else it will return the number 100.


take(value, numberToTake, timeToTake)

Take one or more sensor value. The values are read one at time, but the enclosing function is evaluated on all of them. At the start of program, the values that are not read yet are treated as zero.

take can only be used in context of specific enclosing functions – those that are marked as aggregate.

Arguments: 'value' is a sensor value. 'numberToTake' is a scalar value that describes the number of sensor values to read. 'timeToTake' (optional, default value is not specified) is the time period in which to limit the values.

Example syntax:

  1. sum(take(Random, 100)) – calculate sum of 100 random numbers.
  2. sum(take(Light, 600, 1h)) – calculate sum of light sensor readings sampled in the last hour, and limit their count to six hundred (600).

tuple(value, ...)

Read multiple, heterogenous sensor values.

tuple can only be used in context of specific enclosing functions – those that are marked as aggregate.

Argument: sensor values.

Example syntax: tuple(Light, Temperature, Humidity) – read a tuple of light, temperature, and humidity sensor values.

sync(value, ...)

Synchronize reading of multiple sensors.

Arguments: sensor values.

Example syntax: sync(Light, Temperature, Humidity) – synchronize light, temperature, and humidity sensor reading.