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:
Mon Feb 28 12:21:31 2022 +0000
Revision:
103:34e911b94440
Parent:
99:37cfd8633c9b
Child:
104:f81befbc5ab7
with optical-flow

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