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:
- 2021-12-06
- Revision:
- 83:0a644de28415
- Parent:
- 79:aa2631950f46
- Child:
- 84:028bd650e8bc
File content as of revision 83:0a644de28415:
#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
ScErrStateEKF ekf; // EKF class
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;
MedianFilter accMedian(3);
MedianFilter gyroMedian(3);
MedianFilter magMedian(3);
float palt;
float palt0;
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
int agoffset[6] = {0, 0, 0, 0, 0, 0};
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};
Vector3 rpy_align(0.0f*M_PI/180.0f, 0.0f*M_PI/180.0f, 0.0f);
// eepromのread writeのためのunionを定義
const int eeprom_address = 0xAE; // 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;
}