Eigen Revision
Dependencies: mbed LPS25HB_I2C LSM9DS1 PIDcontroller Autopilot_Eigen LoopTicker GPSUBX_UART_Eigen SBUS_without_mainfile MedianFilter Eigen UsaPack solaESKF_Eigen Vector3 CalibrateMagneto FastPWM
global.hpp@56:888379912f81, 2021-05-31 (annotated)
- Committer:
- cocorlow
- Date:
- Mon May 31 18:59:36 2021 +0000
- Revision:
- 56:888379912f81
- Child:
- 61:c05353850017
file divided
Who changed what in which revision?
User | Revision | Line number | New 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" |
cocorlow | 56:888379912f81 | 10 | #include "I2Cdev.h" |
cocorlow | 56:888379912f81 | 11 | #include "FastPWM.h" |
cocorlow | 56:888379912f81 | 12 | #include <cmath> |
cocorlow | 56:888379912f81 | 13 | #include "UsaPack.hpp" |
cocorlow | 56:888379912f81 | 14 | #include "Vector3.hpp" |
cocorlow | 56:888379912f81 | 15 | #include "HAPS_EKF.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 |
cocorlow | 56:888379912f81 | 27 | #define servoPwmMax 1800.0f |
cocorlow | 56:888379912f81 | 28 | #define servoPwmMin 1200.0f |
cocorlow | 56:888379912f81 | 29 | #define motorPwmMax 2000.0f |
cocorlow | 56:888379912f81 | 30 | #define motorPwmMin 1100.0f |
cocorlow | 56:888379912f81 | 31 | #define N_EEPROM 10 |
cocorlow | 56:888379912f81 | 32 | |
cocorlow | 56:888379912f81 | 33 | // struct union |
cocorlow | 56:888379912f81 | 34 | union U |
cocorlow | 56:888379912f81 | 35 | { |
cocorlow | 56:888379912f81 | 36 | int i[N_EEPROM]; // 0: flag(>1で正常に書き込まれた状態) 1 ~ 3: 磁場の中心座標, 4: 磁場の半径、 5~7; mag, 8~10: acc bias |
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 dt; |
cocorlow | 56:888379912f81 | 43 | int count; |
cocorlow | 56:888379912f81 | 44 | float acc[3]; |
cocorlow | 56:888379912f81 | 45 | float gyro[3]; |
cocorlow | 56:888379912f81 | 46 | float mag[3]; |
cocorlow | 56:888379912f81 | 47 | float rpy[3]; |
cocorlow | 56:888379912f81 | 48 | float rpy_g[3]; |
cocorlow | 56:888379912f81 | 49 | }; |
cocorlow | 56:888379912f81 | 50 | |
cocorlow | 56:888379912f81 | 51 | // var |
cocorlow | 56:888379912f81 | 52 | |
cocorlow | 56:888379912f81 | 53 | // communication |
cocorlow | 56:888379912f81 | 54 | extern Serial pc; |
cocorlow | 56:888379912f81 | 55 | extern I2C i2c; // sda, scl |
cocorlow | 56:888379912f81 | 56 | extern UsaPack tail; // log - tail |
cocorlow | 56:888379912f81 | 57 | extern SBUS sbus; |
cocorlow | 56:888379912f81 | 58 | |
cocorlow | 56:888379912f81 | 59 | // sensor |
cocorlow | 56:888379912f81 | 60 | extern MPU6050 accelgyro; |
cocorlow | 56:888379912f81 | 61 | extern MAG3110 mag_sensor; |
cocorlow | 56:888379912f81 | 62 | |
cocorlow | 56:888379912f81 | 63 | // io |
cocorlow | 56:888379912f81 | 64 | extern DigitalIn userButton; |
cocorlow | 56:888379912f81 | 65 | extern DigitalIn locdef1; |
cocorlow | 56:888379912f81 | 66 | extern DigitalIn locdef2; |
cocorlow | 56:888379912f81 | 67 | |
cocorlow | 56:888379912f81 | 68 | // control |
cocorlow | 56:888379912f81 | 69 | extern FastPWM servo; |
cocorlow | 56:888379912f81 | 70 | extern PID pitchPID; // rad |
cocorlow | 56:888379912f81 | 71 | extern PID pitchratePID;// rad/s |
cocorlow | 56:888379912f81 | 72 | extern HAPS_EKF ekf; // EKF class |
cocorlow | 56:888379912f81 | 73 | |
cocorlow | 56:888379912f81 | 74 | extern int loop_count; |
cocorlow | 56:888379912f81 | 75 | extern int obs_count; |
cocorlow | 56:888379912f81 | 76 | extern float att_dt; |
cocorlow | 56:888379912f81 | 77 | extern float rc[16]; |
cocorlow | 56:888379912f81 | 78 | |
cocorlow | 56:888379912f81 | 79 | extern int16_t ax, ay, az; |
cocorlow | 56:888379912f81 | 80 | extern int16_t gx, gy, gz; |
cocorlow | 56:888379912f81 | 81 | extern MotionSensorDataUnits mdata; |
cocorlow | 56:888379912f81 | 82 | extern float magval[3]; |
cocorlow | 56:888379912f81 | 83 | |
cocorlow | 56:888379912f81 | 84 | // position |
cocorlow | 56:888379912f81 | 85 | extern Vector3 rpy; // x:roll y:pitch z:yaw |
cocorlow | 56:888379912f81 | 86 | extern Vector3 rpy_g; // x:roll y:pitch z:yaw |
cocorlow | 56:888379912f81 | 87 | extern Vector3 acc; |
cocorlow | 56:888379912f81 | 88 | extern Vector3 accref; |
cocorlow | 56:888379912f81 | 89 | extern Vector3 mag; |
cocorlow | 56:888379912f81 | 90 | extern Vector3 magref; |
cocorlow | 56:888379912f81 | 91 | extern Vector3 dynacc; |
cocorlow | 56:888379912f81 | 92 | extern Vector3 gyro; |
cocorlow | 56:888379912f81 | 93 | |
cocorlow | 56:888379912f81 | 94 | extern Vector3 LPacc; |
cocorlow | 56:888379912f81 | 95 | extern Vector3 LPmag; |
cocorlow | 56:888379912f81 | 96 | |
cocorlow | 56:888379912f81 | 97 | extern int out1, out2; |
cocorlow | 56:888379912f81 | 98 | extern float scaledServoOut[1]; |
cocorlow | 56:888379912f81 | 99 | extern float servoOut[1]; |
cocorlow | 56:888379912f81 | 100 | |
cocorlow | 56:888379912f81 | 101 | |
cocorlow | 56:888379912f81 | 102 | extern float val_thmg; |
cocorlow | 56:888379912f81 | 103 | extern float th_mg; |
cocorlow | 56:888379912f81 | 104 | extern float accnormerr; |
cocorlow | 56:888379912f81 | 105 | |
cocorlow | 56:888379912f81 | 106 | extern int calibrationFlag; |
cocorlow | 56:888379912f81 | 107 | extern int pos_tail; // 0:left 1:center 2:right |
cocorlow | 56:888379912f81 | 108 | extern int agoffset[6]; |
cocorlow | 56:888379912f81 | 109 | extern float magbias[4]; |
cocorlow | 56:888379912f81 | 110 | |
cocorlow | 56:888379912f81 | 111 | extern Vector3 rpy_align; |
cocorlow | 56:888379912f81 | 112 | |
cocorlow | 56:888379912f81 | 113 | // eepromのread writeのためのunionを定義 |
cocorlow | 56:888379912f81 | 114 | extern const int eeprom_address; // EEPROMの3つの入力が全て+より |
cocorlow | 56:888379912f81 | 115 | extern const int eeprom_pointeraddress; |
cocorlow | 56:888379912f81 | 116 | |
cocorlow | 56:888379912f81 | 117 | //// UsaPack |
cocorlow | 56:888379912f81 | 118 | extern const int tail_address[3]; |
cocorlow | 56:888379912f81 | 119 | extern valuePack posValues[3]; |
cocorlow | 56:888379912f81 | 120 | |
cocorlow | 56:888379912f81 | 121 | // function |
cocorlow | 56:888379912f81 | 122 | |
cocorlow | 56:888379912f81 | 123 | // main.cpp |
cocorlow | 56:888379912f81 | 124 | |
cocorlow | 56:888379912f81 | 125 | // setup.cpp |
cocorlow | 56:888379912f81 | 126 | extern void setup(); |
cocorlow | 56:888379912f81 | 127 | extern void calibrate(); |
cocorlow | 56:888379912f81 | 128 | |
cocorlow | 56:888379912f81 | 129 | // run.cpp |
cocorlow | 56:888379912f81 | 130 | extern void run(); |
cocorlow | 56:888379912f81 | 131 | |
cocorlow | 56:888379912f81 | 132 | // imu.cpp |
cocorlow | 56:888379912f81 | 133 | extern void getIMUval(); |
cocorlow | 56:888379912f81 | 134 | |
cocorlow | 56:888379912f81 | 135 | // servo.cpp |
cocorlow | 56:888379912f81 | 136 | extern void calcServoOut(); |
cocorlow | 56:888379912f81 | 137 | |
cocorlow | 56:888379912f81 | 138 | // sd_eeprom.cpp |
cocorlow | 56:888379912f81 | 139 | extern void writeSdcard(); |
cocorlow | 56:888379912f81 | 140 | extern void writeEEPROM(int address, unsigned int eeaddress, char *data, int size); |
cocorlow | 56:888379912f81 | 141 | extern void readEEPROM(int address, unsigned int eeaddress, char *data, int size); |
cocorlow | 56:888379912f81 | 142 | |
cocorlow | 56:888379912f81 | 143 | // global.cpp |
cocorlow | 56:888379912f81 | 144 | extern float mapfloat(float x, float in_min, float in_max, float out_min, float out_max); |
cocorlow | 56:888379912f81 | 145 | |
cocorlow | 56:888379912f81 | 146 | #endif |