HAPSRG / Mbed 2 deprecated HAPStail

Dependencies:   mbed MatrixMath LPS25HB_I2C LSM9DS1 Matrix2 PIDcontroller LoopTicker SBUS_without_mainfile UsaPack solaESKF_wind Vector3 CalibrateMagneto FastPWM

Committer:
osaka
Date:
Fri Jan 07 09:49:19 2022 +0000
Revision:
87:981895e1d4f2
Parent:
85:0b14a2a600fc
Child:
88:0fc5df2fddcb
GPS & mag fuse OK

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cocorlow 56:888379912f81 1 #ifndef __GLOBAL_HPP__
cocorlow 56:888379912f81 2 #define __GLOBAL_HPP__
cocorlow 56:888379912f81 3
cocorlow 56:888379912f81 4 #include "mbed.h"
cocorlow 56:888379912f81 5 #include "PIDcontroller.h"
cocorlow 56:888379912f81 6 #include "SBUS.hpp"
cocorlow 56:888379912f81 7 #include "LoopTicker.hpp"
osaka 83:0a644de28415 8 #include "LSM9DS1.h"
osaka 83:0a644de28415 9 #include "LPS.h"
osaka 83:0a644de28415 10 #include "solaESKF.hpp"
NaotoMorita 61:c05353850017 11 #include "CalibrateMagneto.h"
cocorlow 56:888379912f81 12 #include "I2Cdev.h"
cocorlow 56:888379912f81 13 #include "FastPWM.h"
cocorlow 56:888379912f81 14 #include <cmath>
cocorlow 56:888379912f81 15 #include "UsaPack.hpp"
cocorlow 56:888379912f81 16 #include "Vector3.hpp"
NaotoMorita 71:62eb45ecffe9 17 #include "ScErrStateEKF.hpp"
NaotoMorita 70:9e7be21475f8 18 #include "MedianFilter.hpp"
cocorlow 56:888379912f81 19
cocorlow 56:888379912f81 20 #define MPU6050_PWR_MGMT_1 0x6B
cocorlow 56:888379912f81 21 #define MPU_ADDRESS 0x68
cocorlow 56:888379912f81 22 #define M_PI 3.141592f
cocorlow 56:888379912f81 23 #define ACCEL_FSR MPU6050_ACCEL_FS_8
cocorlow 56:888379912f81 24 #define ACCEL_SSF 4096.0f
cocorlow 56:888379912f81 25 #define GYRO_FSR MPU6050_GYRO_FS_250
cocorlow 56:888379912f81 26 #define GYRO_SSF 131.0f
cocorlow 56:888379912f81 27 #define MPU6050_LPF MPU6050_DLPF_BW_256
cocorlow 56:888379912f81 28 #define gyro_th 20.0f
cocorlow 56:888379912f81 29 #define PID_dt 0.015f
osaka 87:981895e1d4f2 30 #define servoPwmMax 2100.0f
osaka 87:981895e1d4f2 31 #define servoPwmMin 900.0f
cocorlow 56:888379912f81 32 #define motorPwmMax 2000.0f
cocorlow 56:888379912f81 33 #define motorPwmMin 1100.0f
NaotoMorita 71:62eb45ecffe9 34 #define N_EEPROM 12
cocorlow 56:888379912f81 35
cocorlow 56:888379912f81 36 // struct union
cocorlow 56:888379912f81 37 union U
cocorlow 56:888379912f81 38 {
cocorlow 56:888379912f81 39 int i[N_EEPROM]; // 0: flag(>1で正常に書き込まれた状態) 1 ~ 3: 磁場の中心座標, 4: 磁場の半径、 5~7; mag, 8~10: acc bias
cocorlow 56:888379912f81 40 char c[N_EEPROM*4]; // floatはcharの4倍
cocorlow 56:888379912f81 41 };
cocorlow 56:888379912f81 42
cocorlow 56:888379912f81 43 struct valuePack
cocorlow 56:888379912f81 44 {
NaotoMorita 73:be7a8b8188de 45 float gyroBias[3];
NaotoMorita 73:be7a8b8188de 46 float gyroBiasCov[6];
cocorlow 56:888379912f81 47 float acc[3];
cocorlow 56:888379912f81 48 float gyro[3];
cocorlow 56:888379912f81 49 float mag[3];
cocorlow 56:888379912f81 50 float rpy[3];
cocorlow 63:851e96f54a86 51 float de;
cocorlow 63:851e96f54a86 52 float deobj;
NaotoMorita 73:be7a8b8188de 53 float rc[5];
cocorlow 63:851e96f54a86 54 };
cocorlow 63:851e96f54a86 55
NaotoMorita 73:be7a8b8188de 56 struct updatePack
cocorlow 63:851e96f54a86 57 {
osaka 84:028bd650e8bc 58 bool gpsUpdateFlag;
osaka 84:028bd650e8bc 59 char gps_fix;
osaka 84:028bd650e8bc 60 int gps_itow;
osaka 84:028bd650e8bc 61 float vi[3];
osaka 84:028bd650e8bc 62 float pi[3];
NaotoMorita 73:be7a8b8188de 63 float gyroBias[3];
NaotoMorita 73:be7a8b8188de 64 float de_command;
cocorlow 56:888379912f81 65 };
cocorlow 56:888379912f81 66
cocorlow 56:888379912f81 67 // var
cocorlow 56:888379912f81 68
cocorlow 56:888379912f81 69 // communication
cocorlow 56:888379912f81 70 extern Serial pc;
cocorlow 56:888379912f81 71 extern I2C i2c; // sda, scl
cocorlow 56:888379912f81 72 extern UsaPack tail; // log - tail
cocorlow 56:888379912f81 73 extern SBUS sbus;
cocorlow 56:888379912f81 74
cocorlow 56:888379912f81 75 // sensor
osaka 83:0a644de28415 76 extern LSM9DS1 lsm;
osaka 83:0a644de28415 77 extern LPS lps;
osaka 83:0a644de28415 78 //extern UsaPack sensor1;
osaka 83:0a644de28415 79 //extern UsaPack sensor2;
NaotoMorita 61:c05353850017 80 extern CalibrateMagneto magCalibrator;
cocorlow 56:888379912f81 81
cocorlow 56:888379912f81 82 // io
cocorlow 56:888379912f81 83 extern DigitalIn userButton;
cocorlow 56:888379912f81 84 extern DigitalIn locdef1;
cocorlow 56:888379912f81 85 extern DigitalIn locdef2;
cocorlow 56:888379912f81 86
cocorlow 56:888379912f81 87 // control
cocorlow 56:888379912f81 88 extern FastPWM servo;
cocorlow 56:888379912f81 89 extern PID pitchPID; // rad
cocorlow 56:888379912f81 90 extern PID pitchratePID;// rad/s
NaotoMorita 79:aa2631950f46 91 extern int itowVEL_log;
osaka 84:028bd650e8bc 92 extern solaESKF eskf;
cocorlow 56:888379912f81 93
cocorlow 56:888379912f81 94 extern int loop_count;
cocorlow 56:888379912f81 95 extern float att_dt;
cocorlow 56:888379912f81 96 extern float rc[16];
cocorlow 56:888379912f81 97
cocorlow 56:888379912f81 98 extern int16_t ax, ay, az;
cocorlow 56:888379912f81 99 extern int16_t gx, gy, gz;
cocorlow 56:888379912f81 100 extern float magval[3];
cocorlow 56:888379912f81 101
cocorlow 63:851e96f54a86 102 // elevator
cocorlow 63:851e96f54a86 103 extern float de;
cocorlow 63:851e96f54a86 104 extern float deobj;
cocorlow 63:851e96f54a86 105
cocorlow 56:888379912f81 106 // position
osaka 83:0a644de28415 107 extern Matrix SensorAlignmentAG;
osaka 83:0a644de28415 108 extern Matrix SensorAlignmentMAG;
osaka 85:0b14a2a600fc 109 extern Matrix euler;
cocorlow 56:888379912f81 110 extern Vector3 rpy; // x:roll y:pitch z:yaw
cocorlow 56:888379912f81 111 extern Vector3 acc;
cocorlow 56:888379912f81 112 extern Vector3 accref;
cocorlow 56:888379912f81 113 extern Vector3 mag;
cocorlow 56:888379912f81 114 extern Vector3 magref;
cocorlow 56:888379912f81 115 extern Vector3 gyro;
NaotoMorita 71:62eb45ecffe9 116 extern Vector3 vb;
osaka 83:0a644de28415 117 extern float palt;
osaka 83:0a644de28415 118 extern float palt0;
NaotoMorita 70:9e7be21475f8 119 extern MedianFilter accMedian;
NaotoMorita 70:9e7be21475f8 120 extern MedianFilter gyroMedian;
NaotoMorita 70:9e7be21475f8 121 extern MedianFilter magMedian;
osaka 84:028bd650e8bc 122 extern bool headingUpdateFlag;
osaka 84:028bd650e8bc 123 extern float dynaccnorm2;
cocorlow 56:888379912f81 124
cocorlow 56:888379912f81 125
cocorlow 56:888379912f81 126 extern float scaledServoOut[1];
cocorlow 56:888379912f81 127 extern float servoOut[1];
cocorlow 56:888379912f81 128
cocorlow 56:888379912f81 129
cocorlow 56:888379912f81 130 extern float val_thmg;
NaotoMorita 61:c05353850017 131 extern float sigma_thmg;
cocorlow 56:888379912f81 132 extern float th_mg;
cocorlow 56:888379912f81 133 extern float accnormerr;
NaotoMorita 61:c05353850017 134 extern float sigma_accnorm;
NaotoMorita 61:c05353850017 135
cocorlow 56:888379912f81 136 extern int calibrationFlag;
cocorlow 56:888379912f81 137 extern int pos_tail; // 0:left 1:center 2:right
cocorlow 56:888379912f81 138 extern int agoffset[6];
NaotoMorita 61:c05353850017 139 extern float magbiasMin[3];
NaotoMorita 61:c05353850017 140 extern float magbiasMax[3];
NaotoMorita 70:9e7be21475f8 141 extern float accMin[3];
NaotoMorita 70:9e7be21475f8 142 extern float accMax[3];
cocorlow 56:888379912f81 143
cocorlow 56:888379912f81 144 extern Vector3 rpy_align;
cocorlow 56:888379912f81 145
cocorlow 56:888379912f81 146 // eepromのread writeのためのunionを定義
cocorlow 56:888379912f81 147 extern const int eeprom_address; // EEPROMの3つの入力が全て+より
cocorlow 56:888379912f81 148 extern const int eeprom_pointeraddress;
cocorlow 56:888379912f81 149
cocorlow 56:888379912f81 150 //// UsaPack
cocorlow 56:888379912f81 151 extern const int tail_address[3];
cocorlow 63:851e96f54a86 152 extern const int time_address;
NaotoMorita 73:be7a8b8188de 153 extern valuePack posValues;
NaotoMorita 73:be7a8b8188de 154 extern updatePack updateValues;
cocorlow 63:851e96f54a86 155 extern Timer system_dt;
cocorlow 56:888379912f81 156
cocorlow 56:888379912f81 157 // function
cocorlow 56:888379912f81 158
cocorlow 56:888379912f81 159 // main.cpp
cocorlow 56:888379912f81 160
cocorlow 56:888379912f81 161 // setup.cpp
cocorlow 56:888379912f81 162 extern void setup();
cocorlow 56:888379912f81 163 extern void calibrate();
NaotoMorita 70:9e7be21475f8 164 extern float accScaleCalibrate(int attNo);
cocorlow 56:888379912f81 165
cocorlow 56:888379912f81 166 // run.cpp
osaka 87:981895e1d4f2 167 extern int gpsitow;
cocorlow 56:888379912f81 168 extern void run();
cocorlow 56:888379912f81 169
cocorlow 56:888379912f81 170 // imu.cpp
cocorlow 56:888379912f81 171 extern void getIMUval();
cocorlow 56:888379912f81 172
cocorlow 56:888379912f81 173 // servo.cpp
cocorlow 56:888379912f81 174 extern void calcServoOut();
cocorlow 56:888379912f81 175
NaotoMorita 73:be7a8b8188de 176 // datatransfer.cpp
NaotoMorita 73:be7a8b8188de 177 extern void send2center();
cocorlow 56:888379912f81 178 extern void writeEEPROM(int address, unsigned int eeaddress, char *data, int size);
cocorlow 56:888379912f81 179 extern void readEEPROM(int address, unsigned int eeaddress, char *data, int size);
cocorlow 56:888379912f81 180
cocorlow 56:888379912f81 181 // global.cpp
cocorlow 56:888379912f81 182 extern float mapfloat(float x, float in_min, float in_max, float out_min, float out_max);
osaka 84:028bd650e8bc 183 extern void setDiag(Matrix& mat, float val);
cocorlow 56:888379912f81 184
cocorlow 56:888379912f81 185 #endif