solaESKF_EIGEN

Dependencies:   mbed LPS25HB_I2C LSM9DS1 PIDcontroller LoopTicker GPSUBX_UART_Eigen SBUS_without_mainfile MedianFilter Eigen UsaPack solaESKF_Eigen Vector3 CalibrateMagneto FastPWM

Committer:
cocorlow
Date:
Fri Dec 10 10:43:50 2021 +0000
Revision:
141:725321fe2949
Parent:
139:b378528c05f2
Child:
143:53808e4e684c
Eigen completed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cocorlow 141:725321fe2949 1 #include "global.hpp"
cocorlow 141:725321fe2949 2
cocorlow 141:725321fe2949 3 void getHilIMUval()
cocorlow 141:725321fe2949 4 {
cocorlow 141:725321fe2949 5 switch(vp.commandIndex){
cocorlow 141:725321fe2949 6 case 1:
cocorlow 141:725321fe2949 7 NVIC_SystemReset();
cocorlow 141:725321fe2949 8 break;
cocorlow 141:725321fe2949 9 default :
cocorlow 141:725321fe2949 10 break;
cocorlow 141:725321fe2949 11 }
cocorlow 141:725321fe2949 12 rpy_align(0) = 0.0f;
cocorlow 141:725321fe2949 13 rpy_align(1) = 0.0f;
cocorlow 141:725321fe2949 14 accref(2) = 1.0f;
cocorlow 141:725321fe2949 15
cocorlow 141:725321fe2949 16
cocorlow 141:725321fe2949 17 lsm.readAccel();
cocorlow 141:725321fe2949 18 lsm.readMag();
cocorlow 141:725321fe2949 19 lsm.readGyro();
cocorlow 141:725321fe2949 20
cocorlow 141:725321fe2949 21 float accmx = lsm.ax * 9.8f - agoffset[0];
cocorlow 141:725321fe2949 22 float accmy = lsm.ay * 9.8f - agoffset[1];
cocorlow 141:725321fe2949 23 float accmz = lsm.az * 9.8f - agoffset[2];
cocorlow 141:725321fe2949 24 float gyromx = (lsm.gx * M_PI_F / 180.0f) - agoffset[3];
cocorlow 141:725321fe2949 25 float gyromy = (lsm.gy * M_PI_F / 180.0f) - agoffset[4];
cocorlow 141:725321fe2949 26 float gyromz = (lsm.gz * M_PI_F / 180.0f) - agoffset[5];
cocorlow 141:725321fe2949 27
cocorlow 141:725321fe2949 28 // gx gy gz ax ay az
cocorlow 141:725321fe2949 29 // 加速度値を分解能で割って加速度(m/s^2)に変換する
cocorlow 141:725321fe2949 30 acc(0) = 9.8f*float(vp.accData[0]) / 4096.0f + accmx; //FS_SEL_0 16,384 LSB / g
cocorlow 141:725321fe2949 31 acc(1) = 9.8f*float(vp.accData[1]) / 4096.0f + accmy;
cocorlow 141:725321fe2949 32 acc(2) = 9.8f*float(vp.accData[2]) / 4096.0f + accmy;
cocorlow 141:725321fe2949 33
cocorlow 141:725321fe2949 34 // 角速度値を分解能で割って角速度(rad per sec)に変換する
cocorlow 141:725321fe2949 35 gyro(0) = float(vp.gyroData[0]) / 131.0f * 0.0174533f + gyromx; // (rad/s)
cocorlow 141:725321fe2949 36 gyro(1) = float(vp.gyroData[1]) / 131.0f * 0.0174533f + gyromy;
cocorlow 141:725321fe2949 37 gyro(2) = float(vp.gyroData[2]) / 131.0f * 0.0174533f + gyromz;
cocorlow 141:725321fe2949 38
cocorlow 141:725321fe2949 39 Vector3f magraw;
cocorlow 141:725321fe2949 40 magraw(0) = float(vp.magData[0])/1000.0f + (lsm.mx-magref(0));
cocorlow 141:725321fe2949 41 magraw(1) = float(vp.magData[1])/1000.0f + (lsm.my-magref(1));
cocorlow 141:725321fe2949 42 magraw(2) = float(vp.magData[2])/1000.0f + (lsm.mz-magref(2));
cocorlow 141:725321fe2949 43
cocorlow 141:725321fe2949 44 //magres = magCalibrator.calcResidial(magraw);
cocorlow 141:725321fe2949 45 //if(magres > magresThreshold){
cocorlow 141:725321fe2949 46 // magCalibrator.updateParams(magraw,0.001f);
cocorlow 141:725321fe2949 47 //};
cocorlow 141:725321fe2949 48 Vector3f magmod = magraw;
cocorlow 141:725321fe2949 49 mag(0) = magmod(0);
cocorlow 141:725321fe2949 50 mag(1) = magmod(1);
cocorlow 141:725321fe2949 51 mag(2) = magmod(2);
cocorlow 141:725321fe2949 52
cocorlow 141:725321fe2949 53 palt = float(vp.piData[2])/1.0f -(lps.pressureToAltitudeMeters(lps.readPressureMillibars())-palt0);;
cocorlow 141:725321fe2949 54
cocorlow 141:725321fe2949 55 if(abs(vp.accData[0])<0.0001f && abs(vp.accData[1])<0.0001f && abs(vp.accData[2])<0.0001f){
cocorlow 141:725321fe2949 56 acc(2) += -9.8f;
cocorlow 141:725321fe2949 57 mag(0) += 0.5;
cocorlow 141:725321fe2949 58 }
cocorlow 141:725321fe2949 59 }
cocorlow 141:725321fe2949 60
cocorlow 141:725321fe2949 61 void getHilGPSval()
cocorlow 141:725321fe2949 62 {
cocorlow 141:725321fe2949 63 float sigma_vi = 0.1f;
cocorlow 141:725321fe2949 64 float sigma_pi = 1.0f;
cocorlow 141:725321fe2949 65
cocorlow 141:725321fe2949 66 //GPSの速度情報m/s
cocorlow 141:725321fe2949 67 vi(0) = float(vp.viData[0])/1000.0f + sigma_vi*randn();
cocorlow 141:725321fe2949 68 vi(1) = float(vp.viData[1])/1000.0f + sigma_vi*randn();
cocorlow 141:725321fe2949 69 vi(2) = float(vp.viData[2])/1000.0f + sigma_vi*randn();
cocorlow 141:725321fe2949 70
cocorlow 141:725321fe2949 71 //GPSの位置情報m/s
cocorlow 141:725321fe2949 72 pi(0) = float(vp.piData[0])/1.0f + sigma_pi*randn();
cocorlow 141:725321fe2949 73 pi(1) = float(vp.piData[1])/1.0f + sigma_pi*randn();
cocorlow 141:725321fe2949 74 pi(2) = float(vp.piData[2])/1.0f + sigma_pi*randn();
cocorlow 141:725321fe2949 75
cocorlow 141:725321fe2949 76 }
cocorlow 141:725321fe2949 77
cocorlow 141:725321fe2949 78 float randn()
cocorlow 141:725321fe2949 79 {
cocorlow 141:725321fe2949 80 float x = (float)rand()/RAND_MAX;
cocorlow 141:725321fe2949 81 float y = (float)rand()/RAND_MAX;
cocorlow 141:725321fe2949 82 float z1 = std::sqrt(-2.0 * std::log(x)) * std::cos(2.0 * M_PI_F * y);
cocorlow 141:725321fe2949 83 return z1;
cocorlow 141:725321fe2949 84 }