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 09:38:31 2022 +0000
Revision:
98:39e4d1844a24
Parent:
97:2a65f22488e4
Child:
99:37cfd8633c9b
new

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;
osaka 98:39e4d1844a24 64 float gps_acc;
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 90:0b1f62f7a83a 119 extern bool gpsUpdateFlag;
osaka 84:028bd650e8bc 120 extern bool headingUpdateFlag;
osaka 84:028bd650e8bc 121 extern float dynaccnorm2;
cocorlow 56:888379912f81 122
cocorlow 56:888379912f81 123
cocorlow 56:888379912f81 124 extern float scaledServoOut[1];
cocorlow 56:888379912f81 125 extern float servoOut[1];
cocorlow 56:888379912f81 126
cocorlow 56:888379912f81 127
cocorlow 56:888379912f81 128 extern float val_thmg;
NaotoMorita 61:c05353850017 129 extern float sigma_thmg;
cocorlow 56:888379912f81 130 extern float th_mg;
cocorlow 56:888379912f81 131 extern float accnormerr;
NaotoMorita 61:c05353850017 132 extern float sigma_accnorm;
NaotoMorita 61:c05353850017 133
cocorlow 56:888379912f81 134 extern int calibrationFlag;
cocorlow 56:888379912f81 135 extern int pos_tail; // 0:left 1:center 2:right
NaotoMorita 90:0b1f62f7a83a 136 extern float agoffset[6];
NaotoMorita 61:c05353850017 137 extern float magbiasMin[3];
NaotoMorita 61:c05353850017 138 extern float magbiasMax[3];
NaotoMorita 70:9e7be21475f8 139 extern float accMin[3];
NaotoMorita 70:9e7be21475f8 140 extern float accMax[3];
cocorlow 56:888379912f81 141
osaka 88:0fc5df2fddcb 142 extern float roll_offset;
osaka 88:0fc5df2fddcb 143 extern float pitch_offset;
cocorlow 56:888379912f81 144
cocorlow 56:888379912f81 145 // eepromのread writeのためのunionを定義
cocorlow 56:888379912f81 146 extern const int eeprom_address; // EEPROMの3つの入力が全て+より
cocorlow 56:888379912f81 147 extern const int eeprom_pointeraddress;
cocorlow 56:888379912f81 148
cocorlow 56:888379912f81 149 //// UsaPack
cocorlow 56:888379912f81 150 extern const int tail_address[3];
cocorlow 63:851e96f54a86 151 extern const int time_address;
NaotoMorita 73:be7a8b8188de 152 extern valuePack posValues;
NaotoMorita 73:be7a8b8188de 153 extern updatePack updateValues;
cocorlow 63:851e96f54a86 154 extern Timer system_dt;
cocorlow 56:888379912f81 155
cocorlow 56:888379912f81 156 // function
cocorlow 56:888379912f81 157
cocorlow 56:888379912f81 158 // main.cpp
cocorlow 56:888379912f81 159
cocorlow 56:888379912f81 160 // setup.cpp
cocorlow 56:888379912f81 161 extern void setup();
cocorlow 56:888379912f81 162 extern void calibrate();
NaotoMorita 70:9e7be21475f8 163 extern float accScaleCalibrate(int attNo);
osaka 88:0fc5df2fddcb 164 extern void alignment();
osaka 88:0fc5df2fddcb 165 extern int n_ave;
osaka 88:0fc5df2fddcb 166 extern float roll_sum;
osaka 88:0fc5df2fddcb 167 extern float pitch_sum;
cocorlow 56:888379912f81 168
cocorlow 56:888379912f81 169 // run.cpp
osaka 87:981895e1d4f2 170 extern int gpsitow;
osaka 91:393b9ae62681 171 extern bool prefligt_finished;
cocorlow 56:888379912f81 172 extern void run();
cocorlow 56:888379912f81 173
cocorlow 56:888379912f81 174 // imu.cpp
cocorlow 56:888379912f81 175 extern void getIMUval();
cocorlow 56:888379912f81 176
cocorlow 56:888379912f81 177 // servo.cpp
cocorlow 56:888379912f81 178 extern void calcServoOut();
cocorlow 56:888379912f81 179
NaotoMorita 73:be7a8b8188de 180 // datatransfer.cpp
NaotoMorita 73:be7a8b8188de 181 extern void send2center();
cocorlow 56:888379912f81 182 extern void writeEEPROM(int address, unsigned int eeaddress, char *data, int size);
cocorlow 56:888379912f81 183 extern void readEEPROM(int address, unsigned int eeaddress, char *data, int size);
cocorlow 56:888379912f81 184
cocorlow 56:888379912f81 185 // global.cpp
cocorlow 56:888379912f81 186 extern float mapfloat(float x, float in_min, float in_max, float out_min, float out_max);
osaka 84:028bd650e8bc 187 extern void setDiag(Matrix& mat, float val);
cocorlow 56:888379912f81 188
cocorlow 56:888379912f81 189 #endif