Skip to content

Commit a2f86c0

Browse files
Merge pull request #1 from andrealaffly/main2
Main2
2 parents 69cfacc + 4041b48 commit a2f86c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2143
-312
lines changed

GainsController.py

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,25 @@ def PID():
3030
KD_rot = np.matrix(1 * np.diag([50,50,50]))
3131
KI_rot = np.matrix(1 * np.diag([20,20,10]))
3232

33-
return [number_of_states,size_DATA,KP_tran,KD_tran,KI_tran,KP_rot,KD_rot,KI_rot]
33+
# ----------------------------------------------------------------
34+
# Safety Mechanism Parameters
35+
# ----------------------------------------------------------------
36+
37+
# Mu - sphere intersection
38+
sphereEpsilon = 1e-2
39+
maximumThrust = 85 # [N] 85
40+
41+
# Mu - elliptic cone intersection
42+
EllipticConeEpsilon = 1e-2
43+
maximumRollAngle = math.radians(32) # [rad] 25
44+
maximumPitchAngle = math.radians(32) # [rad] 25
45+
46+
# Mu - plane intersection
47+
planeEpsilon = 1e-2
48+
alphaPlane = 0.95 # [-] coefficient for setting the 'height' of the bottom plane. Must be >0 and <1.
49+
50+
return [number_of_states,size_DATA,KP_tran,KD_tran,KI_tran,KP_rot,KD_rot,KI_rot,sphereEpsilon,maximumThrust,
51+
EllipticConeEpsilon,maximumRollAngle,maximumPitchAngle,planeEpsilon,alphaPlane]
3452
# ================================================================================================================================================================
3553
# end of PID
3654
# ================================================================================================================================================================
@@ -1336,10 +1354,11 @@ def FunnelTwoLayerMRACwithBASELINE(mass_total_estimated,air_density_estimated,su
13361354
def MRACwithBASELINE_SafetyMechanism(mass_total_estimated,air_density_estimated,surface_area_estimated,drag_coefficient_matrix_estimated):
13371355

13381356
# Number of states to be integrated by RK4
1339-
number_of_states = 100
1357+
# number_of_states = 100
1358+
number_of_states = 106
13401359
# Length of the array vector that will be exported
1341-
size_DATA = 74
1342-
# size_DATA = 94 # OLD data format
1360+
# size_DATA = 74
1361+
size_DATA = 86
13431362

13441363
# ----------------------------------------------------------------
13451364
# Baseline Parameters
@@ -1355,14 +1374,23 @@ def MRACwithBASELINE_SafetyMechanism(mass_total_estimated,air_density_estimated,
13551374
KD_tran_PD_baseline = np.matrix(1 * np.diag([8,8,3]))
13561375

13571376
# **Rotational** baseline parameters
1358-
KP_rot = np.matrix(1e2 * np.diag([1,1,0.5]))
1377+
# KP_rot = np.matrix(1e2 * np.diag([1,1,0.5]))
1378+
# KP_rot = np.matrix(5e1 * np.diag([0.1,0.1,0.5]))
1379+
KP_rot = np.matrix(5e1 * np.diag([0.05,0.05,0.5]))
1380+
# KI_rot = np.matrix(1e2 * np.diag([1,1,1]))
1381+
KI_rot = np.matrix(1e2 * np.diag([1,1,1]))
13591382

13601383
# **Rotational** parameters for the PI baseline controller (Moment_baseline_PI)
1361-
KP_rot_PI_baseline = np.matrix(40 * np.diag([1,1,1]))
1384+
# KP_rot_PI_baseline = np.matrix(40 * np.diag([1,1,1]))
1385+
# KD_rot_PI_baseline = np.matrix(0 * np.diag([1,1,0.5]))
1386+
# KI_rot_PI_baseline = np.matrix(1e-1 * np.diag([1,1,0.5]))
1387+
KP_rot_PI_baseline = np.matrix(200 * np.diag([1,1,0.3]))
13621388
KD_rot_PI_baseline = np.matrix(0 * np.diag([1,1,0.5]))
1363-
KI_rot_PI_baseline = np.matrix(0.1 * np.diag([1,1,0.5]))
1389+
KI_rot_PI_baseline = np.matrix(1e2 * np.diag([10,10,0.5]))
13641390

1365-
K_P_omega_ref = np.matrix(1.5e-1 * np.diag([5,5,10]))
1391+
# K_P_omega_ref = np.matrix(1.5e-1 * np.diag([5,5,10]))
1392+
K_P_omega_ref = np.matrix(1.5e0 * np.diag([50,50,10]))
1393+
K_I_omega_ref = np.matrix(1e2 * np.diag([1,1,1]))
13661394

13671395
# ----------------------------------------------------------------
13681396
# Translational Parameters MRAC
@@ -1413,13 +1441,17 @@ def MRACwithBASELINE_SafetyMechanism(mass_total_estimated,air_density_estimated,
14131441
B_ref_rot = np.matrix(np.eye(3))
14141442

14151443
# **Rotational** parameters Lyapunov equation
1416-
Q_rot = np.matrix(7e-3 * np.diag([1,1,2]))
1444+
# Q_rot = np.matrix(7e-3 * np.diag([1,1,2]))
1445+
Q_rot = np.matrix(7e-3 * np.diag([2,2,2]))
14171446
P_rot = np.matrix(linalg.solve_continuous_lyapunov(A_ref_rot.T, -Q_rot))
14181447

14191448
# **Rotational** adaptive parameters
1420-
Gamma_x_rot = np.matrix(1e1 * np.diag([1,1,10])) # Adaptive rates
1421-
Gamma_r_rot = np.matrix(1e-4 * np.diag([1,1,1])) # Adaptive rates
1422-
Gamma_Theta_rot = np.matrix(1e0 * np.diag([1,1,1,1,1,1])) # Adaptive rates
1449+
# Gamma_x_rot = np.matrix(1e1 * np.diag([1,1,10])) # Adaptive rates
1450+
# Gamma_r_rot = np.matrix(1e-4 * np.diag([1,1,1])) # Adaptive rates
1451+
# Gamma_Theta_rot = np.matrix(1e0 * np.diag([1,1,1,1,1,1])) # Adaptive rates
1452+
Gamma_x_rot = np.matrix(1e4 * np.diag([1,1,1])) # Adaptive rates
1453+
Gamma_r_rot = np.matrix(1e1 * np.diag([1,1,1])) # Adaptive rates
1454+
Gamma_Theta_rot = np.matrix(1e2 * np.diag([1,1,1,1,1,1])) # Adaptive rates
14231455

14241456
# ----------------------------------------------------------------
14251457
# Safety Mechanism Parameters
@@ -1431,16 +1463,16 @@ def MRACwithBASELINE_SafetyMechanism(mass_total_estimated,air_density_estimated,
14311463

14321464
# Mu - elliptic cone intersection
14331465
EllipticConeEpsilon = 1e-2
1434-
maximumRollAngle = math.radians(20) # [rad] 25
1435-
maximumPitchAngle = math.radians(20) # [rad] 25
1466+
maximumRollAngle = math.radians(60) # [rad] 25 - 32
1467+
maximumPitchAngle = math.radians(60) # [rad] 25 - 32
14361468

14371469
# Mu - plane intersection
14381470
planeEpsilon = 1e-2
14391471
alphaPlane = 0.95 # [-] coefficient for setting the 'height' of the bottom plane. Must be >0 and <1.
14401472

14411473

1442-
return [number_of_states,size_DATA,KP_tran,KD_tran,KI_tran,KP_tran_PD_baseline,KD_tran_PD_baseline,KP_rot,KP_rot_PI_baseline,
1443-
KD_rot_PI_baseline,KI_rot_PI_baseline,K_P_omega_ref,A_tran,B_tran,A_tran_bar,Lambda_bar,Theta_tran_adaptive_bar,
1474+
return [number_of_states,size_DATA,KP_tran,KD_tran,KI_tran,KP_tran_PD_baseline,KD_tran_PD_baseline,KP_rot,KI_rot,KP_rot_PI_baseline,
1475+
KD_rot_PI_baseline,KI_rot_PI_baseline,K_P_omega_ref,K_I_omega_ref,A_tran,B_tran,A_tran_bar,Lambda_bar,Theta_tran_adaptive_bar,
14441476
A_ref_tran,B_ref_tran,Gamma_x_tran,Gamma_r_tran,Gamma_Theta_tran,Gamma_Theta_tran,Q_tran,P_tran,K_x_tran_bar,K_r_tran_bar,A_rot,
14451477
B_rot,A_ref_rot,B_ref_rot,Q_rot,P_rot,Gamma_x_rot,Gamma_r_rot,Gamma_Theta_rot,sphereEpsilon,maximumThrust,
14461478
EllipticConeEpsilon,maximumRollAngle,maximumPitchAngle,planeEpsilon,alphaPlane]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function pos = ComputePosition(t, r_x, r_y, r_z)
2+
%COMPUTEPOSITION Summary of this function goes here
3+
% Detailed explanation goes here
4+
5+
6+
% Computing tangent vector T
7+
r_x_ev = polyval(r_x, t);
8+
r_y_ev = polyval(r_y, t);
9+
r_z_ev = polyval(r_z, t);
10+
11+
pos = [r_x_ev; r_y_ev; r_z_ev];
12+
13+
end
14+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
function R = FrenetSerretFrame(t, r_x, r_y, r_z)
2+
%FRENETSERRETFRAME Summary of this function goes here
3+
% Detailed explanation goes here
4+
5+
% Computing tangent vector T
6+
dr_x = polyval(polyder(r_x), t);
7+
dr_y = polyval(polyder(r_y), t);
8+
dr_z = polyval(polyder(r_z), t);
9+
10+
dr = [dr_x; dr_y; dr_z];
11+
T = dr / norm(dr);
12+
13+
% Computing binormal vector B
14+
ddr_x = polyval(polyder(polyder(r_x)), t);
15+
ddr_y = polyval(polyder(polyder(r_y)), t);
16+
ddr_z = polyval(polyder(polyder(r_z)), t);
17+
18+
ddr = [ddr_x; ddr_y; ddr_z];
19+
20+
B = cross(dr,ddr) / norm(cross(dr,ddr));
21+
22+
% Computing normal vector N
23+
24+
N = cross(B,T);
25+
26+
R = [T N B];
27+
28+
29+
end
30+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function R = GenerateRotMat(phi, theta, psi)
2+
%GENERATEROTMAT Rotation matrix deriving from a 321 rotation sequence
3+
% roll - phi
4+
% pitch - theta
5+
% psi - psi
6+
7+
R = [cos(psi)*cos(theta) -cos(phi)*sin(psi) + cos(psi)*sin(theta)*sin(phi) cos(psi)*cos(phi)*sin(theta) + sin(psi)*sin(phi);
8+
cos(theta)*sin(psi) cos(psi)*cos(phi) + sin(psi)*sin(theta)*sin(phi) -cos(psi)*sin(phi) + cos(phi)*sin(psi)*sin(theta);
9+
-sin(theta) cos(theta)*sin(phi) cos(theta)*cos(phi)];
10+
11+
12+
13+
14+
end
15+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function norm_value = Norm2D(poly_coef_x,poly_coef_y,t)
2+
%NORM2D Computes the 2D norm from polynomial coefficients of the components of the vector
3+
% Detailed explanation goes here
4+
5+
norm_value = sqrt((polyval(poly_coef_x,t))^2 + (polyval(poly_coef_y,t))^2);
6+
7+
8+
end
9+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function derivative_value = Norm2Dderivative(poly_coef_x,...
2+
poly_coef_y,...
3+
poly_coef_x_prime,...
4+
poly_coef_y_prime,...
5+
t)
6+
%NORM2DDERIVATIVE Computes the derivative of the 2D norm from polynomial
7+
%coefficients of the components of the vector
8+
% Detailed explanation goes here
9+
10+
derivative_value = (polyval(poly_coef_x,t)*polyval(poly_coef_x_prime,t) +...
11+
polyval(poly_coef_y,t)*polyval(poly_coef_y_prime,t)) /...
12+
Norm2D(poly_coef_x,poly_coef_y,t);
13+
14+
15+
end
16+
Binary file not shown.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function [poly_coeff_matrix_out_x,...
2+
poly_coeff_matrix_out_y,...
3+
poly_coeff_matrix_out_z] = PolyCoefAssigning(poly_coeff_matrix_in)
4+
%POLYCOEFASSIGNING Assigning polynomial coefficients to designated
5+
%variables
6+
% Detailed explanation goes here
7+
8+
poly_coeff_matrix_in_size = size(poly_coeff_matrix_in);
9+
10+
poly_coeff_matrix_out_size = [poly_coeff_matrix_in_size(1)/3, poly_coeff_matrix_in_size(2)];
11+
12+
poly_coeff_matrix_out_x = zeros(poly_coeff_matrix_out_size(1), poly_coeff_matrix_out_size(2));
13+
poly_coeff_matrix_out_y = zeros(poly_coeff_matrix_out_size(1), poly_coeff_matrix_out_size(2));
14+
poly_coeff_matrix_out_z = zeros(poly_coeff_matrix_out_size(1), poly_coeff_matrix_out_size(2));
15+
16+
for i=0:poly_coeff_matrix_out_size(1)-1
17+
poly_coeff_matrix_out_x(i+1,:) = poly_coeff_matrix_in(3*i + 1,:);
18+
poly_coeff_matrix_out_y(i+1,:) = poly_coeff_matrix_in(3*i + 2,:);
19+
poly_coeff_matrix_out_z(i+1,:) = poly_coeff_matrix_in(3*i + 3,:);
20+
21+
end
22+
23+
24+
end
25+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function [t_adjusted,segment] = PolyTimeAdjusted(time_waypoint_vector,t)
2+
%POLYTIMEADJUSTED Adjusts the time to be fed to the various polynomials
3+
% Detailed explanation goes here
4+
5+
num_waypoints = length(time_waypoint_vector);
6+
segment = 0;
7+
% disp('START')
8+
for i=1:num_waypoints-1
9+
% disp(['i: ', num2str(i)])
10+
% disp(['t: ', num2str(t)])
11+
if (t >= time_waypoint_vector(i) & t <= time_waypoint_vector(i+1)) % >= <
12+
segment = i;
13+
% disp(['segment: ', num2str(segment)])
14+
% disp(['time_waypoint_vector(segment): ', num2str(time_waypoint_vector(segment))])
15+
t_adjusted = t - time_waypoint_vector(segment);
16+
% disp(['t_adjusted: ', num2str(t_adjusted)])
17+
% break
18+
return
19+
end
20+
end
21+
22+
end
23+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function poly_coeff_matrix_out = PolyderMatrix(poly_coeff_matrix_in)
2+
%POLYDERMATRIX derivative of the piecewise polynomial coefficient matrix
3+
% Detailed explanation goes here
4+
5+
poly_coeff_matrix_in_size = size(poly_coeff_matrix_in);
6+
7+
poly_coeff_matrix_out = zeros(poly_coeff_matrix_in_size(1), poly_coeff_matrix_in_size(2)-1);
8+
9+
for i=1:poly_coeff_matrix_in_size(1)
10+
poly_coeff_matrix_out(i,:) = polyder(poly_coeff_matrix_in(i,:));
11+
end
12+
13+
14+
end
15+

0 commit comments

Comments
 (0)