HAPSRG / Mbed 2 deprecated HAPStail

Dependencies:   mbed MatrixMath LPS25HB_I2C LSM9DS1 Matrix2 PIDcontroller LoopTicker SBUS_without_mainfile UsaPack solaESKF_wind Vector3 CalibrateMagneto FastPWM

global.cpp

Committer:
NaotoMorita
Date:
2021-06-29
Revision:
70:9e7be21475f8
Parent:
69:0caaad87cf1d
Child:
71:62eb45ecffe9

File content as of revision 70:9e7be21475f8:

#include "global.hpp"

// var

// communication
Serial pc(USBTX, USBRX);
I2C i2c(PB_9,PB_8);  // sda, scl
UsaPack tail(PG_14, PG_9, 57600); // log - tail
SBUS sbus(PD_5, PD_6);

// sensor
MPU6050 accelgyro;
MAG3110 mag_sensor(PB_9,PB_8);
CalibrateMagneto magCalibrator;

// io
DigitalIn userButton(USER_BUTTON);
DigitalIn locdef1(PG_2);
DigitalIn locdef2(PG_3);

// control
FastPWM servo(PE_11);
PID pitchPID(5.0, 0,0, PID_dt); // rad
PID pitchratePID(0.5, 0.0, 0.0, PID_dt); // rad/s
errStateEKF ekf; // EKF class

int loop_count = 0;
int obs_count = 0;
float att_dt = 0.01f;
float rc[16];

int16_t ax, ay, az;
int16_t gx, gy, gz;
MotionSensorDataUnits mdata;
float magval[3] = {1.0f, 0.0f, 0.0f};

// elevator
float de;
float deobj;

// position
Vector3 rpy(0.0f, 0.0f, 0.0f); // x:roll  y:pitch  z:yaw
Vector3 rpy_g(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 dynacc;
Vector3 gyro;
MedianFilter accMedian(3);
MedianFilter gyroMedian(3);
MedianFilter magMedian(3);

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, 386, -450, 48};
float magbiasMin[3] = {0.0f, 0.0f, 0.0f};
float magbiasMax[3] = {0.0f, 0.0f, 0.0f};
float accMin[3] = {-0.974521, -1.010208, -1.055415};
float accMax[3] = { 1.036735, 0.973873, 0.969753};

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[3];
Timer system_dt;
timePack broadcast_time;
timePack system_time;

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;
}