Script examples

Here are some script examples:

Script1

This script takes two physical sensors and calculates two virtual sensors out of that with frequency at one per second.

object {

    M1 = Machine("innius.com", "MilkTank")

    S1 = Sensor(M1, "Distance1")

    S2 = Sensor(M1, "Distance2")

    V1 = VirtualSensor(M1, "DistanceDifference")

    V2 = VirtualSensor(M1, "MilkAmount")

}

 

each (t:second) {

   V1[t] =  abs(S1[t]-S2[t])

    V2[t] = (sqrt(800 + S1[t])) + 10

}

 

output {

  V2, V1

}

 

Script2

This script counts the total value produced by adding the Carton counter value (Sensor S2) of the previous measurement (t-1) up to and including the current time (t), without evaluating the value of the Power sensor. This will be calculated every second. In the calculation of the second sensor, conditional counter, the value of the Power sensor S1 will be evaluated, whether it is equal to '1'. If it is, the total value produced by adding the Carton counter value (Sensor S2) of the previous measurement (t-1) up to and including current time (t). This will be calculated every second as well.

object {

    M1 = Machine("innius.com", "ConveyerBelt")

    S1 = Sensor(M1, "Power")

    S2 = Sensor(M1, "CartonCounter")

    V1 = VirtualSensor(M1, "SecondCounter")

    V2 = VirtualSensor(M1, "ConditionalCounter")

}

 

each (t: second) {

  V1[t] = sum(S2[t-1,t])

 V2[t] = sumif(S2[t-1,t], S1[t] == 1)

 }

 

output {

   V1, V2

}

 

Script 3:

This script counts the total value produced by adding up the input quantity (Sensor S1) of the previous measurement (t-1) up to and including current time (t). This will be calculated every second. The second calculation based on this outcome is calculating the sum over the Second quantity (Sensor V1) every 10 seconds.

object {

    M1 = Machine("innius.com", "Counting")

    S1 = Sensor(M1, "Input")

    V1 = VirtualSensor(M1, "Second")

    V2 = VirtualSensor(M1, "10second")

}

 

each (t: second) {

    V1[t] = sum(S1[t-1,t])

 }

each(t: 10 second) {

  V2[t] = sum(V1[t-1,t])

}

output {

    V1, V2

}

 

Script 4:

This script calculates the average temperature as a virtual sensor, based on two physical temperature sensors in the machine. Both physical temperature sensors are measuring at a frequency of 1 second. The average temperature based on that is also calculated with the same frequency of 1 per second.

object {

 M1 = Machine("innius.com", "MilkCartonMachine")

 Temperature1 = Sensor(M1,"Temperature1")

 Temperature2 = Sensor(M1, "Temperature2")

 AverageTemperature= VirtualSensor(M1, "AverageTemperature")

}

 

each (t:second) {

 AverageTemperature[t] = (Temperature1[t] + Temperature2[t]) / 2

}

 

output {

 AverageTemperature

}

 

Script 5:

This script calculates the production speed of the machine per minute as a virtual sensor, based on a physical cumulative counter sensor. Also calculates a virtual sensor for the threshold of the speed per minute, based on a physical sensor which indicates the type of product being produced. There is an extra calculation for the speed per minute to prevent the value dropping below 0 when the physical cumulative counter is reset by the machine operator, for example. All sensors are set at a frequency of 1 second.

object {
M1 = Machine("innius.com","MilkCartonMachine")
Cartoncounter = Sensor(M1,"Cartoncounter")
Milkpercarton = Sensor(M1,"Milkpercarton")
Cartonslastminute = VirtualSensor(M1,"Cartonslastminute")
CartonThreshold = VirtualSensor(M1,"CartonThreshold")
}

each (t:second) {
Cartonslastminute[t] = Cartoncounter[t] - Cartoncounter[t-60]


if(Milkpercarton[t] == 2)
{
CartonThreshold[t] = 350
}
else
{
CartonThreshold[t] = 290
}

if(Cartonslastminute[t] < 2)
{
Cartonslastminute[t] = 0
}


}

output {
Cartonslastminute, CartonThreshold
}

 

 

 

Have more questions? Submit a request

Comments