Crazyflie 2.0 controller

Dependents:   Drones-Controlador

Committer:
yvesyuzo
Date:
Mon Nov 05 11:12:11 2018 +0000
Revision:
7:fb6174d2ea78
Parent:
6:09cc3b307252
5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yvesyuzo 0:3871dc7bedf7 1 #include "mbed.h"
yvesyuzo 0:3871dc7bedf7 2 #include "AttitudeController.h"
yvesyuzo 0:3871dc7bedf7 3 #include "Library.h"
yvesyuzo 0:3871dc7bedf7 4
yvesyuzo 0:3871dc7bedf7 5 // Class constructor
yvesyuzo 0:3871dc7bedf7 6 AttitudeController :: AttitudeController ()
yvesyuzo 0:3871dc7bedf7 7 {
yvesyuzo 0:3871dc7bedf7 8 }
yvesyuzo 0:3871dc7bedf7 9 // Control torques given reference angles and current angles and angular velocities
yvesyuzo 0:3871dc7bedf7 10 void AttitudeController::control ( float phi_r, float theta_r, float psi_r, float phi, float theta, float psi)
yvesyuzo 0:3871dc7bedf7 11 {
yvesyuzo 2:54fabc943f25 12 tau_phi = single_axis_control ( phi_r , phi , Kp_phi , Td_phi , I_xx, last_erro_phi);
yvesyuzo 7:fb6174d2ea78 13
yvesyuzo 2:54fabc943f25 14 last_erro_phi = last_erro;
yvesyuzo 7:fb6174d2ea78 15
yvesyuzo 2:54fabc943f25 16 tau_theta = single_axis_control ( psi_r , psi , Kp_psi , Td_psi , I_zz, last_erro_psi);
yvesyuzo 7:fb6174d2ea78 17
yvesyuzo 2:54fabc943f25 18 last_erro_theta = last_erro;
yvesyuzo 7:fb6174d2ea78 19
yvesyuzo 2:54fabc943f25 20 tau_psi = single_axis_control ( theta_r , theta , Kp_theta , Td_theta , I_yy, last_erro_theta);
yvesyuzo 7:fb6174d2ea78 21
yvesyuzo 2:54fabc943f25 22 last_erro_psi = last_erro;
yvesyuzo 0:3871dc7bedf7 23 }
yvesyuzo 0:3871dc7bedf7 24 // Control torque of a single axis given reference angles and current angles and angular velocities ( with given gains and /or time constants and moments of inertia )
yvesyuzo 0:3871dc7bedf7 25 float AttitudeController :: single_axis_control ( float angle_r , float angle , float K_angle , float K_rate , float I, float last_erro_angle)
yvesyuzo 0:3871dc7bedf7 26 {
yvesyuzo 2:54fabc943f25 27 float erro = angle_r - angle;
yvesyuzo 2:54fabc943f25 28 float erro_p = (erro - last_erro_angle)/dt2;
yvesyuzo 2:54fabc943f25 29 last_erro = erro;
yvesyuzo 0:3871dc7bedf7 30 float angle_2p = K_angle*(erro+1/K_rate*erro_p);
yvesyuzo 0:3871dc7bedf7 31 return I*angle_2p;
yvesyuzo 0:3871dc7bedf7 32 }