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
- Committer:
- osaka
- Date:
- 2022-01-13
- Revision:
- 91:393b9ae62681
- Parent:
- 90:0b1f62f7a83a
- Child:
- 95:98dbbcc6b39d
File content as of revision 91:393b9ae62681:
#include "global.hpp"
// var
// communication
Serial pc(USBTX, USBRX);
I2C i2c(PB_9,PB_8); // sda, scl
UsaPack tail(PG_14, PG_9, 115200); // log - tail
SBUS sbus(PD_5, PD_6);
// sensor
LSM9DS1 lsm(i2c);
LPS lps(i2c);
//UsaPack sensor1(PC_10, PC_11, 115200);
//UsaPack sensor2(PC_12, PD_2, 115200);
CalibrateMagneto magCalibrator;
// io
DigitalIn userButton(USER_BUTTON);
DigitalIn locdef1(PG_2);
DigitalIn locdef2(PG_3);
// control
FastPWM servo(PE_9);
PID pitchPID(5.0, 0,0, PID_dt); // rad
PID pitchratePID(0.5, 0.0, 0.0, PID_dt); // rad/s
solaESKF eskf;
int itowVEL_log = 0;
int loop_count = 0;
float att_dt = 0.01f;
float rc[16];
int16_t ax, ay, az;
int16_t gx, gy, gz;
float magval[3] = {1.0f, 0.0f, 0.0f};
// elevator
float de;
float deobj;
// position
Matrix SensorAlignmentAG(3,3);
Matrix SensorAlignmentMAG(3,3);
Vector3 rpy(0.0f, 0.0f, 0.0f); // x:roll y:pitch z:yaw
Vector3 acc;
Vector3 accref(0.0f, 0.0f, 0.98f);
Vector3 mag;
Vector3 magref(0.65f, 0.0f, 0.75f);
Vector3 gyro;
Vector3 vb;
Matrix euler(3,1);
MedianFilter accMedian(3);
MedianFilter gyroMedian(3);
MedianFilter magMedian(3);
float palt;
float palt0;
bool gpsUpdateFlag = false;
bool headingUpdateFlag = false;
bool prefligt_finished = false;
float dynaccnorm2;
int out1, out2;
float scaledServoOut[1] = {0.0f};
float servoOut[1] = {1500.0f};
float val_thmg = 0.0f;
float sigma_thmg = 0.0f;
float th_mg = 0.0f;
float accnormerr = 0.0f;
float sigma_accnorm = 0.0f;
int calibrationFlag = 0;
int pos_tail = 0; // 0:left 1:center 2:right
float agoffset[6] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
float magbiasMin[3] = {0.0f, 0.0f, 0.0f};
float magbiasMax[3] = {0.0f, 0.0f, 0.0f};
float accMin[3] = {-1.0f, -1.0f, -1.0f};
float accMax[3] = { 1.0f, 1.0f, 1.0f};
int gpsitow = 0;
float roll_offset = 0.0f;
float pitch_offset = 0.0f;
// eepromのread writeのためのunionを定義
const int eeprom_address = 0xA0; // EEPROMの3つの入力が全て+より
const int eeprom_pointeraddress = 0;
// UsaPack
const int tail_address[3] = {1111, 2222, 3333};
const int time_address = 4444;
valuePack posValues;
updatePack updateValues;
Timer system_dt;
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
void setDiag(Matrix& mat, float val){
for (int i = 1; i < mat.getCols()+1; i++){
mat(i,i) = val;
}
}
//alignment
int n_ave = 0;
float roll_sum = 0.0f;
float pitch_sum = 0.0f;