ISSDK  1.8
IoT Sensing Software Development Kit
motionCheck.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 /*! \file motionCheck.c
10  \brief check to see if the board is moving.
11 
12  This function would normally be called from your fusion_tasks in your main.c.
13  See main_freertos_two_tasks_power_cycling.c for example usage.
14 */
15 
16 // Sensor Fusion Headers
17 #include "sensor_fusion.h" // top level magCal and sensor fusion interfaces
18 
19 /// The motionCheck() function is not a sensor fusion function. It is a function
20 /// that simply monitors an accelerometer or magnetometer tri-axial sensor output,
21 /// returning Boolean true if the sensor appears to be stationary, and false otherwise.
22 /// This function would normally be called from your fusion_tasks in your main().
24  float sample[3], ///< processed triaxial sensor sample (accel or mag)
25  float baseline[3], ///< previous value to compare to
26  float tolerance, ///< how much tolerance you can stand
27  uint32_t winLength, ///< how many samples need to be stable to assert "noMotion"
28  uint32_t *count ///< how many samples so far we've been not moving
29 )
30 {
31  float change[3];
32  bool changed;
33  change[CHX] = fabs(baseline[CHX] - sample[CHX]);
34  change[CHY] = fabs(baseline[CHY] - sample[CHY]);
35  change[CHZ] = fabs(baseline[CHZ] - sample[CHZ]);
36  changed = (change[CHX]>tolerance) ||
37  (change[CHY]>tolerance) ||
38  (change[CHZ]>tolerance);
39  if (changed) {
40  baseline[CHX] = sample[CHX];
41  baseline[CHY] = sample[CHY];
42  baseline[CHZ] = sample[CHZ];
43  *count = 0;
44  } else {
45  if ((*count) <= winLength) (*count) += 1;
46  }
47  return(*count > winLength);
48 }
#define CHZ
Used to access Z-channel entries in various data data structures.
Definition: sensor_fusion.h:62
#define CHY
Used to access Y-channel entries in various data data structures.
Definition: sensor_fusion.h:61
The sensor_fusion.h file implements the top level programming interface.
#define CHX
Used to access X-channel entries in various data data structures.
Definition: sensor_fusion.h:60
bool motionCheck(float sample[3], float baseline[3], float tolerance, uint32_t winLength, uint32_t *count)
Definition: motionCheck.c:23