Cs75保养灯归零:MPU6050归零是如何工作的(mpu6050 motion detection)

大家晚上好。我目前正在进行一个带有智能窗户的项目,其中我将测量温度,湿度加速度,并且我将有一个用于窗户度的陀螺仪。我已经决定继续使用哪些传感器,其中之一是 MPU6050。我想问的问题是我如何使用传感器,以便我可以在加速结束时进行测量,而不是在开始时进行测量?我拥有的 esp32 将在所有时间内唤醒数据并发送数据

#include "Wire.h"
#include "SPI.h"
// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
// for both cles must be in the include path of your project
#include "I2Cdev.h"
#include "MPU6050.h"
// cl default I2C address is 0x68
// specific I2C addresses may be ped as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 accelgyro;
int16_t ax, ay, az;
int16_t gx, gy, gz;
int8_t thresld, count;
float temp;
bool zero_detect;
bool TurnOnZI = false;
bool XnegMD, XposMD, YnegMD, YposMD, ZnegMD, ZposMD;
int minVal=265; int maxVal=402;
double x; double y; double z;
#define LED_PIN 13
#define BUTTON_PIN_BITMASK 0x200000000 // 2^33 in hex
RTC_DATA_ATTR int bootCount = 0;
bool blinkState = false;
void print_wakeup_reason() {
  esp_sleep_wakeup_cause_t wakeup_reason;
  wakeup_reason = esp_sleep_get_wakeup_cause();
  switch (wakeup_reason)
  {
    case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
    case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
    case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break;
    case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;
    case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break;
    default : Serial.printf("Wakeup was not caused by deep sleep: %d\n", wakeup_reason); break;
  }
}
void setup() {
  // join I2C bus (I2Cdev library doesn't do this automatically)
  Wire.begin();
  // initialize serial communication
  // (38400 csen because it works as well at 8MHz as it does at 16MHz, but
  // it's really up to you depending on your project)
  Serial.begin(115200);
  //Increment boot number and print it every reboot
  ++bootCount;
  Serial.println("Boot number: " + String(bootCount));
  //Print the wakeup reason for ESP32
  print_wakeup_reason();
  // initialize device
  Serial.println("Initializing I2C devices...");
  accelgyro.initialize();
  // verify connection
  Serial.println("Testing device connections...");
  Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
  esp_sleep_enable_ext0_wakeup(GPIO_NUM_15, 1); //1 = High, 0 = Low
  //accelgyro.setTempSensorEnabled(false);
  
  //Set up zero motion
  /** Get accelerometer power-on delay.
    The accelerometer data path provides samples to the sensor registers, Motion
    detection, Zero Motion detection, and Free Fall detection modules. The
    signal path contains filters which must be flushed on wake-up with new
    samples before the detection modules begin operations. The default wake-up
    delay, of 4ms can be lengthened by up to 3ms. This additional delay is
    specified in ACCEL_ON_DELAY in units of 1 LSB = 1 ms. The user may select
    any value above zero unless instructed otherwise by InvenSense. Please refer
    to Section 8 of the MPU-6000/MPU-6050 Product Specification doent for
    further information regarding the detection modules.
    @return Current accelerometer power-on delay
    @see MPU60X0_RA_MOT_DETECT_CTRL
    @see MPU60X0_DETECT_ACCEL_ON_DELAY_BIT
  */
  accelgyro.setAccelerometerPowerOnDelay(3);
  /** Get Zero Motion Detection interrupt enabled status.
    Will be set 0 for disabled, 1 for enabled.
    @return Current interrupt enabled status
    @see MPU60X0_RA_INT_ENABLE
    @see MPU60X0_INTERRUPT_ZMOT_BIT
  **/
  accelgyro.setIntZeroMotionEnabled(true);
  //accelgyro.setIntMotionEnabled(true);
  /** Get the high-p filter configuration.
    The DHPF is a filter module in the path leading to motion detectors (Free
    Fall, Motion thresld, and Zero Motion). The high p filter output is not
    available to the data registers (see Figure in Section 8 of the MPU-6000/
    MPU-6050 Product Specification doent).
    The high p filter has three modes:
       Reset: The filter output settles to zero within one sample. This
              effectively disables the high p filter. This mode may be toggled
              to quickly settle the filter.
       On:    The high p filter will p signals above the cut off frequency.
       Hold:  When triggered, the filter lds the present sample. The filter
              output will be the difference between the input sample and the held
              sample.
    ACCEL_HPF | Filter Mode | Cut-off Frequency
    ----------+-------------+------------------
    0         | Reset       | None
    1         | On          | 5Hz
    2         | On          | 2.5Hz
    3         | On          | 1.25Hz
    4         | On          | 0.63Hz
    7         | Hold        | None
    </pre>
    @return Current high-p filter configuration
    @see MPU60X0_DHPF_RESET
    @see MPU60X0_RA_ACCEL_CONFIG
  */
  //DEBUG_PRINTLN("Setting DHPF bandwidth to 5Hz...");
  accelgyro.setDHPFMode(1);
  /** Get motion detection event acceleration thresld.
    This register configures the detection thresld for Motion interrupt
    generation. The unit of MOT_THR is 1LSB = 2mg. Motion is detected when the
    absolute value of any of the accelerometer measurements exceeds this Motion
    detection thresld. This condition increments the Motion detection duration
    counter (Register 32). The Motion detection interrupt is triggered when the
    Motion Detection counter reaches the time count specified in MOT_DUR
    (Register 32).
    The Motion interrupt will indicate the axis and polarity of detected motion
    in MOT_DETECT_STATUS (Register 97).
    For more details on the Motion detection interrupt, see Section 8.3 of the
    MPU-6000/MPU-6050 Product Specification doent as well as Registers 56 and
    58 of this doent.
    @return Current motion detection acceleration thresld value (LSB = 2mg)
    @see MPU60X0_RA_MOT_THR
  */
  //Serial.println("Setting motion detection thresld to 16...");
  //accelgyro.setMotionDetectionThresld(16);
  /** Get zero motion detection event acceleration thresld.
    This register configures the detection thresld for Zero Motion interrupt
    generation. The unit of ZRMOT_THR is 1LSB = 2mg. Zero Motion is detected when
    the absolute value of the accelerometer measurements for the 3 axes are each
    less than the detection thresld. This condition increments the Zero Motion
    duration counter (Register 34). The Zero Motion interrupt is triggered when
    the Zero Motion duration counter reaches the time count specified in
    ZRMOT_DUR (Register 34).
    Unlike Free Fall or Motion detection, Zero Motion detection triggers an
    interrupt both when Zero Motion is first detected and when Zero Motion is no
    longer detected.
    When a zero motion event is detected, a Zero Motion Status will be indicated
    in the MOT_DETECT_STATUS register (Register 97). When a motion-to-zero-motion
    condition is detected, the status bit is set to 1. When a zero-motion-to-
    motion condition is detected, the status bit is set to 0.
    For more details on the Zero Motion detection interrupt, see Section 8.4 of
    the MPU-6000/MPU-6050 Product Specification doent as well as Registers 56
    and 58 of this doent.
    @return Current zero motion detection acceleration thresld value (LSB = 2mg)
    @see MPU60X0_RA_ZRMOT_THR
  */
  Serial.println("Setting zero-motion detection thresld to 156...");
  accelgyro.setZeroMotionDetectionThresld(64);
  /** Get motion detection event duration thresld.
    This register configures the duration counter thresld for Motion interrupt
    generation. The duration counter ticks at 1 kHz, therefore MOT_DUR has a unit
    of 1LSB = 1ms. The Motion detection duration counter increments when the
    absolute value of any of the accelerometer measurements exceeds the Motion
    detection thresld (Register 31). The Motion detection interrupt is
    triggered when the Motion detection counter reaches the time count specified
    in this register.
    For more details on the Motion detection interrupt, see Section 8.3 of the
    MPU-6000/MPU-6050 Product Specification doent.
    @return Current motion detection duration thresld value (LSB = 1ms)
    @see MPU60X0_RA_MOT_DUR
  */
  Serial.println("Setting motion detection duration to 40...");
  //accelgyro.setMotionDetectionDuration(2);
  /** Get zero motion detection event duration thresld.
    This register configures the duration counter thresld for Zero Motion
    interrupt generation. The duration counter ticks at 16 Hz, therefore
    ZRMOT_DUR has a unit of 1 LSB = 64 ms. The Zero Motion duration counter
    increments while the absolute value of the accelerometer measurements are
    each less than the detection thresld (Register 33). The Zero Motion
    interrupt is triggered when the Zero Motion duration counter reaches the time
    count specified in this register.
    For more details on the Zero Motion detection interrupt, see Section 8.4 of
    the MPU-6000/MPU-6050 Product Specification doent, as well as Registers 56
    and 58 of this doent.
    @return Current zero motion detection duration thresld value (LSB = 64ms)
    @see MPU60X0_RA_ZRMOT_DUR
  */
  //Serial.println("Setting zero-motion detection duration to 0...");
  accelgyro.setZeroMotionDetectionDuration(64);
  
  //for (int i = 0; i < 1; i++) {
    // read raw accel/gyro measurements from device
    Serial.println("Getting raw accwl/gyro measurements");
    //accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
    Serial.println("Getting Motion indicators, count and thresld");
    XnegMD = accelgyro.getXNegMotionDetected();
    XposMD = accelgyro.getXPosMotionDetected();
    YnegMD = accelgyro.getYNegMotionDetected();
    YposMD = accelgyro.getYPosMotionDetected();
    ZnegMD = accelgyro.getZNegMotionDetected();
    ZposMD = accelgyro.getZPosMotionDetected();
    zero_detect = accelgyro.getIntMotionStatus();
    thresld = accelgyro.getZeroMotionDetectionThresld();
    //Serial.println("Got to count");
    //count = accelgyro.getMotionDetectionCounterDecrement();
    /** Get current internal temperature.
      @return Temperature reading in 16-bit 2's complement format
      @see MPU60X0_RA_TEMP_OUT_H
    */
    Serial.println("Getting Die Temperature");
    temp = (accelgyro.getTemperature() / 340.) + 36.53;
    /*  The accelerometer and gyroscope measurements are explained in the MPU-6050
      datasheet in the GYRO_CONFIG and ACCEL_CONFIG register descriptions (sections 4.4
      and 4.5 on pages 14 and 15). The scale of each depends on the sensitivity settings
      csen, which can be one of +/- 2, 4, 8, or 16g for the accelerometer and one of
      +/- 250, 500, 1000, or 2000 deg/sec for the gyroscope. The accelerometer produces data
      in units of acceleration (distance over time2), and the gyroscope produces data in units
      of rotational velocity (rotation distance over time).
      The output scale for any setting is [-32768, +32767] for each of the six axes. The default
      setting in the I2Cdevlib cl is +/- 2g for the accel and +/- 250 deg/sec for the gyro. If
      the device is perfectly level and not moving, then:
          X/Y accel axes suld read 0
          Z accel axis suld read 1g, which is +16384 at a sensitivity of 2g
          X/Y/Z gyro axes suld read 0
      In reality, the accel axes won't read exactly 0 since it is difficult to be perfectly level
      and there is some noise/error, and the gyros will also not read exactly 0 for the same reason
      (noise/error).
    */
    // these metds (and a few others) are also available
    accelgyro.getAcceleration(&ax, &ay, &az);
    accelgyro.getRotation(&gx, &gy, &gz);
//    Serial.print(temp); Serial.print(",");
//    Serial.print(ax / 16384.); Serial.print(",");
//    Serial.print(ay / 16384.); Serial.print(",");
//    Serial.print(az / 16384.); Serial.print(",");
//    Serial.print(gx / 131.072); Serial.print(",");
//    Serial.print(gy / 131.072); Serial.print(",");
//    Serial.print(gz / 131.072); Serial.print(",");
    Serial.print(zero_detect); Serial.print(",");
    //Serial.print(XnegMD); Serial.print(",");
    //Serial.println(XposMD);
  int xAng = map(ax,minVal,maxVal,-90,90); 
    int yAng = map(ay,minVal,maxVal,-90,90); 
    int zAng = map(az,minVal,maxVal,-90,90);
x= RAD_TO_DEG * (atan2(-yAng, -zAng)+PI); 
y= RAD_TO_DEG * (atan2(-xAng, -zAng)+PI); 
z= RAD_TO_DEG * (atan2(-yAng, -xAng)+PI);
Serial.print("AngleX= "); Serial.println(x);
Serial.print("AngleY= "); Serial.println(y);
Serial.print("AngleZ= "); Serial.println(z);
    
    // display tab-separated accel/gyro x/y/z values
    /*
      Serial.print("a/g:\t");
      Serial.print(ax/16384.); Serial.print("\t");
      Serial.print(ay/16384.); Serial.print("\t");
      Serial.print(az/16384.); Serial.print("\t");
      Serial.print(gx/131.072); Serial.print("\t");
      Serial.print(gy/131.072); Serial.print("\t");
      Serial.println(gz/131.072);
      Serial.print("DieTemp:\t");Serial.println(temp);
      Serial.print("ZeroMotion(97):\t");
      Serial.print(zero_detect); Serial.print("\t");
      Serial.print("Count: \t");Serial.print(count); Serial.print("\t");
      Serial.print(XnegMD); Serial.print("\t");
      Serial.print(XposMD); Serial.print("\t");
      Serial.print(YnegMD); Serial.print("\t");
      Serial.print(YposMD); Serial.print("\t");
      Serial.print(ZnegMD); Serial.print("\t");
      Serial.println(ZposMD);
    */
   // delay(1000);
    // blink LED to indicate activity
    //    blinkState = !blinkState;
    //    digitalWrite(LED_PIN, blinkState);
  //}
  // configure Arduino LED for
  //pinMode(LED_PIN, OUTPUT);
  Serial.println("Going to sleep now");
  esp_deep_sleep_start();
  Serial.println("This will never be printed");
}
void loop() {
}
0

你应该改变你的一般概念。打开一个窗口可以发生在“部分”。所以你可以期望得到几个运动开始和运动停止中断。你应该做的是:第一次中断让设备保持清醒 — — 比如说 — — 3 秒。如果有进一步的中断,然后重新启动你的计时器 (在硬件计时器中称为“重新触发”)。当 3 秒过去时,读取传感器以获得新的窗度,然后再次发送此信息。

本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处

(594)
温控器代码大全:Lua代码“测试器”(lua code checker)
上一篇
服务器重启指令:Nextcloud服务器重新启动损坏
下一篇

相关推荐

  • cvt变速箱结构图解:CVT变速箱的工作原理

    CVT变速箱是一种无级变速箱,它的结构由两个部分组成:输入轴和输出轴。输入轴由发动机驱动,输出轴将变速箱的输出转移到车轮上。输入轴上安装有一个可变的滑轮,它可以改变输入轴的传动比,从而改变变速箱的输出比。另外,输入轴上还安装有一个液压系统,它可以控制滑轮的位置,从而改变输入轴的传动比。…

    2023-04-02 04:00:04
    0 45 71
  • xcode代码格式化快捷键:使用Command + I快速格式化Xcode代码

    格式化的方法格式化的方法Xcode代码格式化快捷键:Option+Command+F…

    2023-07-13 12:44:06
    0 72 96
  • cv树洞柒夜事件CV树洞中的秘密与惊奇

    cv树洞柒夜事件是一个有趣的计算机视觉活动,它提供了一种新的方式来利用计算机视觉技术来探索和发现景观。它始于2020年7月,由一群热爱计算机视觉的研究者和开发者发起,他们希望通过使用机器学习技术来探索景观中的精彩之处。cv树洞柒夜事件的目标是使用机器学习技术来探索景观中的精彩之处,并利用这些发现来改善景观设计。参与者需要使用机器学习技术来探索景观,并利用这些发现来改善景观设计。参与者可以使用Python,OpenCV,TensorFlow等技术来完成任务,并将其发布在GitHub上。…

    2023-01-09 12:42:42
    0 70 14
  • win10怎么cmd打开设置:如何在Windows 10中使用CMD打开设置

    打开“开始”菜单,点击搜索框,输入cmd,然后按下回车键。在弹出的命令提示符窗口中,输入以下代码:start ms-:…

    2023-06-07 01:59:36
    0 42 76
  • win7安装cad2020:如何在Windows 7上安装AutoCAD 2020

    从官网下载CAD 2020的安装包,并双击安装文件;按照安装向导的提示,选择安装语言、安装位置和安装类型;…

    2023-09-28 00:41:59
    0 36 10
  • java protected关键字:使用protected关键字保护类成员的优点

    示例示例关键字是java中的修饰符,它可以修饰类、变量和方法。修饰类:修饰的类只能在同一个包内被访问,如果子类继承了修饰的父类,则子类可以在不同包内访问父类的成员。…

    2023-04-18 04:45:37
    0 30 36
  • codeblocks手机版下载一款强大的跨平台编程工具

    CodeBlocks是一款免费的、开源的、跨平台的C/C++ IDE,支持多种编程语言,可以用来编写、调试和编译代码。目前CodeBlocks的手机版本只支持Android系统,而且只支持C语言,不支持C++。…

    2023-06-25 04:48:50
    0 32 90
  • go和come的区别:去吧!来吧!改变你的未来

    示例示例go和come的区别:Go是一个动词,表示“去”的意思,指的是从一个地方到另一个地方的运动。Come是一个动词,表示“来”的意思,指的是从另一个地方到当前地方的运动。…

    2023-05-25 16:09:00
    0 35 63

发表评论

登录 后才能评论

评论列表(20条)