HAPSRG / Mbed 2 deprecated HAPStail

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

Committer:
NaotoMorita
Date:
Wed Feb 02 07:59:58 2022 +0000
Revision:
95:98dbbcc6b39d
Parent:
91:393b9ae62681
Child:
97:2a65f22488e4
without kf in preflight check

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