如何在esp8266代码中包括YAW值?

时间:2019-09-25 14:44:23

标签: esp8266 arduino-esp8266

我有带MPU6050的esp8266集成电路。

我正在使用github librery连接两个模块

它可以很好地显示PITCH和ROLL,但不能显示YAW值。

如何在此代码中包含YAW值?

是否可以通过俯仰和滚动来计算偏航角值。

代码如下 LIBRARY I GOT

  

#include <Wire.h>
#include <ESP8266WiFi.h> 
#include <MPU6050.h>

MPU6050 mpu;

int SCL_PIN=D1;
int SDA_PIN=D2;

void setup() 
{
  WiFi.forceSleepBegin();// turn off ESP8266 RF
  delay(1);
  Serial.begin(9600);

  Serial.println("Initialize MPU6050");

  while(!mpu.beginSoftwareI2C(SCL_PIN,SDA_PIN,MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
  {
    Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
    delay(500);
  }
}

void loop()
{
  // Read normalized values 
  Vector normAccel = mpu.readNormalizeAccel();

  // Calculate Pitch & Roll
  int pitch = -(atan2(normAccel.XAxis, sqrt(normAccel.YAxis*normAccel.YAxis + normAccel.ZAxis*normAccel.ZAxis))*180.0)/M_PI;
  int roll = (atan2(normAccel.YAxis, normAccel.ZAxis)*180.0)/M_PI;

  // Output
  Serial.print(" Pitch = ");
  Serial.print(pitch);
  Serial.print(" Roll = ");
  Serial.print(roll);
  
  Serial.println();
  
  delay(10);
}

0 个答案:

没有答案