accAccelerationEvent (Functionblock)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

CX1, SX1, MX2 turbo/encore/warp, NX-200, NX-900, LX2, LX5

Firmware version:

2.40 / 1.40.00


accAccelerationEvent returns the information of an acceleration event.

Note that the information is only valid after an "Acceleration" event is raised; the event will be removed when this function block is called.

An "Acceleration" event is raised when the acceleration matches the parameters set when monitoring was enabled.

 

 

Input:

None.

 

Output:

XAbove   : BOOL

Was x-axis above threshold for the duration.

 

XBelow   : BOOL

Was x-axis below threshold for the duration.

 

YAbove   : BOOL

Was y-axis above threshold for the duration.

 

YBelow   : BOOL

Was y-axis below threshold for the duration.

 

ZAbove   : BOOL

Was z-axis above threshold for the duration.

 

ZBelow   : BOOL

was z-axis below threshold for the duration.

 

X : DINT

Last x-axis reading before event (mg).

 

Y : DINT

Last y-axis reading before event (mg).

 

Z : DINT

Last z-axis reading before event (mg).

 

Ready : BOOL

Indicates whether event was removed and data updated.

 

 

Declaration:

FUNCTION_BLOCK accAccelerationEvent;
VAR_OUTPUT
  X           : DINT;
  Y           : DINT;
  Z           : DINT;
  XAbove      : BOOL;
  XBelow      : BOOL;
  YAbove      : BOOL;
  YBelow      : BOOL;
  ZAbove      : BOOL;
  ZBelow      : BOOL;
  Ready       : BOOL;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
VAR
  acc : accAccelerationEvent;
END_VAR;
 
FUNCTION ReadAccEvent;
  acc();
  IF acc.ready THEN
    DebugMsg(message := "*** acceleration event received ***");
    DebugFmt(message := "-x=\4", v4 := acc.x);
    DebugFmt(message := "-y=\4", v4 := acc.y);
    DebugFmt(message := "-z=\4", v4 := acc.z);
  END_IF;
END_FUNCTION;
 
THREAD_BLOCK accMonitor;
VAR
  event : INT := 0;
END_VAR;
 
WHILE event <> -1 DO
  event := accWaitEvent(timeout := -1);
  CASE event OF
     ...
    7: ReadAccEvent();
     ...
  END_CASE;
END_WHILE;
END_THREAD_BLOCK;