Library containing Crazyflie 2.0 controller classes: - Attitude estimator - Horizontal estimator - Vertical estimator - Attitude controller - Horizontal controller - Vertical controller - Mixer

Committer:
fbob
Date:
Thu Dec 06 16:44:40 2018 +0000
Revision:
24:7b9e3beb61d5
Parent:
23:4905fbc2b31a
Adjust

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fbob 5:b9947e3d20cf 1 #ifndef Parameters_h
fbob 5:b9947e3d20cf 2 #define Parameters_h
fbob 5:b9947e3d20cf 3
fbob 24:7b9e3beb61d5 4 // PWM frequencies
fbob 24:7b9e3beb61d5 5 const float f_pwm = 500.0f;
fbob 24:7b9e3beb61d5 6 const float period_pwm = 1.0f/f_pwm;
fbob 24:7b9e3beb61d5 7
fbob 24:7b9e3beb61d5 8 const float motor_test_on_time = 0.05f;
fbob 24:7b9e3beb61d5 9 const float motor_test_off_time = 0.15f;
fbob 24:7b9e3beb61d5 10
fbob 13:1a871ebd35bb 11 // Interrupt frequencies
fbob 15:155ca63b7884 12 const float f = 500.0f; // Hz
fbob 13:1a871ebd35bb 13 const float f_range = 20.0f; // Hz
fbob 21:169cc2b1d2ff 14 const float f_flow = 500.0f; // Hz
fbob 13:1a871ebd35bb 15 const float dt = 1.0f/f; // s
fbob 13:1a871ebd35bb 16 const float dt_range = 1.0f/f_range;// s
fbob 13:1a871ebd35bb 17 const float dt_flow = 1.0f/f_flow; // s
fbob 9:15058b4fa090 18
fbob 21:169cc2b1d2ff 19 // Quadcopter dimensions
fbob 21:169cc2b1d2ff 20 const float m = 30e-3f; // kg
fbob 21:169cc2b1d2ff 21 const float I_xx = 16.0e-6f; // kg.m^2
fbob 21:169cc2b1d2ff 22 const float I_yy = 16.0e-6f; // kg.m^2
fbob 21:169cc2b1d2ff 23 const float I_zz = 29.0e-6f; // kg.m^2
fbob 21:169cc2b1d2ff 24 const float l = 33e-3f; // m
fbob 21:169cc2b1d2ff 25
fbob 21:169cc2b1d2ff 26 // Physical constants
fbob 21:169cc2b1d2ff 27 const float pi = 3.1416f;
fbob 21:169cc2b1d2ff 28 const float g = 9.81f; // m/s^2
fbob 21:169cc2b1d2ff 29
fbob 5:b9947e3d20cf 30 // Motor constants
fbob 5:b9947e3d20cf 31 const float alpha = 1.16e-07f;
fbob 5:b9947e3d20cf 32 const float beta = 7.149e-10f;
fbob 5:b9947e3d20cf 33
fbob 5:b9947e3d20cf 34 // Propeller constants
fbob 9:15058b4fa090 35 const float kl = 1.726e-08f; // N.s^2/rad^2
fbob 9:15058b4fa090 36 const float kd = 1.426e-10f; // N.m.s^2/rad^2
fbob 5:b9947e3d20cf 37
fbob 9:15058b4fa090 38 // Attitude estimator weighthing (accelerometer X gyroscope)
fbob 15:155ca63b7884 39 const float rho_att = 0.01f;
fbob 5:b9947e3d20cf 40
fbob 19:83b357d6806e 41 // Attitude controller gains (roll/pitch)
fbob 23:4905fbc2b31a 42 const float Ts_phi = 0.3f; // s
fbob 21:169cc2b1d2ff 43 const float OS_phi = 0.005f; // %
fbob 19:83b357d6806e 44 const float zeta_phi = abs(log(OS_phi))/sqrt(pow(log(OS_phi),2)+pow(pi,2));
fbob 19:83b357d6806e 45 const float omega_n_phi = 4.0f/(Ts_phi*zeta_phi);
fbob 21:169cc2b1d2ff 46 const float kp_phi = pow(omega_n_phi,2.0f);
fbob 21:169cc2b1d2ff 47 const float kd_phi = 2.0f*zeta_phi*omega_n_phi;
fbob 21:169cc2b1d2ff 48 const float kp_theta = kp_phi;
fbob 21:169cc2b1d2ff 49 const float kd_theta = kd_phi;
fbob 19:83b357d6806e 50
fbob 19:83b357d6806e 51 // Attitude controller gains (yaw)
fbob 23:4905fbc2b31a 52 const float Ts_psi = 0.6f; // s
fbob 22:5f2323e30cdc 53 const float OS_psi = 0.005f; // %
fbob 19:83b357d6806e 54 const float zeta_psi = abs(log(OS_psi))/sqrt(pow(log(OS_psi),2)+pow(pi,2));
fbob 19:83b357d6806e 55 const float omega_n_psi = 4.0f/(Ts_psi*zeta_psi);
fbob 21:169cc2b1d2ff 56 const float kd_psi = pow(omega_n_psi,2.0f);
fbob 21:169cc2b1d2ff 57 const float kp_psi = 2.0f*zeta_psi*omega_n_psi;
fbob 5:b9947e3d20cf 58
fbob 9:15058b4fa090 59 // Vertical estimator weighthing (measurement X prediction)
fbob 9:15058b4fa090 60 const float rho_ver = 0.3f;
fbob 7:220ce3839be8 61
fbob 21:169cc2b1d2ff 62 // Vertical controller gains (z)
fbob 22:5f2323e30cdc 63 const float Ts_z = 2.0f; // s
fbob 22:5f2323e30cdc 64 const float OS_z = 0.005f; // %
fbob 19:83b357d6806e 65 const float zeta_z = abs(log(OS_z))/sqrt(pow(log(OS_z),2)+pow(pi,2));
fbob 19:83b357d6806e 66 const float omega_n_z = 4.0f/(Ts_z*zeta_z);
fbob 21:169cc2b1d2ff 67 const float kp_z = pow(omega_n_z,2.0f);
fbob 21:169cc2b1d2ff 68 const float kd_z = 2.0f*zeta_z*omega_n_z;
fbob 9:15058b4fa090 69
fbob 22:5f2323e30cdc 70 // Optical flow sensor constant
fbob 22:5f2323e30cdc 71 const float gamma = 42.0f;
fbob 22:5f2323e30cdc 72 const float resolution = 420.0f;
fbob 22:5f2323e30cdc 73 const float sigma = (1.0f/dt_flow)*(2.0f*tan((gamma*pi/180.0f)/2.0f))/resolution;
fbob 22:5f2323e30cdc 74
fbob 9:15058b4fa090 75 // Horizontal estimator weighthing (measurement X prediction)
fbob 23:4905fbc2b31a 76 const float rho_hor = 0.4f;
fbob 8:d05fe9f8bfb6 77
fbob 21:169cc2b1d2ff 78 // Horizontal controller gains (x/y)
fbob 22:5f2323e30cdc 79 const float Ts_x = 4.0f; // s
fbob 22:5f2323e30cdc 80 const float OS_x = 0.005f; // %
fbob 21:169cc2b1d2ff 81 const float zeta_x = abs(log(OS_x))/sqrt(pow(log(OS_x),2)+pow(pi,2));
fbob 19:83b357d6806e 82 const float omega_n_x = 4.0f/(Ts_x*zeta_x);
fbob 21:169cc2b1d2ff 83 const float kp_x = pow(omega_n_x,2.0f);
fbob 21:169cc2b1d2ff 84 const float kd_x = 2.0f*zeta_x*omega_n_x;
fbob 21:169cc2b1d2ff 85 const float kp_y = kp_x;
fbob 21:169cc2b1d2ff 86 const float kd_y = kd_x;
fbob 7:220ce3839be8 87
fbob 6:3188b00263e8 88 #endif