سلام
بنده از Arduino IDE برای برنامه نویسی برد ESP32 استفاده می کنم.
کدی دارم که با بردهای آردوینو کامپایل می شود ولی وقتی می خواهم همان کد را بر روی برد ESP32 کامپایل کنم از قسمتی از کد که مربوط به کتابخانه MATH.H هست ایراد می گیرد.
ظاهرا این کتابخانه را پیدا نمی کند
چگونه می توانم این مشکل را برطرف کنم؟

// 3 Axis QST5883L Magnetometer Tilt compensation using ADXl345#include “Wire.h”
#include “I2Cdev.h”
#include “math.h”
#include “ADXL345.h”//#include <AbsMouse.h>
#define BUTTON_CAL 2
#define BUTTON_TEST 5
#define LED 4 // LED_BUILTIN pin 13 is also SPICLK SCK//#define EEADDR 98 //66 // Start location to write EEPROM data.
#define CALTIME 10000 // In ms.
#define SMOOTH_ACCELL 20ADXL345 accel;
static byte stat,ovfl,skipped;
static int minx,maxx,miny,maxy,minz,maxz;
static int offx=0,offy=0,offz=0;static int degTest=0,updateSpeed=1000;
int tbearing;
int x,y,z; // Raw compass output values.
int bearing,i;int startbearing;
bool getStartbearing = false;
int MagnetometerX = 0;float mouseX = 0;
float mouseY = 0;float LastMouseX;
int Xresolution = 800;
int Yresolution = 800;//////////////////////////////////////////////
#include <MPU6050_light.h>MPU6050 mpu(Wire);
unsigned long timer = 0;/////////////////////////////////////////////////////////////
// Generic I2C write to I2C device with address, i2cAddrvoid I2C_write_AddrDev_AddrReg_Byte(byte i2cAddr, byte regaddr, byte d )
{
Wire.beginTransmission(i2cAddr);
Wire.write(regaddr);
Wire.write(d);
Wire.endTransmission();
}/////////////////////////////////////////////////////////////
void calc_offsets(void) {
offx = (maxx+minx)/2; // maxx/2 - minx/2 + 2minx/2
offy = (maxy+miny)/2;
offz = (maxz+minz)/2;
}/////////////////////////////////////////////////////////////
byte magnetometerReady(void) {
// Data ready?
Wire.beginTransmission(0x0d); // Read from status reg
Wire.write(0x06);
int num = Wire.requestFrom((byte)0x0d, (byte)1);
stat = Wire.read(); // DOR Data out Ready (SKIPPED).
Wire.endTransmission();ovfl = stat & 0x02;
skipped = stat & 0x04;return (stat && 0x01); // 0x01 is the DRDY Data Ready flag
}/////////////////////////////////////////////////////////////
// If data is not ready x,y,z are not changed.
// raw data is aligned to QST5883L coords
byte getMagnetometerRaw(int16_t *x, int16_t *y, int16_t *z)
{if ( !magnetometerReady() ) return 0;
Wire.beginTransmission(0x0d);
Wire.write(0x00); // read from address zero = x,y,z registers.
int err = Wire.endTransmission();if (!err) {
Wire.requestFrom((byte)0x0d, (byte)6); //Blocking?
while(Wire.available()<6); //Wait if above blocking then this not needed.
*x = (int16_t)(Wire.read() | Wire.read() << 8);
*y = (int16_t)(Wire.read() | Wire.read() << 8);
*z = (int16_t)(Wire.read() | Wire.read() << 8);
}
return 1;
}/////////////////////////////////////////////////////////////
// Orient to board coordinates
void getMagnetometer(int16_t *x, int16_t *y, int16_t *z) {if ( !getMagnetometerRaw(x, y, z) ) return;
// modify for accel board orientation (board x = up, y to left).
*y = -(*y);
}/////////////////////////////////////////////////////////////
float getMagnetometerBearing(int16_t x, int16_t y, int16_t z) {float atan2val = 180/M_PI * atan2((float)y,(float)x); // NEW coords.
int b = (int)(-atan2val + 360 ) % 360;
return b;
}/////////////////////////////////////////////////////////////
// Blocking: Waits in this function for reading to be ready.
void readMagnetometer(int16_t *x, int16_t *y,int16_t *z) {
while( !magnetometerReady() );
getMagnetometer(x, y, z); // Note: Addresses of pointers passed.
}///////////////////////////////////////////////////////////////
float getMagnetometerTiltCompensatedBearing(int x, int y, int z) {
float r, p, mx, my, mz;getRollPitch(&r, &p);
// Convert back to radians
//int rdeg = r;
//int pdeg = p;
r = (M_PI/180)*r;
p = (M_PI/180)*p;mx = (float)x;
my = (float)y;
mz = (float)z;int cx = (int)( mxcos(p) + mysin(r)sin(p) - mzcos(r)sin(p) );
int cy = (int)( mycos(r) + mz*sin(r) );
// Also diffrerent here:
// Tilt Compensating a Compass with an Accelerometer - Tutorials - Love Electronics
// Same as 1st!!!int tx=cx,ty=cy,tz=z; // Done offx,y above
float atan2val = 180/M_PI * atan2((float)(ty),(float)(tx));int tb = (int)(-atan2val + 360 ) % 360;
return tb;
}
///////////////////////////////////////////////////////////////
// Returns angle calculated from z, y, z accelerometers.
//
void getRollPitchRawFloat(float *roll, float *pitch) {
float r,x,y,z;
int16_t ax, ay, az;// Datasheet: OPERATION AT VOLTAGES OTHER THAN 2.5 V
// 3v3 X,Y 25mg too high, z 20mg too low
// 3V3 lsb value 265/g c (g/265)=0.03698
// 2V5 lsb value 256/g (g/256)=0.03828 z axis unaffected by voltage supply.
#define ADXL345_LSBVAL_3V3 3.698E-3
#define ADXL345_LSBVAL_2V5 3.828E-3accel.getAcceleration(&ax, &ay, &az);
x = (float)axADXL345_LSBVAL_3V3 - 25E-3;
y = (float)ayADXL345_LSBVAL_3V3 - 25E-3;
z = (float)az*ADXL345_LSBVAL_2V5 + 20e-3;r = sqrt(xx+yy+z*z);
// modify for accel board orientation (board x = up, y to left).
y = -y;
*pitch = 180/M_PI * asin(x/r);
*roll = 180/M_PI * -asin(y/r);
}///////////////////////////////////////////////////////////////
void getRollPitch(float *roll, float *pitch) {
static float avg_r[SMOOTH_ACCELL], avg_p[SMOOTH_ACCELL];
static byte idx=0;
float r,p;getRollPitchRawFloat(roll, pitch);
avg_r[idx] = *roll; // Smooth.
avg_p[idx] = *pitch;
idx++;
if (idx>=SMOOTH_ACCELL) idx = 0;r = p = 0;
for (int i=0; i<SMOOTH_ACCELL; i++) {
r += avg_r[i];
p += avg_p[i];
}
r /= SMOOTH_ACCELL;
p /= SMOOTH_ACCELL;*roll = r;
*pitch = p;
}/////////////////////////////////////////////////////////////
void setup()
{
delay(3000);
Wire.begin();
Serial.begin(115200);
//Serial.begin(9600);//AbsMouse.init(Xresolution, Yresolution);
////////////////////////////mpu 6050/////////////////
byte status = mpu.begin();
Serial.print(F("MPU6050 status: "));
Serial.println(status);
while(status!=0){ } // stop everything if could not connect to MPU6050Serial.println(F(“Calculating offsets, do not move MPU6050”));
delay(1000);
// mpu.upsideDownMounting = true; // uncomment this line if the MPU6050 is mounted upside-down
mpu.calcOffsets(); // gyro and accelero
Serial.println(“Done!\n”);
/////////////////////////////////pinMode(LED,OUTPUT);
pinMode(BUTTON_CAL,INPUT_PULLUP);
pinMode(BUTTON_TEST,INPUT_PULLUP);// Wire.begin(); // Start I2C
Wire.setClock(100000); // Test at high speed// Datasheet suggests this for chip startup HMC5883L.
// Set reset register.Datasheet suggests this as 0x01.
I2C_write_AddrDev_AddrReg_Byte(0x0d,0x0b,1);
// Control reg : Mode:continuous, ODR:10Hz, RNG:2G, OSR:512 (over sample)
// I2C_write_AddrDev_AddrReg_Byte(0x0d,0x09,B00000001);
// In lab gauss > 2G so need higher range.
I2C_write_AddrDev_AddrReg_Byte(0x0d,0x09,B00010001);calc_offsets();
//Serial.println(“Compass hmc5883L”);
accel.initialize();
Serial.println(F(“Testing device connections…”));
Serial.print(F("ADXL345 connection "));
Serial.println(accel.testConnection() ? F(“successful”) : F(“failed”) );accel.setFullResolution(ADXL345_RANGE_2G);
accel.setRate(ADXL345_RATE_100); // This is default but shows the value.accel.setFullResolution(1); // 0 => 10 bit mode.
accel.setLowPowerEnabled(0);
accel.setRange(0); // 0 => 2g, 3 => 16g
}/////////////////////////////////////////////////////////////
// Can choose whether to write to EEPROM for testing.
void calibrate(boolean eeprom_write, byte xy_or_z) {
unsigned long calTimeWas = millis();int x,y,z;
float deg=0,deg2=0;readMagnetometer(&x, &y, &z);
maxx = minx = x; // Set initial values to current magnetometer readings.
maxy = miny = y;
maxz = minz = z;delay(300); // Allow button release.
while(1) { // Calibration loop.
if (digitalRead(BUTTON_CAL)==0 || digitalRead(BUTTON_TEST)==0) { delay(300); // Allow button release. return; // Abort } if ( magnetometerReady() ) getMagnetometer(&x, &y, &z); if (x>maxx) maxx = x; if (x<minx) minx = x; if (y>maxy) maxy = y; if (y<miny) miny = y; if (z>maxz) maxz = z; if (z<minz) minz = z; int secmillis = millis()-calTimeWas; if (secmillis>CALTIME) break; // Exit after time up. delay(10);} // while cal
if (xy_or_z==0) {
offx = ((maxx-minx)/2)+minx;
offy = ((maxy-miny)/2)+miny;
} else
offz = ((maxz-minz)/2)+minz;calc_offsets();
}void loop(void)
{///////////////////////mpu6050////////////////////
mpu.update();if((millis()-timer)>1){
mouseX = mpu.getAngleZ(); mouseY = mpu.getAngleX();//if(mouseX == 0 || mouseX == 1 || mouseX == -1)LastGyroZ = GyroZ;
/*
if(LastGyroZ<0)
{
while(LastGyroZ<0)GyroZ = GyroZ-1;
LastGyroZ= GyroZ;
}
else
if(LastGyroZ>0)
{
while(LastGyroZ>0)GyroZ = GyroZ+1;
LastGyroZ= GyroZ;
}
*///timer = millis();
//}///////////////////////////////////////////
if (digitalRead(BUTTON_CAL)==0) { calibrate(1,0); calibrate(1,1); }
if (digitalRead(BUTTON_TEST)==0) { calibrate(0,0); calibrate(0,1); }getMagnetometer(&x,&y,&z);
bearing = (int)getMagnetometerBearing(x-offx, y-offy, z-offz);
tbearing = getMagnetometerTiltCompensatedBearing(x-offx, y-offy, z-offz);
if(getStartbearing == false)
{
if(startbearing == 0)
{
startbearing = tbearing;
}
else
{
getStartbearing = true;
}
}MagnetometerX = tbearing-startbearing;
int endbearing = startbearing-360;
//tbearing = (tbearing > 180)? tbearing - 360 : tbearing;
if(MagnetometerX == 0)
{
LastMouseX = mouseX;
}mouseX = mpu.getAngleZ()-LastMouseX; mouseY = mpu.getAngleX(); mouseX = -mouseX+(Xresolution/2); mouseY = -mouseY+(Yresolution/2); Serial.print(mouseX); Serial.print("\t"); Serial.print(mouseY); Serial.print("\t"); Serial.print(MagnetometerX); Serial.print("\t"); Serial.println(LastMouseX); //AbsMouse.move(mouseX,mouseY);//mouseX = tbearing-startbearing;
//Serial.println(mouseX);
//Serial.println(x);
//Serial.print(“\t”);
//Serial.print(y);
//Serial.print(“\t”);
//Serial.print(bearing);
//Serial.print(“\tmouseX : “);
//Serial.println(mouseX);
//Serial.print(”\t”);
//Serial.print("\ttbearing : ");
//Serial.println(tbearing);
timer = millis();
}
}