LTPS Movement Analysis

LTPS Movement Analysis

About the Application

This tutotial demonstrates the options LTPS can be integrated with AggreGate platform. Understanding of the process implies some basic knowledge of the platform. For communication with a device we will use a TPS-driver mentioned in the previous tutorials. As for the platform, its models and alarms will be required. Let's create an App based on a function block diagram (FBD) and an ST function. The code serves the purpose of analysing the LTPS movement. As soon as the movements are detected the data of the ambient light sensor undergo further analysis. If the light is not bright enough, the LED will be turned on for additional lighting. After that if need to turn off alarm and LED, push the button.

What you need


On-board Software


First, let's create a helper function for the data of the 3-axis accelerometer to be processed. A helper function will be written in ST language. It's time to create a code in ST with settings left default.


In the opened window, create local variables.

Declaration of variables

    newX, newY, newZ : DINT;
    averregeVal : DINT;
    differences : ARRAY[0..4] OF DINT;
    summ : DINT;
    i : LINT;

Now we can create functions for average (value) computing to reduce and eliminate random noise in the accelerometer output.

Implementation of the function

summ :=0;
FOR i := 4 TO 1 BY 1 DO
    differences[i] := differences[i-1];
    summ := summ + differences[i];
differences[0] := newX + newY + newZ;
summ := summ + differences[0];
averregeVal := summ / 5;


Implementation of the program logic. General program will be created by building a function block diagram (FBD). When creating a code, the following properties must be set:

  1. Type - Program;
  2. Import - add a previously created calculateAverageMovement program;
  3. Task - true;
  4. Device Context - LTPS (already created);
  5. Execution Type - Cycle.

Basic scheme of the program:

To implement the scheme, we will need a function block employing a previously created and imported function. As soon as the function block is added it requires function values to be set (see the screenshot below).


To create a scheme, it is necessary to add several "inputs" with the expressions written in ST language. Inside themselves, the functions use the Aggregate expression language. Let's drill down two types of the expressiones from the scheme:

А) Getting the value of one coordinate from the table.

OBJECT_TO_DINT(cell({users.admin.devices.TPSAgent:s6_tibbit36} , "accelerationX" , 0 , FALSE))
//1 - ST function "OBJECT_TO_DINT"
//2 - AggreGate expression language "cell" 
//cell paramiters:
//{users.admin.devices.TPSAgent:s6_tibbit36} - dataTable from context, "accelerationX" - field, 0 - row, FALSE - description. 

B) Getting the value from the table and after the comparison operation.

OBJECT_TO_DINT(cell({users.admin.devices.TPSAgent:s4_tibbit28}, "illumination" , 0 , FALSE)) < 30
//1 - ST function "OBJECT_TO_DINT"
//2 - AggreGate expression language "cell" 
//cell paramiters:
//{users.admin.devices.TPSAgent:s4_tibbit28} - dataTable from context, "illumination" - field, 0 - row, FALSE - description.
//3 - compare <.

Nested and simple environment

Conditions mentioned in the scheme are implemented as jumps to the lable (see blocks 7 and 9). The jump condition will be successfully done right after the Boolean expression is calculated in the "input".


It is necessary to create the model with a variable which controls alarms.


Finally, it's time to run the program. As soon as it detects a motion it will change the variable value in the model and trigger the alarm in AggreGate platform. If the lighting is not sufficient the program will turn on the LED. After that if need to turn off alarm and LED, push the button.

LTPS Movement Analysis