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 Sep 29 06:32:46 2021 +0000
Revision:
79:aa2631950f46
Parent:
73:be7a8b8188de
Child:
83:0a644de28415
SC

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"
cocorlow 56:888379912f81 8 #include "MPU6050.h"
cocorlow 56:888379912f81 9 #include "MAG3110.h"
NaotoMorita 61:c05353850017 10 #include "CalibrateMagneto.h"
cocorlow 56:888379912f81 11 #include "I2Cdev.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"
NaotoMorita 71:62eb45ecffe9 16 #include "ScErrStateEKF.hpp"
NaotoMorita 70:9e7be21475f8 17 #include "MedianFilter.hpp"
cocorlow 56:888379912f81 18
cocorlow 56:888379912f81 19 #define MPU6050_PWR_MGMT_1 0x6B
cocorlow 56:888379912f81 20 #define MPU_ADDRESS 0x68
cocorlow 56:888379912f81 21 #define M_PI 3.141592f
cocorlow 56:888379912f81 22 #define ACCEL_FSR MPU6050_ACCEL_FS_8
cocorlow 56:888379912f81 23 #define ACCEL_SSF 4096.0f
cocorlow 56:888379912f81 24 #define GYRO_FSR MPU6050_GYRO_FS_250
cocorlow 56:888379912f81 25 #define GYRO_SSF 131.0f
cocorlow 56:888379912f81 26 #define MPU6050_LPF MPU6050_DLPF_BW_256
cocorlow 56:888379912f81 27 #define gyro_th 20.0f
cocorlow 56:888379912f81 28 #define PID_dt 0.015f
cocorlow 56:888379912f81 29 #define servoPwmMax 1800.0f
cocorlow 56:888379912f81 30 #define servoPwmMin 1200.0f
cocorlow 56:888379912f81 31 #define motorPwmMax 2000.0f
cocorlow 56:888379912f81 32 #define motorPwmMin 1100.0f
NaotoMorita 71:62eb45ecffe9 33 #define N_EEPROM 12
cocorlow 56:888379912f81 34
cocorlow 56:888379912f81 35 // struct union
cocorlow 56:888379912f81 36 union U
cocorlow 56:888379912f81 37 {
cocorlow 56:888379912f81 38 int i[N_EEPROM]; // 0: flag(>1で正常に書き込まれた状態) 1 ~ 3: 磁場の中心座標, 4: 磁場の半径、 5~7; mag, 8~10: acc bias
cocorlow 56:888379912f81 39 char c[N_EEPROM*4]; // floatはcharの4倍
cocorlow 56:888379912f81 40 };
cocorlow 56:888379912f81 41
cocorlow 56:888379912f81 42 struct valuePack
cocorlow 56:888379912f81 43 {
cocorlow 63:851e96f54a86 44 int day;
cocorlow 63:851e96f54a86 45 int ms;
NaotoMorita 73:be7a8b8188de 46 float gyroBias[3];
NaotoMorita 73:be7a8b8188de 47 float gyroBiasCov[6];
cocorlow 56:888379912f81 48 float acc[3];
cocorlow 56:888379912f81 49 float gyro[3];
cocorlow 56:888379912f81 50 float mag[3];
cocorlow 56:888379912f81 51 float rpy[3];
cocorlow 63:851e96f54a86 52 float de;
cocorlow 63:851e96f54a86 53 float deobj;
NaotoMorita 73:be7a8b8188de 54 float rc[5];
cocorlow 63:851e96f54a86 55 };
cocorlow 63:851e96f54a86 56
NaotoMorita 73:be7a8b8188de 57 struct updatePack
cocorlow 63:851e96f54a86 58 {
cocorlow 63:851e96f54a86 59 int day;
cocorlow 63:851e96f54a86 60 int ms;
NaotoMorita 79:aa2631950f46 61 int gps_itowPOS;
NaotoMorita 79:aa2631950f46 62 int gps_itowVEL;
NaotoMorita 73:be7a8b8188de 63 float gyroBias[3];
NaotoMorita 79:aa2631950f46 64 float posgps[3];
NaotoMorita 79:aa2631950f46 65 float vgps[3];
NaotoMorita 73:be7a8b8188de 66 float de_command;
cocorlow 56:888379912f81 67 };
cocorlow 56:888379912f81 68
cocorlow 56:888379912f81 69 // var
cocorlow 56:888379912f81 70
cocorlow 56:888379912f81 71 // communication
cocorlow 56:888379912f81 72 extern Serial pc;
cocorlow 56:888379912f81 73 extern I2C i2c; // sda, scl
cocorlow 56:888379912f81 74 extern UsaPack tail; // log - tail
cocorlow 56:888379912f81 75 extern SBUS sbus;
cocorlow 56:888379912f81 76
cocorlow 56:888379912f81 77 // sensor
cocorlow 56:888379912f81 78 extern MPU6050 accelgyro;
cocorlow 56:888379912f81 79 extern MAG3110 mag_sensor;
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 71:62eb45ecffe9 91 extern ScErrStateEKF ekf; // EKF class
NaotoMorita 79:aa2631950f46 92 extern int itowVEL_log;
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 MotionSensorDataUnits mdata;
cocorlow 56:888379912f81 101 extern float magval[3];
cocorlow 56:888379912f81 102
cocorlow 63:851e96f54a86 103 // elevator
cocorlow 63:851e96f54a86 104 extern float de;
cocorlow 63:851e96f54a86 105 extern float deobj;
cocorlow 63:851e96f54a86 106
cocorlow 56:888379912f81 107 // position
cocorlow 56:888379912f81 108 extern Vector3 rpy; // x:roll y:pitch z:yaw
cocorlow 56:888379912f81 109 extern Vector3 acc;
cocorlow 56:888379912f81 110 extern Vector3 accref;
cocorlow 56:888379912f81 111 extern Vector3 mag;
cocorlow 56:888379912f81 112 extern Vector3 magref;
cocorlow 56:888379912f81 113 extern Vector3 gyro;
NaotoMorita 71:62eb45ecffe9 114 extern Vector3 vb;
NaotoMorita 70:9e7be21475f8 115 extern MedianFilter accMedian;
NaotoMorita 70:9e7be21475f8 116 extern MedianFilter gyroMedian;
NaotoMorita 70:9e7be21475f8 117 extern MedianFilter magMedian;
cocorlow 56:888379912f81 118
cocorlow 56:888379912f81 119
cocorlow 56:888379912f81 120 extern float scaledServoOut[1];
cocorlow 56:888379912f81 121 extern float servoOut[1];
cocorlow 56:888379912f81 122
cocorlow 56:888379912f81 123
cocorlow 56:888379912f81 124 extern float val_thmg;
NaotoMorita 61:c05353850017 125 extern float sigma_thmg;
cocorlow 56:888379912f81 126 extern float th_mg;
cocorlow 56:888379912f81 127 extern float accnormerr;
NaotoMorita 61:c05353850017 128 extern float sigma_accnorm;
NaotoMorita 61:c05353850017 129
cocorlow 56:888379912f81 130 extern int calibrationFlag;
cocorlow 56:888379912f81 131 extern int pos_tail; // 0:left 1:center 2:right
cocorlow 56:888379912f81 132 extern int agoffset[6];
NaotoMorita 61:c05353850017 133 extern float magbiasMin[3];
NaotoMorita 61:c05353850017 134 extern float magbiasMax[3];
NaotoMorita 70:9e7be21475f8 135 extern float accMin[3];
NaotoMorita 70:9e7be21475f8 136 extern float accMax[3];
cocorlow 56:888379912f81 137
cocorlow 56:888379912f81 138 extern Vector3 rpy_align;
cocorlow 56:888379912f81 139
cocorlow 56:888379912f81 140 // eepromのread writeのためのunionを定義
cocorlow 56:888379912f81 141 extern const int eeprom_address; // EEPROMの3つの入力が全て+より
cocorlow 56:888379912f81 142 extern const int eeprom_pointeraddress;
cocorlow 56:888379912f81 143
cocorlow 56:888379912f81 144 //// UsaPack
cocorlow 56:888379912f81 145 extern const int tail_address[3];
cocorlow 63:851e96f54a86 146 extern const int time_address;
NaotoMorita 73:be7a8b8188de 147 extern valuePack posValues;
NaotoMorita 73:be7a8b8188de 148 extern updatePack updateValues;
cocorlow 63:851e96f54a86 149 extern Timer system_dt;
cocorlow 56:888379912f81 150
cocorlow 56:888379912f81 151 // function
cocorlow 56:888379912f81 152
cocorlow 56:888379912f81 153 // main.cpp
cocorlow 56:888379912f81 154
cocorlow 56:888379912f81 155 // setup.cpp
cocorlow 56:888379912f81 156 extern void setup();
cocorlow 56:888379912f81 157 extern void calibrate();
NaotoMorita 70:9e7be21475f8 158 extern float accScaleCalibrate(int attNo);
cocorlow 56:888379912f81 159
cocorlow 56:888379912f81 160 // run.cpp
cocorlow 56:888379912f81 161 extern void run();
cocorlow 56:888379912f81 162
cocorlow 56:888379912f81 163 // imu.cpp
cocorlow 56:888379912f81 164 extern void getIMUval();
cocorlow 56:888379912f81 165
cocorlow 56:888379912f81 166 // servo.cpp
cocorlow 56:888379912f81 167 extern void calcServoOut();
cocorlow 56:888379912f81 168
NaotoMorita 73:be7a8b8188de 169 // datatransfer.cpp
NaotoMorita 73:be7a8b8188de 170 extern void send2center();
cocorlow 56:888379912f81 171 extern void writeEEPROM(int address, unsigned int eeaddress, char *data, int size);
cocorlow 56:888379912f81 172 extern void readEEPROM(int address, unsigned int eeaddress, char *data, int size);
cocorlow 56:888379912f81 173
cocorlow 56:888379912f81 174 // global.cpp
cocorlow 56:888379912f81 175 extern float mapfloat(float x, float in_min, float in_max, float out_min, float out_max);
cocorlow 56:888379912f81 176
cocorlow 56:888379912f81 177 #endif