accSetAccelerationEvent (Function)

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


This function will enable or disable monitoring of the acceleration.

 

When monitoring is enabled, the accelerometer will compare the acceleration of an axis with a threshold value.

If the acceleration is above (or below) the threshold for the selected duration, an "Acceleration" event is raised. See also accWaitEvent for event # 7.

The accelerometer will continue to raise the event after each duration interval until the acceleration moves below (or above) the threshold again.

 

 

acc3d_acceleration_combined

If combined is true, then all axis conditions must be true for the event to be raised as illustrated above where all axes are required to be below threshold (also know as free fall).

 

 

Input:

Enable : BOOL (default FALSE)

Is event generation enabled.

 

Once : BOOL (default FALSE)

Event must be enabled again after detection.

 

Threshold: DINT (0..16000, default 0)

The acceleration which each axis is compared against (in mg).

 

Duration : DINT (0..5120, default 0)

Number of milliseconds the axis must be high/low before the axis condition is true.

 

Combined : BOOL (default FALSE)

Whether all axis conditions should be true or just a single one before the event is raised.

 

XAbove : BOOL (default FALSE)

Fire event when x-axis is above threshold for the duration.

 

XBelow : BOOL (default FALSE)

Fire event when x-axis is below threshold for the duration.

 

YAbove : BOOL (default FALSE)

Fire event when y-axis is above threshold for the duration.

 

YBelow : BOOL (default FALSE)

Fire event when y-axis is below threshold for the duration.

 

ZAbove : BOOL (default FALSE)

Fire event when z-axis is above threshold for the duration.

 

ZBelow : BOOL (default FALSE)

Fire event when z-axis is below threshold for the duration.

 

Output:

None.

 

Returns: INT

0

- OK

-1

- General error.

-2

- Interface not open (see accOpen).

-3

- Invalid threshold.

-4

- Invalid duration.

-5

- Conflict in combined axis.

 

Declaration:

FUNCTION accSetAccelerationEvent : INT;
VAR_INPUT
  Threshold   : DINT := 0;
  Duration    : DINT := 0;
  Once        : BOOL := FALSE;
  Combined    : BOOL := FALSE;
  XAbove      : BOOL := FALSE;
  XBelow      : BOOL := FALSE;
  YAbove      : BOOL := FALSE;
  YBelow      : BOOL := FALSE;
  ZAbove      : BOOL := FALSE;
  ZBelow      : BOOL := FALSE;
  Enable      : BOOL := FALSE;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
PROGRAM example;
  accOpen();
  accSetAccelerationEvent(Threshold := 500, Duration := 10, XAbove := TRUE, Enable := TRUE);
BEGIN
e := accWaitEvent(timeout := 60);  
 ...
END;
END_PROGRAM;