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@73:be7a8b8188de, 2021-08-25 (annotated)
- Committer:
- NaotoMorita
- Date:
- Wed Aug 25 07:01:12 2021 +0000
- Revision:
- 73:be7a8b8188de
- Parent:
- 71:62eb45ecffe9
- Child:
- 77:b06a5f8554f4
- Child:
- 79:aa2631950f46
centered correction
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 |
| NaotoMorita | 73:be7a8b8188de | 8 | UsaPack tail(PG_14, PG_9, 115200); // 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 | 71:62eb45ecffe9 | 25 | ScErrStateEKF ekf; // EKF class |
| NaotoMorita | 71:62eb45ecffe9 | 26 | int obsCount = 0; |
| cocorlow | 56:888379912f81 | 27 | |
| cocorlow | 56:888379912f81 | 28 | int loop_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 acc; |
| NaotoMorita | 71:62eb45ecffe9 | 44 | Vector3 accref(0.0f, 0.0f, 0.98f); |
| cocorlow | 56:888379912f81 | 45 | Vector3 mag; |
| cocorlow | 56:888379912f81 | 46 | Vector3 magref(0.65f, 0.0f, 0.75f); |
| cocorlow | 56:888379912f81 | 47 | Vector3 gyro; |
| NaotoMorita | 71:62eb45ecffe9 | 48 | Vector3 vb; |
| NaotoMorita | 70:9e7be21475f8 | 49 | MedianFilter accMedian(3); |
| NaotoMorita | 70:9e7be21475f8 | 50 | MedianFilter gyroMedian(3); |
| NaotoMorita | 70:9e7be21475f8 | 51 | MedianFilter magMedian(3); |
| cocorlow | 56:888379912f81 | 52 | |
| cocorlow | 56:888379912f81 | 53 | int out1, out2; |
| cocorlow | 56:888379912f81 | 54 | float scaledServoOut[1] = {0.0f}; |
| cocorlow | 56:888379912f81 | 55 | float servoOut[1] = {1500.0f}; |
| cocorlow | 56:888379912f81 | 56 | |
| cocorlow | 56:888379912f81 | 57 | float val_thmg = 0.0f; |
| NaotoMorita | 61:c05353850017 | 58 | float sigma_thmg = 0.0f; |
| cocorlow | 56:888379912f81 | 59 | float th_mg = 0.0f; |
| cocorlow | 56:888379912f81 | 60 | float accnormerr = 0.0f; |
| NaotoMorita | 61:c05353850017 | 61 | float sigma_accnorm = 0.0f; |
| cocorlow | 56:888379912f81 | 62 | |
| cocorlow | 56:888379912f81 | 63 | int calibrationFlag = 0; |
| cocorlow | 56:888379912f81 | 64 | int pos_tail = 0; // 0:left 1:center 2:right |
| NaotoMorita | 71:62eb45ecffe9 | 65 | int agoffset[6] = {0, 0, 0, 0, 0, 0}; |
| NaotoMorita | 61:c05353850017 | 66 | float magbiasMin[3] = {0.0f, 0.0f, 0.0f}; |
| NaotoMorita | 61:c05353850017 | 67 | float magbiasMax[3] = {0.0f, 0.0f, 0.0f}; |
| NaotoMorita | 71:62eb45ecffe9 | 68 | float accMin[3] = {-1.0f, -1.0f, -1.0f}; |
| NaotoMorita | 71:62eb45ecffe9 | 69 | float accMax[3] = { 1.0f, 1.0f, 1.0f}; |
| cocorlow | 56:888379912f81 | 70 | |
| cocorlow | 56:888379912f81 | 71 | Vector3 rpy_align(0.0f*M_PI/180.0f, 0.0f*M_PI/180.0f, 0.0f); |
| cocorlow | 56:888379912f81 | 72 | |
| cocorlow | 56:888379912f81 | 73 | // eepromのread writeのためのunionを定義 |
| cocorlow | 56:888379912f81 | 74 | const int eeprom_address = 0xAE; // EEPROMの3つの入力が全て+より |
| cocorlow | 56:888379912f81 | 75 | const int eeprom_pointeraddress = 0; |
| cocorlow | 56:888379912f81 | 76 | |
| cocorlow | 56:888379912f81 | 77 | // UsaPack |
| cocorlow | 56:888379912f81 | 78 | const int tail_address[3] = {1111, 2222, 3333}; |
| cocorlow | 63:851e96f54a86 | 79 | const int time_address = 4444; |
| NaotoMorita | 73:be7a8b8188de | 80 | valuePack posValues; |
| NaotoMorita | 73:be7a8b8188de | 81 | updatePack updateValues; |
| cocorlow | 63:851e96f54a86 | 82 | Timer system_dt; |
| cocorlow | 56:888379912f81 | 83 | |
| cocorlow | 56:888379912f81 | 84 | float mapfloat(float x, float in_min, float in_max, float out_min, float out_max) |
| cocorlow | 56:888379912f81 | 85 | { |
| cocorlow | 56:888379912f81 | 86 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; |
| cocorlow | 56:888379912f81 | 87 | } |