solaESKF_EIGEN
Dependencies: mbed LPS25HB_I2C LSM9DS1 PIDcontroller LoopTicker GPSUBX_UART_Eigen SBUS_without_mainfile MedianFilter Eigen UsaPack solaESKF_Eigen Vector3 CalibrateMagneto FastPWM
global.cpp@63:9c4973a98600, 2021-06-22 (annotated)
- Committer:
- NaotoMorita
- Date:
- Tue Jun 22 02:02:08 2021 +0000
- Revision:
- 63:9c4973a98600
- Parent:
- 62:ef10fd919f7b
- Child:
- 67:41fcdfb7cc5a
global.cpp
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cocorlow | 56:888379912f81 | 1 | #include "global.hpp" |
cocorlow | 56:888379912f81 | 2 | |
cocorlow | 56:888379912f81 | 3 | // var |
cocorlow | 56:888379912f81 | 4 | |
cocorlow | 56:888379912f81 | 5 | // communication |
cocorlow | 56:888379912f81 | 6 | I2C i2c(PB_9,PB_8); // sda, scl |
NaotoMorita | 63:9c4973a98600 | 7 | UsaPack tail(USBTX, USBRX, 57600); // log - tail |
cocorlow | 56:888379912f81 | 8 | |
cocorlow | 56:888379912f81 | 9 | // sensor |
cocorlow | 56:888379912f81 | 10 | MPU6050 accelgyro; |
cocorlow | 56:888379912f81 | 11 | MAG3110 mag_sensor(PB_9,PB_8); |
NaotoMorita | 61:c05353850017 | 12 | CalibrateMagneto magCalibrator; |
cocorlow | 56:888379912f81 | 13 | |
cocorlow | 56:888379912f81 | 14 | // io |
cocorlow | 56:888379912f81 | 15 | DigitalIn userButton(USER_BUTTON); |
NaotoMorita | 63:9c4973a98600 | 16 | CalibrateMagneto joyCalibrator; |
cocorlow | 56:888379912f81 | 17 | // control |
NaotoMorita | 63:9c4973a98600 | 18 | FastPWM elevServo(PE_11); |
NaotoMorita | 63:9c4973a98600 | 19 | FastPWM rudServo(PE_13); |
cocorlow | 56:888379912f81 | 20 | PID pitchPID(5.0, 0,0, PID_dt); // rad |
cocorlow | 56:888379912f81 | 21 | PID pitchratePID(0.5, 0.0, 0.0, PID_dt); // rad/s |
cocorlow | 56:888379912f81 | 22 | HAPS_EKF ekf; // EKF class |
cocorlow | 56:888379912f81 | 23 | |
cocorlow | 56:888379912f81 | 24 | int loop_count = 0; |
cocorlow | 56:888379912f81 | 25 | float att_dt = 0.01f; |
cocorlow | 56:888379912f81 | 26 | |
cocorlow | 56:888379912f81 | 27 | int16_t ax, ay, az; |
cocorlow | 56:888379912f81 | 28 | int16_t gx, gy, gz; |
cocorlow | 56:888379912f81 | 29 | MotionSensorDataUnits mdata; |
cocorlow | 56:888379912f81 | 30 | float magval[3] = {1.0f, 0.0f, 0.0f}; |
cocorlow | 56:888379912f81 | 31 | |
cocorlow | 56:888379912f81 | 32 | // position |
cocorlow | 56:888379912f81 | 33 | Vector3 rpy(0.0f, 0.0f, 0.0f); // x:roll y:pitch z:yaw |
cocorlow | 56:888379912f81 | 34 | Vector3 acc; |
cocorlow | 56:888379912f81 | 35 | Vector3 accref(0.0f, 0.0f, -0.98f); |
cocorlow | 56:888379912f81 | 36 | Vector3 mag; |
cocorlow | 56:888379912f81 | 37 | Vector3 magref(0.65f, 0.0f, 0.75f); |
cocorlow | 56:888379912f81 | 38 | Vector3 gyro; |
cocorlow | 56:888379912f81 | 39 | |
NaotoMorita | 63:9c4973a98600 | 40 | float scaledServoOut[2] = {0.0f,0.0f}; |
NaotoMorita | 63:9c4973a98600 | 41 | float servoOut[2] = {1500.0f,1500.0f}; |
cocorlow | 56:888379912f81 | 42 | |
cocorlow | 56:888379912f81 | 43 | int calibrationFlag = 0; |
cocorlow | 56:888379912f81 | 44 | int agoffset[6] = {0, 0, 0, 386, -450, 48}; |
NaotoMorita | 61:c05353850017 | 45 | float magbiasMin[3] = {0.0f, 0.0f, 0.0f}; |
NaotoMorita | 61:c05353850017 | 46 | float magbiasMax[3] = {0.0f, 0.0f, 0.0f}; |
cocorlow | 56:888379912f81 | 47 | |
NaotoMorita | 63:9c4973a98600 | 48 | Vector3 rpy_align(0.0f*M_PI/180.0f, 0.0f*M_PI/180.0f, 0.0f*M_PI/180.0f); |
cocorlow | 56:888379912f81 | 49 | |
cocorlow | 56:888379912f81 | 50 | |
cocorlow | 56:888379912f81 | 51 | // UsaPack |
NaotoMorita | 63:9c4973a98600 | 52 | valuePack posValues; |
cocorlow | 56:888379912f81 | 53 | |
cocorlow | 56:888379912f81 | 54 | float mapfloat(float x, float in_min, float in_max, float out_min, float out_max) |
cocorlow | 56:888379912f81 | 55 | { |
cocorlow | 56:888379912f81 | 56 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; |
cocorlow | 56:888379912f81 | 57 | } |