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

Committer:
NaotoMorita
Date:
Wed Sep 29 04:50:51 2021 +0000
Revision:
84:ff48e01ea76b
Parent:
83:e69ab831031c
Child:
86:456f00d52974
newer;

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"
NaotoMorita 70:99f974d8960e 5 #include "SBUS.hpp"
cocorlow 56:888379912f81 6 #include "PIDcontroller.h"
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 76:7fd3ac1afe3e 16 #include "ScErrStateEKF.hpp"
NaotoMorita 70:99f974d8960e 17 #include "MedianFilter.hpp"
NaotoMorita 73:84ffa0166e6c 18 #include "Joystick.h"
cocorlow 56:888379912f81 19
cocorlow 56:888379912f81 20 #define MPU6050_PWR_MGMT_1 0x6B
cocorlow 56:888379912f81 21 #define MPU_ADDRESS 0x68
cocorlow 56:888379912f81 22 #define M_PI 3.141592f
cocorlow 56:888379912f81 23 #define ACCEL_FSR MPU6050_ACCEL_FS_8
cocorlow 56:888379912f81 24 #define ACCEL_SSF 4096.0f
NaotoMorita 70:99f974d8960e 25 #define GYRO_FSR MPU6050_GYRO_FS_250
NaotoMorita 70:99f974d8960e 26 #define GYRO_SSF 131.0f
NaotoMorita 73:84ffa0166e6c 27 #define MPU6050_LPF MPU6050_DLPF_BW_42
NaotoMorita 73:84ffa0166e6c 28 #define MPU6050_SAMPLERATE 0
cocorlow 56:888379912f81 29 #define PID_dt 0.015f
cocorlow 56:888379912f81 30 #define servoPwmMax 1800.0f
cocorlow 56:888379912f81 31 #define servoPwmMin 1200.0f
cocorlow 56:888379912f81 32 #define motorPwmMax 2000.0f
cocorlow 56:888379912f81 33 #define motorPwmMin 1100.0f
cocorlow 56:888379912f81 34
cocorlow 56:888379912f81 35 struct valuePack
cocorlow 56:888379912f81 36 {
NaotoMorita 73:84ffa0166e6c 37 int16_t accData[3];
NaotoMorita 73:84ffa0166e6c 38 int16_t gyroData[3];
NaotoMorita 84:ff48e01ea76b 39 int16_t magData[3];
NaotoMorita 84:ff48e01ea76b 40 int16_t viData[3];
NaotoMorita 84:ff48e01ea76b 41 int16_t actData[4];
NaotoMorita 76:7fd3ac1afe3e 42 int16_t commandIndex;
NaotoMorita 83:e69ab831031c 43 int16_t commandVal;
NaotoMorita 83:e69ab831031c 44 };
NaotoMorita 83:e69ab831031c 45
NaotoMorita 83:e69ab831031c 46 struct sendPack
NaotoMorita 83:e69ab831031c 47 {
NaotoMorita 83:e69ab831031c 48 float da;
NaotoMorita 83:e69ab831031c 49 float de;
NaotoMorita 83:e69ab831031c 50 float dT;
NaotoMorita 83:e69ab831031c 51 float rpy[3];
NaotoMorita 84:ff48e01ea76b 52 float vi[3];
NaotoMorita 84:ff48e01ea76b 53 float vihat[3];
cocorlow 56:888379912f81 54 };
cocorlow 56:888379912f81 55
cocorlow 56:888379912f81 56 // var
cocorlow 56:888379912f81 57
cocorlow 56:888379912f81 58 // communication
cocorlow 56:888379912f81 59 extern I2C i2c; // sda, scl
NaotoMorita 64:e9661430f0e3 60 extern UsaPack pc; // log - tail
NaotoMorita 76:7fd3ac1afe3e 61 extern Serial sd;
cocorlow 56:888379912f81 62
cocorlow 56:888379912f81 63 // sensor
cocorlow 56:888379912f81 64 extern MPU6050 accelgyro;
cocorlow 56:888379912f81 65 extern MAG3110 mag_sensor;
NaotoMorita 61:c05353850017 66 extern CalibrateMagneto magCalibrator;
cocorlow 56:888379912f81 67
cocorlow 56:888379912f81 68 // io
cocorlow 56:888379912f81 69 extern DigitalIn userButton;
NaotoMorita 70:99f974d8960e 70 extern SBUS sbus;
NaotoMorita 73:84ffa0166e6c 71 extern Joystick joystick;
cocorlow 56:888379912f81 72
cocorlow 56:888379912f81 73 // control
NaotoMorita 70:99f974d8960e 74 extern FastPWM servoRight;
NaotoMorita 70:99f974d8960e 75 extern FastPWM servoLeft;
NaotoMorita 70:99f974d8960e 76 extern FastPWM servoThrust;
NaotoMorita 70:99f974d8960e 77 extern PID pitchPID; //rad
NaotoMorita 70:99f974d8960e 78 extern PID pitchratePID;//rad/s
NaotoMorita 70:99f974d8960e 79 extern PID rollPID;
NaotoMorita 70:99f974d8960e 80 extern PID rollratePID;//rad/s
NaotoMorita 76:7fd3ac1afe3e 81 extern ScErrStateEKF ekf; // EKF class
NaotoMorita 76:7fd3ac1afe3e 82 extern int obsCount;
cocorlow 56:888379912f81 83
NaotoMorita 70:99f974d8960e 84 extern float rc[16];
cocorlow 56:888379912f81 85 extern int loop_count;
cocorlow 56:888379912f81 86 extern float att_dt;
cocorlow 56:888379912f81 87
cocorlow 56:888379912f81 88 extern int16_t ax, ay, az;
cocorlow 56:888379912f81 89 extern int16_t gx, gy, gz;
cocorlow 56:888379912f81 90 extern MotionSensorDataUnits mdata;
cocorlow 56:888379912f81 91 extern float magval[3];
cocorlow 56:888379912f81 92
NaotoMorita 70:99f974d8960e 93
cocorlow 56:888379912f81 94 // position
cocorlow 56:888379912f81 95 extern Vector3 rpy; // x:roll y:pitch z:yaw
cocorlow 56:888379912f81 96 extern Vector3 acc;
cocorlow 56:888379912f81 97 extern Vector3 accref;
NaotoMorita 68:b9f6938fab9d 98 extern Vector3 dynacc;
cocorlow 56:888379912f81 99 extern Vector3 mag;
cocorlow 56:888379912f81 100 extern Vector3 magref;
cocorlow 56:888379912f81 101 extern Vector3 gyro;
NaotoMorita 77:2bf856e3eca4 102 extern Vector3 vb;
NaotoMorita 82:c183c29d2427 103 extern Vector3 vi;
NaotoMorita 73:84ffa0166e6c 104 extern float de;
NaotoMorita 73:84ffa0166e6c 105 extern float da;
NaotoMorita 73:84ffa0166e6c 106 extern float dT;
NaotoMorita 70:99f974d8960e 107 extern MedianFilter accMedian;
NaotoMorita 70:99f974d8960e 108 extern MedianFilter gyroMedian;
NaotoMorita 70:99f974d8960e 109 extern MedianFilter magMedian;
cocorlow 56:888379912f81 110
NaotoMorita 64:e9661430f0e3 111 extern float scaledServoOut[2];
NaotoMorita 70:99f974d8960e 112 extern float scaledMotorOut[1];
NaotoMorita 64:e9661430f0e3 113 extern float servoOut[2];
NaotoMorita 70:99f974d8960e 114 extern float motorOut[1];
cocorlow 56:888379912f81 115
NaotoMorita 61:c05353850017 116
cocorlow 56:888379912f81 117 extern int calibrationFlag;
cocorlow 56:888379912f81 118 extern int agoffset[6];
NaotoMorita 61:c05353850017 119 extern float magbiasMin[3];
NaotoMorita 61:c05353850017 120 extern float magbiasMax[3];
NaotoMorita 76:7fd3ac1afe3e 121 extern float magbias[4];
NaotoMorita 70:99f974d8960e 122 extern float accMin[3];
NaotoMorita 70:99f974d8960e 123 extern float accMax[3];
cocorlow 56:888379912f81 124
cocorlow 56:888379912f81 125 extern Vector3 rpy_align;
cocorlow 56:888379912f81 126
cocorlow 56:888379912f81 127
cocorlow 56:888379912f81 128 //// UsaPack
NaotoMorita 73:84ffa0166e6c 129 extern valuePack vp;
NaotoMorita 83:e69ab831031c 130 extern sendPack sp;
NaotoMorita 73:84ffa0166e6c 131
NaotoMorita 73:84ffa0166e6c 132 // HIL
NaotoMorita 73:84ffa0166e6c 133 extern bool hilFlag;
NaotoMorita 76:7fd3ac1afe3e 134 extern bool serialControlSource;
NaotoMorita 76:7fd3ac1afe3e 135 extern bool serialParamSource;
NaotoMorita 76:7fd3ac1afe3e 136 extern int checkParamSerial[5];
cocorlow 56:888379912f81 137 // function
cocorlow 56:888379912f81 138
cocorlow 56:888379912f81 139 // main.cpp
cocorlow 56:888379912f81 140
cocorlow 56:888379912f81 141 // setup.cpp
cocorlow 56:888379912f81 142 extern void setup();
cocorlow 56:888379912f81 143 extern void calibrate();
NaotoMorita 70:99f974d8960e 144 extern float accScaleCalibrate(int attNo);
cocorlow 56:888379912f81 145
cocorlow 56:888379912f81 146 // run.cpp
cocorlow 56:888379912f81 147 extern void run();
cocorlow 56:888379912f81 148
cocorlow 56:888379912f81 149 // imu.cpp
cocorlow 56:888379912f81 150 extern void getIMUval();
cocorlow 56:888379912f81 151
NaotoMorita 73:84ffa0166e6c 152 // hil.cpp
NaotoMorita 73:84ffa0166e6c 153 extern void getHILval();
NaotoMorita 73:84ffa0166e6c 154 extern float randn();
NaotoMorita 73:84ffa0166e6c 155
cocorlow 56:888379912f81 156 // servo.cpp
cocorlow 56:888379912f81 157 extern void calcServoOut();
cocorlow 56:888379912f81 158
cocorlow 56:888379912f81 159 // sd_eeprom.cpp
cocorlow 56:888379912f81 160 extern void writeSdcard();
cocorlow 56:888379912f81 161
cocorlow 56:888379912f81 162 // global.cpp
cocorlow 56:888379912f81 163 extern float mapfloat(float x, float in_min, float in_max, float out_min, float out_max);
cocorlow 56:888379912f81 164
NaotoMorita 67:41fcdfb7cc5a 165
cocorlow 56:888379912f81 166 #endif