Skip to content

Commit 5671917

Browse files
Christa03sys_maker
authored and
sys_maker
committedJul 22, 2016
Jira509:add IMU examples:FreeFallDetection, MotionDetection,ZeroMotionDetection; change CurieIMU.cpp line490 from 'setZeroMotionDetectionThreshold' to 'setZeroMtionDetectionDuration'
1 parent 12b2376 commit 5671917

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed
 

‎libraries/CurieIMU/examples/ZeroMotionDetect/ZeroMotionDetect.ino

+27-14
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,53 @@
99
*/
1010
#include "CurieIMU.h"
1111

12-
boolean blinkState = false; // state of the LED
13-
unsigned long loopTime = 0; // get the time since program started
14-
unsigned long interruptsTime = 0; // get the time when zero motion event is detected
12+
boolean ledState = false; // state of the LED
1513
void setup() {
1614
Serial.begin(9600);
1715
while(!Serial); // wait for the serial port to open
1816

1917
/* Initialise the IMU */
20-
blinkState = CurieIMU.begin();
18+
CurieIMU.begin();
2119
CurieIMU.attachInterrupt(eventCallback);
2220

2321
/* Enable Zero Motion Detection */
24-
CurieIMU.setDetectionThreshold(CURIE_IMU_ZERO_MOTION, 1500); // 1.5g=1500mg
25-
CurieIMU.setDetectionDuration(CURIE_IMU_ZERO_MOTION, 25); // 25s
22+
CurieIMU.setDetectionThreshold(CURIE_IMU_ZERO_MOTION, 50); // 50mg
23+
CurieIMU.setDetectionDuration(CURIE_IMU_ZERO_MOTION, 2); // 2s
2624
CurieIMU.interrupts(CURIE_IMU_ZERO_MOTION);
2725

26+
/* Enable Motion Detection */
27+
CurieIMU.setDetectionThreshold(CURIE_IMU_MOTION, 20); // 20mg
28+
CurieIMU.setDetectionDuration(CURIE_IMU_MOTION, 10); // trigger times of consecutive slope data points
29+
CurieIMU.interrupts(CURIE_IMU_MOTION);
30+
2831
Serial.println("IMU initialisation complete, waiting for events...");
2932
}
3033

3134
void loop() {
32-
//if zero motion is detected in 1500ms, LED will be turned up
33-
loopTime = millis();
34-
if(abs(loopTime -interruptsTime) < 1500)
35-
blinkState = true;
36-
else
37-
blinkState = false;
38-
digitalWrite(13, blinkState);
35+
// if zero motion is detected, LED will be turned up.
36+
digitalWrite(13, ledState);
3937
}
4038

4139
static void eventCallback(void){
4240
if (CurieIMU.getInterruptStatus(CURIE_IMU_ZERO_MOTION)) {
43-
interruptsTime = millis();
41+
ledState = true;
4442
Serial.println("zero motion detected...");
4543
}
44+
if (CurieIMU.getInterruptStatus(CURIE_IMU_MOTION)) {
45+
ledState = false;
46+
if (CurieIMU.motionDetected(X_AXIS, POSITIVE))
47+
Serial.println("Negative motion detected on X-axis");
48+
if (CurieIMU.motionDetected(X_AXIS, NEGATIVE))
49+
Serial.println("Positive motion detected on X-axis");
50+
if (CurieIMU.motionDetected(Y_AXIS, POSITIVE))
51+
Serial.println("Negative motion detected on Y-axis");
52+
if (CurieIMU.motionDetected(Y_AXIS, NEGATIVE))
53+
Serial.println("Positive motion detected on Y-axis");
54+
if (CurieIMU.motionDetected(Z_AXIS, POSITIVE))
55+
Serial.println("Negative motion detected on Z-axis");
56+
if (CurieIMU.motionDetected(Z_AXIS, NEGATIVE))
57+
Serial.println("Positive motion detected on Z-axis");
58+
}
4659
}
4760

4861
/*

‎libraries/CurieIMU/src/CurieIMU.cpp

+1-11
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,6 @@ float CurieIMUClass::getDetectionThreshold(int feature)
432432
return getTapDetectionThreshold();
433433

434434
case CURIE_IMU_STEP:
435-
case CURIE_IMU_TAP_SHOCK:
436-
case CURIE_IMU_TAP_QUIET:
437435
case CURIE_IMU_DOUBLE_TAP:
438436
case CURIE_IMU_FIFO_FULL:
439437
case CURIE_IMU_DATA_READY:
@@ -466,8 +464,6 @@ void CurieIMUClass::setDetectionThreshold(int feature, float threshold)
466464
break;
467465

468466
case CURIE_IMU_STEP:
469-
case CURIE_IMU_TAP_SHOCK:
470-
case CURIE_IMU_TAP_QUIET:
471467
case CURIE_IMU_DOUBLE_TAP:
472468
case CURIE_IMU_FIFO_FULL:
473469
case CURIE_IMU_DATA_READY:
@@ -795,7 +791,7 @@ void CurieIMUClass::setDetectionDuration(int feature, float value)
795791
break;
796792

797793
case CURIE_IMU_ZERO_MOTION:
798-
setZeroMotionDetectionThreshold(value);
794+
setZeroMotionDetectionDuration(value);
799795
break;
800796

801797
case CURIE_IMU_TAP_QUIET:
@@ -1465,8 +1461,6 @@ void CurieIMUClass::enableInterrupt(int feature, bool enabled)
14651461
setIntDataReadyEnabled(enabled);
14661462
break;
14671463

1468-
case CURIE_IMU_TAP_QUIET:
1469-
case CURIE_IMU_TAP_SHOCK:
14701464
default:
14711465
break;
14721466
}
@@ -1502,8 +1496,6 @@ bool CurieIMUClass::interruptsEnabled(int feature)
15021496
case CURIE_IMU_DATA_READY:
15031497
return getIntDataReadyEnabled();
15041498

1505-
case CURIE_IMU_TAP_QUIET:
1506-
case CURIE_IMU_TAP_SHOCK:
15071499
default:
15081500
return false;
15091501
}
@@ -1539,8 +1531,6 @@ bool CurieIMUClass::getInterruptStatus(int feature)
15391531
case CURIE_IMU_DATA_READY:
15401532
return getIntDataReadyStatus();
15411533

1542-
case CURIE_IMU_TAP_QUIET:
1543-
case CURIE_IMU_TAP_SHOCK:
15441534
default:
15451535
return false;
15461536
}

0 commit comments

Comments
 (0)
Please sign in to comment.