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:
Wed Feb 02 08:37:33 2022 +0000
Revision:
97:2a65f22488e4
Parent:
95:98dbbcc6b39d
Parent:
96:0be0d80d5299
Child:
98:39e4d1844a24
merged

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;
osaka 96:0be0d80d5299 52 float pi[3];
osaka 96:0be0d80d5299 53 float vi[3];
cocorlow 63:851e96f54a86 54 };
cocorlow 63:851e96f54a86 55
NaotoMorita 73:be7a8b8188de 56 struct updatePack
cocorlow 63:851e96f54a86 57 {
osaka 88:0fc5df2fddcb 58 int calibrationFlag;
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 de_command;
cocorlow 56:888379912f81 64 };
cocorlow 56:888379912f81 65
cocorlow 56:888379912f81 66 // var
cocorlow 56:888379912f81 67
cocorlow 56:888379912f81 68 // communication
cocorlow 56:888379912f81 69 extern Serial pc;
cocorlow 56:888379912f81 70 extern I2C i2c; // sda, scl
cocorlow 56:888379912f81 71 extern UsaPack tail; // log - tail
cocorlow 56:888379912f81 72 extern SBUS sbus;
cocorlow 56:888379912f81 73
cocorlow 56:888379912f81 74 // sensor
osaka 83:0a644de28415 75 extern LSM9DS1 lsm;
osaka 83:0a644de28415 76 extern LPS lps;
osaka 83:0a644de28415 77 //extern UsaPack sensor1;
osaka 83:0a644de28415 78 //extern UsaPack sensor2;
NaotoMorita 61:c05353850017 79 extern CalibrateMagneto magCalibrator;
cocorlow 56:888379912f81 80
cocorlow 56:888379912f81 81 // io
cocorlow 56:888379912f81 82 extern DigitalIn userButton;
cocorlow 56:888379912f81 83 extern DigitalIn locdef1;
cocorlow 56:888379912f81 84 extern DigitalIn locdef2;
cocorlow 56:888379912f81 85
cocorlow 56:888379912f81 86 // control
cocorlow 56:888379912f81 87 extern FastPWM servo;
cocorlow 56:888379912f81 88 extern PID pitchPID; // rad
cocorlow 56:888379912f81 89 extern PID pitchratePID;// rad/s
NaotoMorita 79:aa2631950f46 90 extern int itowVEL_log;
osaka 84:028bd650e8bc 91 extern solaESKF eskf;
cocorlow 56:888379912f81 92
cocorlow 56:888379912f81 93 extern int loop_count;
cocorlow 56:888379912f81 94 extern float att_dt;
cocorlow 56:888379912f81 95 extern float rc[16];
cocorlow 56:888379912f81 96
cocorlow 56:888379912f81 97 extern int16_t ax, ay, az;
cocorlow 56:888379912f81 98 extern int16_t gx, gy, gz;
cocorlow 56:888379912f81 99 extern float magval[3];
cocorlow 56:888379912f81 100
cocorlow 63:851e96f54a86 101 // elevator
cocorlow 63:851e96f54a86 102 extern float de;
cocorlow 63:851e96f54a86 103 extern float deobj;
cocorlow 63:851e96f54a86 104
cocorlow 56:888379912f81 105 // position
osaka 83:0a644de28415 106 extern Matrix SensorAlignmentAG;
osaka 83:0a644de28415 107 extern Matrix SensorAlignmentMAG;
osaka 85:0b14a2a600fc 108 extern Matrix euler;
cocorlow 56:888379912f81 109 extern Vector3 rpy; // x:roll y:pitch z:yaw
cocorlow 56:888379912f81 110 extern Vector3 acc;
cocorlow 56:888379912f81 111 extern Vector3 accref;
cocorlow 56:888379912f81 112 extern Vector3 mag;
cocorlow 56:888379912f81 113 extern Vector3 magref;
cocorlow 56:888379912f81 114 extern Vector3 gyro;
NaotoMorita 71:62eb45ecffe9 115 extern Vector3 vb;
osaka 83:0a644de28415 116 extern float palt;
osaka 83:0a644de28415 117 extern float palt0;
NaotoMorita 90:0b1f62f7a83a 118 extern bool gpsUpdateFlag;
osaka 84:028bd650e8bc 119 extern bool headingUpdateFlag;
osaka 84:028bd650e8bc 120 extern float dynaccnorm2;
cocorlow 56:888379912f81 121
cocorlow 56:888379912f81 122
cocorlow 56:888379912f81 123 extern float scaledServoOut[1];
cocorlow 56:888379912f81 124 extern float servoOut[1];
cocorlow 56:888379912f81 125
cocorlow 56:888379912f81 126
cocorlow 56:888379912f81 127 extern float val_thmg;
NaotoMorita 61:c05353850017 128 extern float sigma_thmg;
cocorlow 56:888379912f81 129 extern float th_mg;
cocorlow 56:888379912f81 130 extern float accnormerr;
NaotoMorita 61:c05353850017 131 extern float sigma_accnorm;
NaotoMorita 61:c05353850017 132
cocorlow 56:888379912f81 133 extern int calibrationFlag;
cocorlow 56:888379912f81 134 extern int pos_tail; // 0:left 1:center 2:right
NaotoMorita 90:0b1f62f7a83a 135 extern float agoffset[6];
NaotoMorita 61:c05353850017 136 extern float magbiasMin[3];
NaotoMorita 61:c05353850017 137 extern float magbiasMax[3];
NaotoMorita 70:9e7be21475f8 138 extern float accMin[3];
NaotoMorita 70:9e7be21475f8 139 extern float accMax[3];
cocorlow 56:888379912f81 140
osaka 88:0fc5df2fddcb 141 extern float roll_offset;
osaka 88:0fc5df2fddcb 142 extern float pitch_offset;
cocorlow 56:888379912f81 143
cocorlow 56:888379912f81 144 // eepromのread writeのためのunionを定義
cocorlow 56:888379912f81 145 extern const int eeprom_address; // EEPROMの3つの入力が全て+より
cocorlow 56:888379912f81 146 extern const int eeprom_pointeraddress;
cocorlow 56:888379912f81 147
cocorlow 56:888379912f81 148 //// UsaPack
cocorlow 56:888379912f81 149 extern const int tail_address[3];
cocorlow 63:851e96f54a86 150 extern const int time_address;
NaotoMorita 73:be7a8b8188de 151 extern valuePack posValues;
NaotoMorita 73:be7a8b8188de 152 extern updatePack updateValues;
cocorlow 63:851e96f54a86 153 extern Timer system_dt;
cocorlow 56:888379912f81 154
cocorlow 56:888379912f81 155 // function
cocorlow 56:888379912f81 156
cocorlow 56:888379912f81 157 // main.cpp
cocorlow 56:888379912f81 158
cocorlow 56:888379912f81 159 // setup.cpp
cocorlow 56:888379912f81 160 extern void setup();
cocorlow 56:888379912f81 161 extern void calibrate();
NaotoMorita 70:9e7be21475f8 162 extern float accScaleCalibrate(int attNo);
osaka 88:0fc5df2fddcb 163 extern void alignment();
osaka 88:0fc5df2fddcb 164 extern int n_ave;
osaka 88:0fc5df2fddcb 165 extern float roll_sum;
osaka 88:0fc5df2fddcb 166 extern float pitch_sum;
cocorlow 56:888379912f81 167
cocorlow 56:888379912f81 168 // run.cpp
osaka 87:981895e1d4f2 169 extern int gpsitow;
osaka 91:393b9ae62681 170 extern bool prefligt_finished;
cocorlow 56:888379912f81 171 extern void run();
cocorlow 56:888379912f81 172
cocorlow 56:888379912f81 173 // imu.cpp
cocorlow 56:888379912f81 174 extern void getIMUval();
cocorlow 56:888379912f81 175
cocorlow 56:888379912f81 176 // servo.cpp
cocorlow 56:888379912f81 177 extern void calcServoOut();
cocorlow 56:888379912f81 178
NaotoMorita 73:be7a8b8188de 179 // datatransfer.cpp
NaotoMorita 73:be7a8b8188de 180 extern void send2center();
cocorlow 56:888379912f81 181 extern void writeEEPROM(int address, unsigned int eeaddress, char *data, int size);
cocorlow 56:888379912f81 182 extern void readEEPROM(int address, unsigned int eeaddress, char *data, int size);
cocorlow 56:888379912f81 183
cocorlow 56:888379912f81 184 // global.cpp
cocorlow 56:888379912f81 185 extern float mapfloat(float x, float in_min, float in_max, float out_min, float out_max);
osaka 84:028bd650e8bc 186 extern void setDiag(Matrix& mat, float val);
cocorlow 56:888379912f81 187
cocorlow 56:888379912f81 188 #endif