Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed MatrixMath LPS25HB_I2C LSM9DS1 Matrix2 PIDcontroller LoopTicker SBUS_without_mainfile UsaPack solaESKF_wind Vector3 CalibrateMagneto FastPWM
global.cpp@70:9e7be21475f8, 2021-06-29 (annotated)
- Committer:
- NaotoMorita
- Date:
- Tue Jun 29 10:53:06 2021 +0000
- Revision:
- 70:9e7be21475f8
- Parent:
- 69:0caaad87cf1d
- Child:
- 71:62eb45ecffe9
revert
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 |
| NaotoMorita | 58:a7947322db87 | 6 | Serial pc(USBTX, USBRX); |
| cocorlow | 56:888379912f81 | 7 | I2C i2c(PB_9,PB_8); // sda, scl |
| cocorlow | 56:888379912f81 | 8 | UsaPack tail(PG_14, PG_9, 57600); // log - tail |
| cocorlow | 56:888379912f81 | 9 | SBUS sbus(PD_5, PD_6); |
| cocorlow | 56:888379912f81 | 10 | |
| cocorlow | 56:888379912f81 | 11 | // sensor |
| cocorlow | 56:888379912f81 | 12 | MPU6050 accelgyro; |
| cocorlow | 56:888379912f81 | 13 | MAG3110 mag_sensor(PB_9,PB_8); |
| NaotoMorita | 61:c05353850017 | 14 | CalibrateMagneto magCalibrator; |
| cocorlow | 56:888379912f81 | 15 | |
| cocorlow | 56:888379912f81 | 16 | // io |
| cocorlow | 56:888379912f81 | 17 | DigitalIn userButton(USER_BUTTON); |
| cocorlow | 56:888379912f81 | 18 | DigitalIn locdef1(PG_2); |
| cocorlow | 56:888379912f81 | 19 | DigitalIn locdef2(PG_3); |
| cocorlow | 56:888379912f81 | 20 | |
| cocorlow | 56:888379912f81 | 21 | // control |
| NaotoMorita | 62:ef10fd919f7b | 22 | FastPWM servo(PE_11); |
| cocorlow | 56:888379912f81 | 23 | PID pitchPID(5.0, 0,0, PID_dt); // rad |
| cocorlow | 56:888379912f81 | 24 | PID pitchratePID(0.5, 0.0, 0.0, PID_dt); // rad/s |
| NaotoMorita | 69:0caaad87cf1d | 25 | errStateEKF ekf; // EKF class |
| cocorlow | 56:888379912f81 | 26 | |
| cocorlow | 56:888379912f81 | 27 | int loop_count = 0; |
| cocorlow | 56:888379912f81 | 28 | int obs_count = 0; |
| cocorlow | 56:888379912f81 | 29 | float att_dt = 0.01f; |
| cocorlow | 56:888379912f81 | 30 | float rc[16]; |
| cocorlow | 56:888379912f81 | 31 | |
| cocorlow | 56:888379912f81 | 32 | int16_t ax, ay, az; |
| cocorlow | 56:888379912f81 | 33 | int16_t gx, gy, gz; |
| cocorlow | 56:888379912f81 | 34 | MotionSensorDataUnits mdata; |
| cocorlow | 56:888379912f81 | 35 | float magval[3] = {1.0f, 0.0f, 0.0f}; |
| cocorlow | 56:888379912f81 | 36 | |
| cocorlow | 63:851e96f54a86 | 37 | // elevator |
| cocorlow | 63:851e96f54a86 | 38 | float de; |
| cocorlow | 63:851e96f54a86 | 39 | float deobj; |
| cocorlow | 63:851e96f54a86 | 40 | |
| cocorlow | 56:888379912f81 | 41 | // position |
| cocorlow | 56:888379912f81 | 42 | Vector3 rpy(0.0f, 0.0f, 0.0f); // x:roll y:pitch z:yaw |
| cocorlow | 56:888379912f81 | 43 | Vector3 rpy_g(0.0f, 0.0f, 0.0f); // x:roll y:pitch z:yaw |
| cocorlow | 56:888379912f81 | 44 | Vector3 acc; |
| cocorlow | 56:888379912f81 | 45 | Vector3 accref(0.0f, 0.0f, -0.98f); |
| cocorlow | 56:888379912f81 | 46 | Vector3 mag; |
| cocorlow | 56:888379912f81 | 47 | Vector3 magref(0.65f, 0.0f, 0.75f); |
| cocorlow | 56:888379912f81 | 48 | Vector3 dynacc; |
| cocorlow | 56:888379912f81 | 49 | Vector3 gyro; |
| NaotoMorita | 70:9e7be21475f8 | 50 | MedianFilter accMedian(3); |
| NaotoMorita | 70:9e7be21475f8 | 51 | MedianFilter gyroMedian(3); |
| NaotoMorita | 70:9e7be21475f8 | 52 | MedianFilter magMedian(3); |
| cocorlow | 56:888379912f81 | 53 | |
| cocorlow | 56:888379912f81 | 54 | int out1, out2; |
| cocorlow | 56:888379912f81 | 55 | float scaledServoOut[1] = {0.0f}; |
| cocorlow | 56:888379912f81 | 56 | float servoOut[1] = {1500.0f}; |
| cocorlow | 56:888379912f81 | 57 | |
| cocorlow | 56:888379912f81 | 58 | float val_thmg = 0.0f; |
| NaotoMorita | 61:c05353850017 | 59 | float sigma_thmg = 0.0f; |
| cocorlow | 56:888379912f81 | 60 | float th_mg = 0.0f; |
| cocorlow | 56:888379912f81 | 61 | float accnormerr = 0.0f; |
| NaotoMorita | 61:c05353850017 | 62 | float sigma_accnorm = 0.0f; |
| cocorlow | 56:888379912f81 | 63 | |
| cocorlow | 56:888379912f81 | 64 | int calibrationFlag = 0; |
| cocorlow | 56:888379912f81 | 65 | int pos_tail = 0; // 0:left 1:center 2:right |
| cocorlow | 56:888379912f81 | 66 | int agoffset[6] = {0, 0, 0, 386, -450, 48}; |
| NaotoMorita | 61:c05353850017 | 67 | float magbiasMin[3] = {0.0f, 0.0f, 0.0f}; |
| NaotoMorita | 61:c05353850017 | 68 | float magbiasMax[3] = {0.0f, 0.0f, 0.0f}; |
| NaotoMorita | 70:9e7be21475f8 | 69 | float accMin[3] = {-0.974521, -1.010208, -1.055415}; |
| NaotoMorita | 70:9e7be21475f8 | 70 | float accMax[3] = { 1.036735, 0.973873, 0.969753}; |
| cocorlow | 56:888379912f81 | 71 | |
| cocorlow | 56:888379912f81 | 72 | Vector3 rpy_align(0.0f*M_PI/180.0f, 0.0f*M_PI/180.0f, 0.0f); |
| cocorlow | 56:888379912f81 | 73 | |
| cocorlow | 56:888379912f81 | 74 | // eepromのread writeのためのunionを定義 |
| cocorlow | 56:888379912f81 | 75 | const int eeprom_address = 0xAE; // EEPROMの3つの入力が全て+より |
| cocorlow | 56:888379912f81 | 76 | const int eeprom_pointeraddress = 0; |
| cocorlow | 56:888379912f81 | 77 | |
| cocorlow | 56:888379912f81 | 78 | // UsaPack |
| cocorlow | 56:888379912f81 | 79 | const int tail_address[3] = {1111, 2222, 3333}; |
| cocorlow | 63:851e96f54a86 | 80 | const int time_address = 4444; |
| cocorlow | 56:888379912f81 | 81 | valuePack posValues[3]; |
| cocorlow | 63:851e96f54a86 | 82 | Timer system_dt; |
| cocorlow | 63:851e96f54a86 | 83 | timePack broadcast_time; |
| cocorlow | 63:851e96f54a86 | 84 | timePack system_time; |
| cocorlow | 56:888379912f81 | 85 | |
| cocorlow | 56:888379912f81 | 86 | float mapfloat(float x, float in_min, float in_max, float out_min, float out_max) |
| cocorlow | 56:888379912f81 | 87 | { |
| cocorlow | 56:888379912f81 | 88 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; |
| cocorlow | 56:888379912f81 | 89 | } |