solaESKF_EIGEN

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

Committer:
NaotoMorita
Date:
Fri Jun 24 05:44:34 2022 +0000
Revision:
143:53808e4e684c
Parent:
141:725321fe2949
complete

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;
NaotoMorita 143:53808e4e684c 9 case 2:
NaotoMorita 143:53808e4e684c 10 hilDataOut = vp.commandVal;
NaotoMorita 143:53808e4e684c 11 break;
cocorlow 141:725321fe2949 12 default :
cocorlow 141:725321fe2949 13 break;
cocorlow 141:725321fe2949 14 }
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 Vector3f magmod = magraw;
cocorlow 141:725321fe2949 45 mag(0) = magmod(0);
cocorlow 141:725321fe2949 46 mag(1) = magmod(1);
cocorlow 141:725321fe2949 47 mag(2) = magmod(2);
cocorlow 141:725321fe2949 48
cocorlow 141:725321fe2949 49 palt = float(vp.piData[2])/1.0f -(lps.pressureToAltitudeMeters(lps.readPressureMillibars())-palt0);;
cocorlow 141:725321fe2949 50
cocorlow 141:725321fe2949 51 if(abs(vp.accData[0])<0.0001f && abs(vp.accData[1])<0.0001f && abs(vp.accData[2])<0.0001f){
cocorlow 141:725321fe2949 52 acc(2) += -9.8f;
cocorlow 141:725321fe2949 53 mag(0) += 0.5;
cocorlow 141:725321fe2949 54 }
cocorlow 141:725321fe2949 55 }
cocorlow 141:725321fe2949 56
cocorlow 141:725321fe2949 57 void getHilGPSval()
cocorlow 141:725321fe2949 58 {
cocorlow 141:725321fe2949 59 float sigma_vi = 0.1f;
cocorlow 141:725321fe2949 60 float sigma_pi = 1.0f;
cocorlow 141:725321fe2949 61
cocorlow 141:725321fe2949 62 //GPSの速度情報m/s
cocorlow 141:725321fe2949 63 vi(0) = float(vp.viData[0])/1000.0f + sigma_vi*randn();
cocorlow 141:725321fe2949 64 vi(1) = float(vp.viData[1])/1000.0f + sigma_vi*randn();
cocorlow 141:725321fe2949 65 vi(2) = float(vp.viData[2])/1000.0f + sigma_vi*randn();
cocorlow 141:725321fe2949 66
cocorlow 141:725321fe2949 67 //GPSの位置情報m/s
cocorlow 141:725321fe2949 68 pi(0) = float(vp.piData[0])/1.0f + sigma_pi*randn();
cocorlow 141:725321fe2949 69 pi(1) = float(vp.piData[1])/1.0f + sigma_pi*randn();
cocorlow 141:725321fe2949 70 pi(2) = float(vp.piData[2])/1.0f + sigma_pi*randn();
cocorlow 141:725321fe2949 71
cocorlow 141:725321fe2949 72 }
cocorlow 141:725321fe2949 73
cocorlow 141:725321fe2949 74 float randn()
cocorlow 141:725321fe2949 75 {
cocorlow 141:725321fe2949 76 float x = (float)rand()/RAND_MAX;
cocorlow 141:725321fe2949 77 float y = (float)rand()/RAND_MAX;
cocorlow 141:725321fe2949 78 float z1 = std::sqrt(-2.0 * std::log(x)) * std::cos(2.0 * M_PI_F * y);
cocorlow 141:725321fe2949 79 return z1;
cocorlow 141:725321fe2949 80 }