NOBのArduino日記!

NOBのArduino日記!

趣味は車・バイク・自転車・ラジコン・電子工作です。

Arduino IDE(CurieIMU.getDetectionThresholdの使い方)

■CurieIMU.getDetectionThreshold関数
  CurieIMU.hライブラリの CurieIMU.getDetectionThreshold関数は、検出閾値の値を返します。

■使用例
 CurieIMU.getDetectionThreshold関数を使ったArduinoIDEのプログラム例は図1の通りです。
 このプログラムを実行すると「落下」「衝突」「動く」「止まる」「叩く」の動作を判定する機能を持つ関数の閾値を、mg単位で図2の様にシリアルモニタ上に出力します。

#include "CurieIMU.h"

void setup() {
  Serial.begin(9600); // シリアル通信を初期化
  while (!Serial);    // シリアルポートが開くのを待つ

  // デバイスの初期化
  Serial.println("Initializing IMU device...");
  CurieIMU.begin();

  // 加速度計の範囲を2Gに設定する
  CurieIMU.setAccelerometerRange(2);
}

void loop() {
  float ax, ay, az;   //スケールされた加速度計の値

  // デバイスからの加速度計測定値を設定された範囲にスケール
  CurieIMU.readAccelerometerScaled(ax, ay, az);

  // タブで区切られた加速度計のx / y / z値を表示する
  Serial.print("getDetectionThreshold_FREEFALL:");
  Serial.print(CurieIMU.getDetectionThreshold(CURIE_IMU_FREEFALL));
  Serial.println("mg");
  Serial.print("getDetectionThreshold_SHOCK:");
  Serial.print(CurieIMU.getDetectionThreshold(CURIE_IMU_SHOCK));
  Serial.println("mg");
  Serial.print("getDetectionThreshold_MOTION:");
  Serial.print(CurieIMU.getDetectionThreshold(CURIE_IMU_MOTION));
  Serial.println("mg");
  Serial.print("getDetectionThreshold_ZERO_MOTION:");
  Serial.print(CurieIMU.getDetectionThreshold(CURIE_IMU_ZERO_MOTION));
  Serial.println("mg");
  Serial.print("getDetectionThreshold_TAP:");
  Serial.print(CurieIMU.getDetectionThreshold(CURIE_IMU_TAP));
  Serial.println("mg");
  delay(5000);
}
イメージ 1
図1:プログラム例
 
イメージ 1
図2:プログラム実行結果
 

■「CurieIMU.getDetectionThreshold(feature)」のパラメータ
 feature:指定した表1に示すいずれかの機能に設定された検出閾値を返します。

表1:feature(機能)
項目 内容
CURIE_IMU_FREEFALL 落下の判定
CURIE_IMU_SHOCK 衝突の判定
CURIE_IMU_MOTION 動くの判定
CURIE_IMU_ZERO_MOTION  止まるの判定
CURIE_IMU_TAP 叩くの判定
 
 戻り値選択されたフィーチャの検出しきい値(単位:mg)
     返される値の範囲は、加速度計の範囲設定に関連しています。
 
■その他関数
 Curie IMUライブラリに関するその他関数については、コチラをご覧ください。
 
イメージ 1 イメージ 3
励みになりますのでよければクリック下さい(^o^)/

↩【ArduinoIDE reference】目次に戻る