Annexes

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 56

Universitat Politècnica De Catalunya.

Barcelona
Tech - UPC

Escola Superior d’Enginyeries Industrial, Aeroespacial i


Audiovisual de Terrassa

MODELING, SIZING AND SIMULATION OF THE


POWER SUBSYSTEM OF CUBESATS WITH
MATLAB/SIMULINK

Final Degree Project

Document: Annexes

Author:

Gonzálvez Tamarit, Iván

Director: Gago Barrio, Javier


Co-director: Gonzalez Diez, David

Spring 2022
Universitat politècnica de Catalunya- Barcelona Tech- UPC

Final degree project


Bibliography

1
Universitat politècnica de Catalunya- Barcelona Tech- UPC

2 Final degree project


Appendices

3
Appendix A

Run the simulation in a new


computer

If this program is to be used in a new computer, it is necessary to take into account the
following considerations to make it work without problems.

• First of all, the Matlab version used to develop this project is MATLAB R2021b, so
if the user wants to use a different version, should take this into account to avoid
unexpected warnings and errors.

• To make the battery pack work, it is necessary to download the Simscape and Sim-
scape Electrical toolboxes.

• To make the CubeSat vehicle work, it is necessary the Aerospace Blockset and
Aerospace Toolbox

• The visualizer must be configured following the steps that will be exposed below.

Configuration of the visualizer

1. Open the Simulink project PowerSimulator 2022, right click into the block Simulink
3D Animation, and click in Open in new tab

2. Right click in the block VR sink 1 >properties>Open Block: VR SINK1. This will
give an error, and open a new window.

5
Universitat politècnica de Catalunya- Barcelona Tech- UPC

3. In Source File, select the path by opening the folder SCENARIO, and selecting the
file scenario final

4. In Virtual World Tree>objects>children choose the variables that appear in the VR


sink 1. It is important to select the same variables, in the same order.

5. Repeat the step 2. This time it should not appear any error, and a new window will
be opend.

6. File>Open in editor>Objects>Children>Earth>Children>Appearence>Texture> im-


ageTexture. Here, change the URL by the path of the Earth’s texture in folder
scenario earth.jpg.

7. Repeat the second step, and select file>relaod.

6 Final degree project


Appendix B

Important aspects of the visualizer

The visualizer requires lots of inputs that locate and orientate the Sun, the Earth, the
CubeSat, the solar panels, and the antenna in the space. Some of this variables are
computed by the Simulink project, as were included in the template, but the ones regarding
the position and orientation of the solar cells are computed in a self-made Matlab script.
This script is named SolarCellsVR whose inputs are the angles α and β, the faces that
have associated a solar cell, and a scale factor related to the size of the CubeSat’s face.
If the user wants to edit this script, it is important to know that the coordinates system
used by Matlab is not the same as the one used by the Visualizer. In the following table,
the equivalences of the axis is exposed:

Matlab Visualizer
x x
y z
z -y

Table B.1: Visualizer coordinate system

Three different translations are performed in that script. The first one, to locate each
the solar panel in its face, the second one to avoid that a part of the solar panel goes inside
the CubeSat’s frame when the solar panel rotates, and the third one to move the solar
panels to the extremes of the faces in the 1DOF and symmetric configurations.
Regarding the rotations, it is computed by means of rotation matrices, and the function
vrrotmat2vec converts the rotation matrix into the format that is required by the visualizer
to rotate the objects.

7
Universitat politècnica de Catalunya- Barcelona Tech- UPC

8 Final degree project


Appendix C

Matlab Scripts

C.1 Script 0.1: Machine learning-GetData

1 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 % TFG Ivan Gonzalvez Tamarit: Solar Panel Orientation
3 % SCRIPT 0.1: Machine learning−GetData
4

5 % Director: Javier Gago


6 % Co−director: David Gonzalez
7 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
8 clc, clear, clear all
9

10 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
11 % 1. INPUTS
12 % User definition of the different solver's inputs
13 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
14

15 N=500; %Number of iterations


16 Tmin=−100; %Minimum temperature
17 Tmax=100; %Maximum temperature
18 Irrad min=10; %Minimum irradiance
19 Irrad max=1700; %Maximum irradiance
20

21

22 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
23 % 2. OBTAIN THE DATA
24 % Simulate the "MPPT simul" and save the results for different

9
Universitat politècnica de Catalunya- Barcelona Tech- UPC

25 % combinations of temperature and irradiance


26 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
27

28 %Create random values of temperature and irradiance


29 T vec=Tmin+(Tmax−Tmin).*rand(N,1);
30 Irrad vec=Irrad min+(Irrad max−Irrad min).*rand(N,1);
31

32 %Run simulations
33 cont=0;
34 for i=1:N
35 cont=cont+1;
36 Temperature=T vec(i);
37 Irradiance=Irrad vec(i);
38 tic
39 out=sim('MPPT simul.slx');
40 toc
41 I(cont)=out.current(end);
42 V(cont)=out.voltage(end);
43 T(cont)=Temperature;
44 Irrad(cont)=Irradiance;
45 cont
46 end
47

48 %Generate DATA matrix


49 DATA=[V',T',Irrad'];
50 save('DATA MPPT','DATA','I');

C.2 Script 0.2: Machine learning-Regularization

1 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 % TFG Ivan Gonzalvez Tamarit: Solar Panel Orientation
3 % SCRIPT 0.2: Machine learning−Regularization
4

5 % Director: Javier Gago


6 % Co−director: David Gonzalez
7 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
8 clc, clear, clear all, warning('off','all');
9

10 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
11 % 1. INPUTS

10 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

12 % User definition of the different inputs


13 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
14 deg=4; %Maximum degree of the polynomial basis ...
proposed
15 splitting reg=5000; %Number of random spits for regulatization
16 splitting=5000; %Number of splits after regularization
17 lambda =logspace(−30,5,50); %Define the vector of lambda
18 smoothy=1; %How many times the MSE curve will be smoothed
19

20 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
21 % 2. LOAD DATA
22 % Load the data that will be used to train/test the machine
23 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
24

25 load('DATA MPPT');
26 Y=DATA(:,1);
27 X=DATA(:,[2,3]);
28

29 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
30 % 3. PROPOSE A BASIS
31 % Propose the basis to fit the data (polynomial, exponential...)
32 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
33

34 %X1ˆ1,X2ˆ1,X1ˆ2,X2ˆ2...X1ˆdeg,X2ˆdeg
35 X=[ones(size(X,1),1),X];
36 for i=2:deg
37 X=[X,X(:,[2,3]).ˆi];
38 end
39

40 %X1*X2, X1*X2ˆ2...X1*X2ˆdeg
41 %X1ˆ2*X2, X1ˆ2*X2ˆ2... X1ˆ2*X2ˆdeg
42 %......................X1ˆdeg*X2ˆdeg
43

44

45 for i=1:deg
46 for j=1:deg
47 X=[X,X(:,2).ˆi.*X(:,3).ˆj];
48 end
49 end
50

51

11 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

52 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
53 % 4. REGULARIZATION
54 % Compute the optimum value of lambda for regularization
55 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
56

57

58 for cont=1:length(lambda )
59 lambda=lambda (cont);
60 for k=1:splitting reg
61

62 % Random splitting
63 p = randperm(size(X,1)); %Choose random ...
numbers
64 aux1=p(1:round(0.8*length(DATA))); %Train indices
65 aux2=p(round(0.8*length(DATA))+1:end); %Test indices
66

67 %Train and test vectors


68 Xtrain=X(p(aux1),:);
69 Ytrain=Y(p(aux1),:);
70 Xtest=X(p(aux2),:);
71 Ytest=Y(p(aux2),:);
72

73 %Solve the minimization problem


74 w=[Xtrain'*Xtrain+lambda*eye(size(Xtrain,2))]\(Xtrain'*Ytrain);
75

76 %Compute the errors


77 for i=1:size(Xtest,1)
78 error test(i)=abs(Ytest(i)−Xtest(i,:)*w);
79 end
80 for i=1:size(Xtrain,1)
81 error train(i)=abs(Ytrain(i)−Xtrain(i,:)*w);
82 end
83

84 MSE test(k)=1/size(Xtest,1)*sum((error test).ˆ2); %MSE test


85 MSE train(k)=1/size(Xtrain,1)*sum((error train).ˆ2); %MSE train
86 end
87 MSE test mean(cont)=mean(MSE test); %Compute the mean MSE test
88 MSE train mean(cont)=mean(MSE train); %Compute the mean MSE train
89 var test(cont)=var(MSE test,1); %Variance of the MSE test
90 var train(cont)=var(MSE train,1); %Variance of the MSE train
91 disp([cont,length(lambda )]) %Display the iteration
92 end
93

12 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

94

95 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
96 % 5. PLOT MSE and VARIANCE
97 % Plot the MSE with its mean and its variance. Also a smoothed curve
98 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
99

100 %Compute a smoother curve for the MSE


101 MSE test smooth=MSE test mean;
102 for i=1:smoothy
103 MSE test smooth=smooth(MSE test smooth);
104 end
105

106 %Plot the MSE test curves with the variance


107 figure()
108 semilogx(lambda ,MSE test mean), hold on, grid on;
109 semilogx(lambda ,MSE test mean+sqrt(var test));
110 semilogx(lambda ,MSE test mean−sqrt(var test));
111

112 legend('MSE {test}','MSE {test}+\sigma','MSE {test}−\sigma')


113 xlabel('\lambda'), ylabel('MSE'), title('MSE {test} vs \lambda');
114

115 %Plot the MSE train curves with the variance


116 figure()
117 semilogx(lambda ,MSE train mean), hold on, grid on;
118 semilogx(lambda ,MSE train mean+sqrt(var train));
119 semilogx(lambda ,MSE train mean−sqrt(var train));
120

121 legend('MSE {train}','MSE {train}+\sigma','MSE {train}−\sigma')


122 xlabel('\lambda'), ylabel('MSE'), title('MSE {train} vs \lambda');
123

124 %Plot the smoothed MSE test curve


125 figure()
126 semilogx(lambda ,MSE test smooth), grid on;
127 xlabel('\lambda'),ylabel('Smoothed MSE {test}');
128 title('Smoothed MSE {test} vs \lambda');
129

130 %Plot the MSE test curve


131 figure()
132 semilogx(lambda ,MSE test mean), grid on;
133 xlabel('\lambda'),ylabel('MSE {test}');
134 title('MSE {test} vs \lambda');
135

136 %Find the optimum value of lambda

13 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

137 [min MSE test,index lambda]=min(MSE test smooth);


138 lambda opt=lambda (index lambda);
139

140

141 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
142 % 5. COMPUTE THE REGRESSION WITH OPTIMUM LAMBDA
143 % Use the most optimum lambda to coimpute the coefficients
144 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
145 clearvars −except lambda opt deg splitting DATA X Y;
146 lambda=lambda opt;
147 for k=1:splitting
148 % Random splitting
149 p = randperm(size(X,1)); %Choose random ...
numbers
150 aux1=p(1:round(0.8*length(DATA))); %Train indices
151 aux2=p(round(0.8*length(DATA))+1:end); %Test indices
152

153 %Train and test vectors


154 Xtrain=X(p(aux1),:);
155 Ytrain=Y(p(aux1),:);
156 Xtest=X(p(aux2),:);
157 Ytest=Y(p(aux2),:);
158

159 %Solve the minimization problem


160 w=[Xtrain'*Xtrain+lambda*eye(size(Xtrain,2))]\(Xtrain'*Ytrain);
161

162 %Compute the errors


163 for i=1:size(Xtest,1)
164 error test(i)=abs(Ytest(i)−Xtest(i,:)*w);
165 end
166 for i=1:size(Xtrain,1)
167 error train(i)=abs(Ytrain(i)−Xtrain(i,:)*w);
168 end
169

170 MSE test(k)=1/size(Xtest,1)*sum((error test).ˆ2); %MSE test


171 MSE train(k)=1/size(Xtrain,1)*sum((error train).ˆ2); %MSE train
172 end
173 var MSE test=var(MSE test,1); %Variance of the MSE test
174 MSE test mean=mean(MSE test); %Compute the mean MSE test
175 MSE train mean=mean(MSE train); %Compute the mean MSE train
176

177

14 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

178 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
179 % 6. PLOTS OF DATA AND REGRESSION
180 % Plot the MSE, data, resultant surface and other interesting results
181 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
182

183 %Plot the MSE, mean MSE and its variance for each split
184 figure();
185 scatter(1:length(MSE test),MSE test), hold on
186 yline(MSE test mean);
187 yline(MSE test mean+sqrt(var MSE test));
188 yline(MSE test mean−sqrt(var MSE test));
189 legend('MSE {test}','mean MSE {test}','MSE {test}+\sqrt(\sigma)',...
190 'MSE {test}−\sqrt(\sigma)'), title('MSE {test} vs splits'),
191 xlabel('Splits'),ylabel('MSE {test}')
192

193 %Plot the data (test and train)


194 figure()
195 scatter3(Xtrain(:,2),Xtrain(:,3),Ytrain(:)), hold on;
196 scatter3(Xtest(:,2),Xtest(:,3),Ytest(:),'+');
197

198 %Plot the resultant surface


199 x1=linspace(−100,100,300);
200 x2=linspace(min(X(:,3)),max(X(:,3)),300);
201

202 X plot(:,:,1)=meshgrid(ones(size(x1)));
203 X plot(:,:,2)=meshgrid(x1);
204 X plot(:,:,3)=meshgrid(x2)';
205

206 for i=2:deg


207 X plot(:,:,i*2)=meshgrid(x1.ˆi);
208 X plot(:,:,i*2+1)=meshgrid(x2.ˆi)';
209 end
210 cont=0;
211 for i=1:deg
212 for j=1:deg
213 cont=cont+1;
214 X plot(:,:,deg*2+1+cont)=X plot(:,:,i*2).* X plot(:,:,j*2+1);
215 end
216 end
217

218 h=zeros(size(X plot,1));


219 for i=1:size(X plot,3)
220 h=h+X plot(:,:,i).*w(i);

15 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

221 end
222

223 surf(x1,x2,h);
224 xlabel('Temperature [C]'), ylabel('Irradiance [W/mˆ2]'),...
225 zlabel('Voltage for the MPPT [V]'), shading interp,...
226 light, lighting gouraud, material dull;
227 title('Surface plot of the machine learning regression');
228 legend('Train Data','Test Data','Regression surface')
229 ylim([10 1400])
230 xlim([−80 80])
231

232

233 %Plot the error diagram


234 figure()
235 bar(1:length(error test),error test)
236 xlabel('x');
237 ylabel('Error')
238 title('Error bar diagram')
239

240 %Plot the values of w


241 figure()
242 bar(1:size(w,1),w)
243 xlabel('Degree');
244 ylabel('\omega')
245 title('Values of \omega')

C.3 Script 0.3: Machine learning-PostProcess

1 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 % TFG Ivan Gonzalvez Tamarit: Solar Panel Orientation
3 % SCRIPT 0.3: Machine learning−PostProcess
4

5 % Director: Javier Gago


6 % Co−director: David Gonzalez
7 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
8

9 clc, clear all, close all


10

11 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
12 % 1. INPUT AND LOAD DATA

16 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

13 % User definition of the different solver's inputs


14 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
15 splits=100; %Number of random splits for the MSE calculation
16 lambda=0.0215; %Optimum value of lambda (from the regularization script)
17 deg=4; %Degree of the polinomial basis of the own−made model
18

19 addpath('ToolboxModels')
20 load('DATA MPPT.mat');
21

22

23 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
24 % 2. PREVIOUS CALCULATIONS
25 % Previous calculations for the own−made model
26 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
27 Y=DATA(:,1);
28 X=DATA(:,[2,3]);
29

30 %Propose basis for the own−made model


31 X=[ones(size(X,1),1),X];
32 for i=2:deg
33 X=[X,X(:,[2,3]).ˆi];
34 end
35

36 for i=1:deg
37 for j=1:deg
38 X=[X,X(:,2).ˆi.*X(:,3).ˆj];
39 end
40 end
41

42 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
43 % 3. MSE for each model
44 % Compute the MSE for each model, mean value and variance
45 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
46 for i=1:splits
47

48 %Generate random splitting


49 p = randperm(size(DATA,1)); %Choose random numbers
50 aux1=p(1:round(0.8*length(DATA))); %Train indices
51 aux2=p(round(0.8*length(DATA))+1:end); %Test indices
52

53 %Train and test matrix


54 DATA train=DATA(p(aux1),:);

17 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

55 DATA test=DATA(p(aux2),:);
56

57 %Train the own−made model


58 Xtrain=X(p(aux1),:);
59 Ytrain=Y(p(aux1),:);
60 Xtest=X(p(aux2),:);
61 Ytest=Y(p(aux2),:);
62 trainedOwn=[Xtrain'*Xtrain+lambda*eye(size(Xtrain,2))]\(Xtrain'*Ytrain);
63

64 %Train each regression model


65 [trainedCoarseTree, ¬] = CoarseTree(DATA train);
66 [trainedOptimizableTree, ¬] = OptimizableTree(DATA train);
67

68 [trainedMatern52GPR, ¬] = Matern52GPR(DATA train);


69 [trainedOptimizableGPR, ¬] = OptimizableGPR(DATA train);
70

71 [trainedMediumGaussianSVM, ¬] = MediumGaussianSVM(DATA train);


72 [trainedOptimizableSVM, ¬] = OptimizableSVM(DATA train);
73

74

75 %Compute the Yfit for each test sample and each model
76 Yfit CoarseTree=trainedCoarseTree.predictFcn(DATA test(:,[2,3]));
77 Yfit OptimizableTree=trainedOptimizableTree.predictFcn(DATA test(:,[2,3]));
78

79 Yfit Matern52GPR=trainedMatern52GPR.predictFcn(DATA test(:,[2,3]));


80 Yfit OptimizableGPR=trainedOptimizableGPR.predictFcn(DATA test(:,[2,3]));
81

82 Yfit MediumGaussianSVM=trainedMediumGaussianSVM.predictFcn(DATA test(:,[2,3]));


83 Yfit OptimizableSVM=trainedOptimizableSVM.predictFcn(DATA test(:,[2,3]));
84

85 Yfit Own=Xtest*trainedOwn;
86

87 %Compute the MSE of each model


88 MSE CoarseTree(i)=1/length(Yfit CoarseTree)*...
89 sum((Yfit CoarseTree−DATA test(:,1)).ˆ2);
90 MSE OptimizableTree(i)=1/length(Yfit OptimizableTree)*...
91 sum((Yfit OptimizableTree−DATA test(:,1)).ˆ2);
92

93 MSE Matern52GPR(i)=1/length(Yfit Matern52GPR)*...


94 sum((Yfit Matern52GPR−DATA test(:,1)).ˆ2);
95 MSE OptimizableGPR(i)=1/length(Yfit OptimizableGPR)*...
96 sum((Yfit OptimizableGPR−DATA test(:,1)).ˆ2);
97

98 MSE MediumGaussianSVM(i)=1/length(Yfit MediumGaussianSVM)*...

18 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

99 sum((Yfit MediumGaussianSVM−DATA test(:,1)).ˆ2);


100 MSE OptimizableSVM(i)=1/length(Yfit OptimizableSVM)*...
101 sum((Yfit OptimizableSVM−DATA test(:,1)).ˆ2);
102

103 MSE Own(i)=1/length(Yfit Own)*...


104 sum((Yfit Own−Ytest).ˆ2);
105

106 disp(['Split: ', num2str(i), '/', num2str(splits)]);


107 end
108

109 %Compute the mean MSE of each model


110 MSE CoarseTree mean=mean(MSE CoarseTree);
111 MSE OptimizableTree mean=mean(MSE OptimizableTree);
112

113 MSE Matern52GPR mean=mean(MSE Matern52GPR);


114 MSE OptimizableGPR mean=mean(MSE OptimizableGPR);
115

116 MSE MediumGaussianSVM mean=mean(MSE MediumGaussianSVM);


117 MSE OptimizableSVM mean=mean(MSE OptimizableSVM);
118

119 MSE Own mean=mean(MSE Own);


120

121 %Compute the variance of the MSE of each model


122 MSE CoarseTree var=var(MSE CoarseTree);
123 MSE OptimizableTree var=var(MSE OptimizableTree);
124

125 MSE Matern52GPR var=var(MSE Matern52GPR);


126 MSE OptimizableGPR var=var(MSE OptimizableGPR);
127

128 MSE MediumGaussianSVM var=var(MSE MediumGaussianSVM);


129 MSE OptimizableSVM var=var(MSE OptimizableSVM);
130

131 MSE Own var=var(MSE Own);


132 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
133 % 4. PLOTS
134 % Plot the results to compare the different models
135 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
136

137 %Plot the MSE, mean MSE and its variance for each split
138

139 figure();
140 subplot(4,2,[1 2])
141 scatter(1:i,MSE Own), hold on

19 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

142 yline(MSE Own mean);


143 yline(MSE Own mean+sqrt(MSE Own var));
144 yline(MSE Own mean−sqrt(MSE Own var));
145 legend('MSE','mean MSE','MSE+\sigma','MSE−\sigma');
146 title('MSE for the own−made model')
147

148 subplot(4,2,3)
149 scatter(1:i,MSE CoarseTree), hold on
150 yline(MSE CoarseTree mean);
151 yline(MSE CoarseTree mean+sqrt(MSE CoarseTree var));
152 yline(MSE CoarseTree mean−sqrt(MSE CoarseTree var));
153 legend('MSE','mean MSE','MSE+\sigma','MSE−\sigma');
154 title('MSE for Coarse Tree model')
155

156 subplot(4,2,4)
157 scatter(1:i,MSE OptimizableTree), hold on
158 yline(MSE OptimizableTree mean);
159 yline(MSE OptimizableTree mean+sqrt(MSE OptimizableTree var));
160 yline(MSE OptimizableTree mean−sqrt(MSE OptimizableTree var));
161 legend('MSE','mean MSE','MSE+\sigma','MSE−\sigma');
162 title('MSE for Optimizable Tree model')
163

164 subplot(4,2,5)
165 scatter(1:i,MSE Matern52GPR), hold on
166 yline(MSE Matern52GPR mean);
167 yline(MSE Matern52GPR mean+sqrt(MSE Matern52GPR var));
168 yline(MSE Matern52GPR mean−sqrt(MSE Matern52GPR var));
169 legend('MSE','mean MSE','MSE+\sigma','MSE−\sigma');
170 title('MSE for Matern 5/2 GPR model')
171

172 subplot(4,2,6)
173 scatter(1:i,MSE OptimizableGPR), hold on
174 yline(MSE OptimizableGPR mean);
175 yline(MSE OptimizableGPR mean+sqrt(MSE OptimizableGPR var));
176 yline(MSE OptimizableGPR mean−sqrt(MSE OptimizableGPR var));
177 legend('MSE','mean MSE','MSE+\sigma','MSE−\sigma');
178 title('MSE for Optimizable GPR model')
179

180 subplot(4,2,7)
181 scatter(1:i,MSE MediumGaussianSVM), hold on
182 yline(MSE MediumGaussianSVM mean);
183 yline(MSE MediumGaussianSVM mean+sqrt(MSE MediumGaussianSVM var));
184 yline(MSE MediumGaussianSVM mean−sqrt(MSE MediumGaussianSVM var));
185 legend('MSE','mean MSE','MSE+\sigma','MSE−\sigma');

20 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

186 title('MSE for Medium Gaussian SVM model')


187

188 subplot(4,2,8)
189 scatter(1:i,MSE OptimizableSVM), hold on
190 yline(MSE OptimizableSVM mean);
191 yline(MSE OptimizableSVM mean+sqrt(MSE OptimizableSVM var));
192 yline(MSE OptimizableSVM mean−sqrt(MSE OptimizableSVM var));
193 legend('MSE','mean MSE','MSE+\sigma','MSE−\sigma');
194 title('MSE for Optimizable SVM model')
195

196 disp('MSE:')
197 disp(['Coarse Tree: ',num2str(MSE CoarseTree mean)])
198 disp(['Optimizable Tree: ',num2str(MSE OptimizableTree mean)])
199 disp(['Matern 5/2 GPR: ',num2str(MSE Matern52GPR mean)])
200 disp(['Optimizable GPR: ',num2str(MSE OptimizableGPR mean)])
201 disp(['Medium Gaussian SVM: ',num2str(MSE MediumGaussianSVM mean)])
202 disp(['Optimizable SVM: ',num2str(MSE OptimizableSVM mean)])
203 disp(['Own model: ',num2str(MSE Own mean)])
204 disp('−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−')
205

206 disp('Variance:')
207 disp(['Coarse Tree: ',num2str(MSE CoarseTree var)])
208 disp(['Optimizable Tree: ',num2str(MSE OptimizableTree var)])
209 disp(['Matern 5/2 GPR: ',num2str(MSE Matern52GPR var)])
210 disp(['Optimizable GPR: ',num2str(MSE OptimizableGPR var)])
211 disp(['Medium Gaussian SVM: ',num2str(MSE MediumGaussianSVM var)])
212 disp(['Optimizable SVM: ',num2str(MSE OptimizableSVM var)])
213 disp(['Own model: ',num2str(MSE Own var)])
214

215 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
216 % 5. SAVE THE RESULTS OF THE BEST REGRESSION MODEL
217 % Save the results of the chosen regression model to use it in the
218 % simulink project
219 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
220 save('ML Regression','trainedOwn')

C.4 Script 1.1: Input data

1 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 % TFG Ivan Gonzalvez Tamarit: Solar Panel Orientation

21 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

3 % SCRIPT 1.1: Input data


4

5 % Director: Javier Gago


6 % Co−director: David Gonzalez
7 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
8 clc, clear, clear all
9

10 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
11 % 1. ASTRODYNAMICS
12 % User definition of the different astrodynamics inputs
13 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
14 Re=6371000; % Earth Radius [m]
15 Rs=696000000; % Sun Radius [m]
16 mu=3.986044418e14; % Standard Earth's gravitational parameter
17

18 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
19 % 2. ATTITUDE CONTROL
20 % Variables related to the attitude control of the CubeSat
21 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
22 %Initial conditions
23 pitch=0; %Theta [deg]
24 yaw=0; %Phi [deg]
25 roll=0; %Psi [deg]
26 eulerangles=[roll pitch yaw]; %Initial Euler angles[deg]
27 bodyang=[0 0 0]; %Initial body angular rates [deg/s]
28

29 %Geometry
30 M = 1; %Mass [kg]
31 side = 0.1; %Side [m]
32 INERTIA = [M*sideˆ2/6 0 0;0 M*sideˆ2/6 0;0 0 M*sideˆ2/6]; %Inertia ...
[kg mˆ2]
33

34 %Magnetorquers
35 n=300; %Number of turns in the coil
36 Acoil=pi*(4e−03)ˆ2; %Coil section Area [mˆ2]
37

38 %Reaction Wheels
39 rpm RW initial = 0; %Initial angular speed [rpm]
40 rpm RW max = 10000; %Saturation angular speed [rpm]
41 w RW initial = rpm RW initial *2*pi/60;
42 w RW max = rpm RW max *2*pi/60;
43 mom sat RW = 1.5e−3; %Momentum saturation [N−m−s]

22 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

44 I RW = mom sat RW/w RW max; %Inertia of RW


45 beta RW = (400e−3−10e−3)/w RW max; %Friction losses of RW ...
[W/(rad/s)]
46 M dist = −6.35e−11*[1 1 1]; %Disturbance torque [N−m]
47 DistrMatr = eye(3); %Distribution matrix
48

49

50 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
51 % 3. SOLAR CELLS CHARACTERISTICS
52 % User definition of the different solar cells inputs
53 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
54 %General characteristics
55 irrad = 1367; %Irradiance [W/mˆ2]
56 celleff = 0.22; %Solar cell efficiency (approx)
57 ns = 4; %Solar cells per Cubesat's face
58 Asol = (10*20*(30.8−4*0.2)/5)*10ˆ(−6); %Solar cell area [mˆ2] (fram ...
datasheet)
59 DCeff = 0.9; %DC−DC converter efficiency
60 l=0.3; %Scale of the Solar Cells ...
(for the VR)
61

62 %Variables for thermal analysis of solar cells


63 epsilon cell=0.899; %Emittence of the solar cell
64 alpha cell=0.92; %Absorptance of the solar cell
65 epsilon back=0.88; %Emmitance of the back side of the solar ...
cell
66 alpha back=0.39; %Absorptance of the back side of solar cell
67

68 Cp cell=800.3; %Specific heat of the solar cell [J/KgK]


69 rho cell=2510; %Density of the solar cell [kg/mˆ3]
70 z direct=0.0015; %Length of the solar cell in z direction [m]
71

72 sigma=5.670*10ˆ(−8); %Stefan−Boltzmann constant [W/mˆ2*Kˆ4]


73 beta=0.35; %Albedo
74 Tearth=273−23; %Temperature of the Earth as a black body
75 irrad sun=1371; %Irradiance of the Earth
76 irrad earth=sigma*Tearthˆ4; %Irradiance of the Earth [W/mˆ2]
77

78 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
79 % 4. BATTERY CHARACTERISTICS
80 % User definition of the different battery inputs
81 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−

23 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

82

83 Volt=3.2; %Nominal voltage (V)


84 Capac=1.5; %Rated capacity (Ah)
85 Initial charge=80; %Initial state−of−charge (%)
86 Respons time=1; %Battery response time (s)
87

88 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
89 % 5. NUMERICAL VARIABLES
90 % User definition of the different numerical inputs
91 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
92

93 tol=1e−12; %Error tolerance for mean anomaly


94 T SAMPLE=5; %Sample time of the simulation
95

96 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
97 % 6. SAVE
98 % Save the input data
99 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
100 save('InputData')

C.5 Script 1.2: Mission Profile Generator

1 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 % TFG Ivan Gonzalvez Tamarit: Solar Panel Orientation
3 % SCRIPT 1.2: Mission Profile Generator
4

5 % Director: Javier Gago


6 % Co−director: David Gonzalez
7 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
8 clc, clear, clear all
9

10 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
11 % 1. INPUTS
12 % User definition of the different inputs
13 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
14

15 load("InputData");
16

24 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

17 %Keplerian Orbital Elements


18 a= 6791000; %Semi−major axis (>0) [m]
19 e=0.00001; %Eccentricity (≥0)
20 Omega=32; %RAAN (0=<Omega<360) [deg]
21 i=70; %Inclination (0≤i<180)[deg]
22 omega=30; %Argument of periapsis (0≤omega<360) [deg]
23 theta 0=0; %Value of the true anomaly at t=0
24

25 %Simulation time (choose between number of orbits or absolute time)


26 sim Days=0; %InitialDays that will be simulated
27 sim Hours=7; %InitialHours that will be simulated
28 sim Minutes=45; %InitialMinutes that will be simulated
29 sim Seconds=10; %InitialSeconds that will be simulated
30

31 nT=1; %Number of orbits that will be simulated (zero to ...


ignore)
32 T=sqrt(4*piˆ2/mu*aˆ3); %Orbital period
33

34 %Power requirements
35 constant=2; %Constant well−functioning power [W]
36 attitude=1; %Constant attitude power [W]
37 link=20; %Power for sending information [W]
38 seconds link=5*60; %Time sending information [s]
39 times link=2; %Times per period that the satellite sends ...
information
40

41

42 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
43 % 2. PREVIOUS CALCULATIONS
44 % Calculation of the simulation's duration and others
45 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
46

47 %Duration of the simulation


48 if nT==0
49 tstop=sim initialSeconds+60*sim initialMinutes+...
50 60*60*sim initialHours+60*60*24*sim initialDays;
51 else
52 tstop=nT*T;
53 end
54 time=0:1:tstop;
55 periods=round(tstop/T);
56 length periods=round(length(time)/periods);
57

25 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

58 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
59 % 3. DATA GENERATOR
60 % Generate arrays with the power information
61 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
62

63 %Constant values of power generator


64 power constant=constant*ones(length(time),1);
65 power attitude=attitude*ones(length(time),1);
66

67 %Variable values of power generator


68 power link=zeros(length(time),1);
69

70 for i=0:times link−1


71 for j=1:periods
72 set period=(j−1)*length periods;
73 set link=round(i/times link*length periods)+1;
74 power link([set period+set link:set period+set link+seconds link],1)=link;
75 end
76 end
77

78 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
79 % 4. SAVE DATA
80 % Save the data generated
81 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
82 save('PowerProfile','power constant','power attitude','power link');

C.6 Script 2.1: Cell orientation optimization

1 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 % TFG Ivan Gonzalvez Tamarit: Solar Panel Orientation
3 % SCRIPT 2.1: Cell orientation optimization
4

5 % Director: Javier Gago


6 % Co−director: David Gonzalez
7 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
8 clc, clear all, close all, warning('off','all')
9

10 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−

26 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

11 % 1. INPUT
12 % User definition of the different solver's inputs
13 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
14 addpath('MachineLearning'); %Add the path with the machine ...
leaening info
15 addpath('Functions'); %Add the path with the functions
16 load('InputData.mat'); %Load the input data
17 load('ML Regression.mat'); %Load the regression model for the MPPT
18

19 %Initial Date
20 initialYear=2025; %Year
21 initialMonth=6; %Month (number 1−12)
22 initialDay=5; %Day (number 1−31)
23 initialHour=3; %Hour (number 00−23)
24 initialMinute=7; %Minute (number 0−59)
25 initialSecond=23; %Second (number 0−59)
26

27 %Keplerian Orbital Elements


28 a= 6791000; %Semi−major axis (>0) [m]
29 e=0.00001; %Eccentricity (≥0)
30 Omega=320; %RAAN (0=<Omega<360) [deg]
31 i=75; %Inclination (0≤i<180)[deg]
32 omega=50; %Argument of periapsis (0≤omega<360) [deg]
33 theta 0=230; %Value of the true anomaly at t=0
34

35 %Simulation time (choose between number of orbits or absolute time)


36 sim Days=0; %InitialDays that will be simulated
37 sim Hours=7; %InitialHours that will be simulated
38 sim Minutes=45; %InitialMinutes that will be simulated
39 sim Seconds=10; %InitialSeconds that will be simulated
40

41 nT=1; %Number of orbits that will be simulated (zero to ...


ignore)
42

43 %Optimization variables
44 alpha=[−90:5:90];
45 beta =[−90:5:90];
46

47 %Faces with solar panels


48 faces panels=[1,2,3,4,5,6];
49

50 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
51 % 2. PREVIOUS CALCULATIONS

27 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

52 % Compute some previous calculations for the simulation


53 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
54

55 %Sizing parameters
56 N batt=1; %Number of battery blocks (3p1s)
57 SF Panel1=1; %Sizing factor for the solar panel 1
58 SF Panel2=1; %Sizing factor for the solar panel 2
59 SF Panel3=1; %Sizing factor for the solar panel 3
60 SF Panel4=1; %Sizing factor for the solar panel 4
61 SF Panel5=1; %Sizing factor for the solar panel 5
62 SF Panel6=1; %Sizing factor for the solar panel 6
63

64 % Solar cell orientation (VR)


65 alpha sc=zeros(1,6);
66 beta sc=zeros(1,6);
67 alpha 1dof=zeros(1,6);
68 beta 1dof=zeros(1,6);
69 alpha symmetry=zeros(1,6);
70 beta symmetry=zeros(1,6);
71 opt alpha=zeros(1,6);
72 opt beta=zeros(1,6);
73

74 %Orientation of the Solar Cells for the VR


75 [SolCellRot1, SolCellRot2, SolCellRot3, SolCellRot4, SolCellRot5,...
76 SolCellRot6, SolCellTrans1, SolCellTrans2, SolCellTrans3,...
77 SolCellTrans4, SolCellTrans5, SolCellTrans6, scale sc]=...
78 SolarCellsVR(l, beta sc, alpha sc, faces panels);
79

80 %Initial date of the simulation


81 initial date=datetime(initialYear,initialMonth,...
82 initialDay,initialHour,initialMinute,initialSecond); %Initial date
83 initialJulian=juliandate(initial date); %Initial Julian Date
84 epochJulian = initialJulian; %Epoch of ECI frame
85 T=sqrt(4*piˆ2/mu*aˆ3); %Orbital period
86

87 %Duration of the simulation


88 if nT==0
89 tstop=sim Seconds+60*sim Minutes+...
90 60*60*sim Hours+60*60*24*sim Days;
91 else
92 tstop=nT*T;
93 end
94

95 %Set the power consumption to zero to make sure the simulation finishes

28 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

96 power constant=zeros(1,length(0:tstop));
97 power attitude=zeros(1,length(0:tstop));
98 power link=zeros(1,length(0:tstop));
99

100 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
101 % 3. RUN THE SIMULATION
102 % Solve the location and attitude at each instant with Simulink
103 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
104

105 %Run the simulation


106 out=sim('SIMULADOR 2021.slx');
107

108 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
109 % 4. SUN INCIDENCE IN EACH FACE AND POWER OBTAINED
110 % Compute how does the Sun incide in each face of the cubesat for
111 % different values of alpha and beta and the power absorved
112 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
113

114 %Load results from simulation


115 steps=length(out.t);
116 umbra =out.umbra condition;
117 for N=1:steps
118 R ECI BODY(:,:,N)=out.DCM eci2body(:,:,N); %DCM ECI−>BODY
119 R BODY ECI(:,:,N)=R ECI BODY(:,:,N)'; %DCM BODY−>ECI
120 unit s vec ECI(:,N)=out.sunECI(N,:)./...
121 norm(out.sunECI(N,:)); %Sun position in ECI frame
122 end
123

124 %Vector with the optimum power values


125 max total power=zeros(1,6);
126

127 %Compute the power obtained for each alpha+beta combination for each face
128 for ang1=1:length(alpha)
129 for ang2=1:length(beta )
130

131 %Components of the vectors defined by two angles


132 v1=sind(alpha(ang1))*cosd(beta (ang2));
133 v2=cosd(alpha(ang1))*cosd(beta (ang2));
134 v3=sind(beta (ang2));
135

136 for N=1:steps


137 if umbra (N)==0

29 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

138 power(i,N)=0; %If in umbra, the power absorved is zero


139 else
140 for i=faces panels
141 switch i %Unitary vectors of each solar panel in ECI
142 case 1
143 body ECI(:,N,1)=R BODY ECI(:,:,N)*[v2;v1;v3];
144 case 2
145 body ECI(:,N,2)=R BODY ECI(:,:,N)*[−v2;−v1;v3];
146 case 3
147 body ECI(:,N,3)=R BODY ECI(:,:,N)*[−v1;v2;v3];
148 case 4
149 body ECI(:,N,4)=R BODY ECI(:,:,N)*[v1;−v2;v3];
150 case 5
151 body ECI(:,N,5)=R BODY ECI(:,:,N)*[v3;−v1;v2];
152 case 6
153 body ECI(:,N,6)=R BODY ECI(:,:,N)*[v3;v1;−v2];
154 end
155 end
156

157 %Sun incidence for each face (6 faces)


158

159 %Face 1 −−> X direction


160 %Face 2 −−> −X direction
161 %Faces 3 −−> Y direction
162 %Faces 4 −−> −Y direction
163 %Faces 5 −−> Z direction
164 %Faces 6 −−> −Z direction
165

166 for i=faces panels


167 cosinus=dot(unit s vec ECI(:,N),...
168 body ECI(:,N,i)); %Cosinus solar cell−Sun postion
169

170 %if cos<0, the cell is not illuminated and is set ...
to 0
171 if (cosinus>0)
172 cosinus (i,N) = cosinus;
173 else
174 cosinus (i,N) = 0;
175 end
176

177 %Compute the power absoved by the face in each ...


timestep
178 power(i,N)=irrad*...
179 celleff*ns*Asol*...

30 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

180 cosinus (i,N);


181 end
182 end
183 end
184

185 %Total Sun power obtained by each face


186 for i=faces panels
187 total power(i)=sum(power(i,:));
188 end
189

190 %Save the most optimum orientation


191 for i=faces panels
192 if (total power(i)>max total power(i))
193 max total power(i)=total power(i);
194 opt alpha(i)=alpha(ang1);
195 opt beta(i)=beta (ang2);
196 end
197 end
198

199 %Save the power of each face vs alpha and beta for plotting
200 total power angles(ang1,ang2,:)=total power;
201 disp(['alpha=',num2str(alpha(ang1))]);
202 disp(['beta=',num2str(beta (ang2))]);
203 end
204 end
205

206 %Convert the total powers (sum of powers in each step) into mean powers
207 mean power angles=total power angles/steps;
208

209 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
210 % 5. POSTPROCESS FOR 1DOF ANALYSIS
211 % Compute the most opotimum angles assuming one variable angle and
212 % one angle fixed to zero
213 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
214 for i=faces panels
215 beta 1dof(i)=beta (...
216 find(mean power angles((length(mean power angles)+1)/2,:,i)==...
217 max(mean power angles((length(mean power angles)+1)/2,:,i))));
218 alpha 1dof(i)=alpha(...
219 find(mean power angles(:,(length(mean power angles)+1)/2,i)==...
220 max(mean power angles(:,(length(mean power angles)+1)/2,i))));
221 if mean power angles((length(mean power angles)+1)/2,...
222 find(beta ==beta 1dof(i)),i)...

31 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

223 >mean power angles(find(alpha==alpha 1dof(i)),...


224 (length(mean power angles)+1)/2,i)
225 alpha 1dof(i)=0;
226 else
227 beta 1dof(i)=0;
228 end
229 end
230

231 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
232 % 6. POSTPROCESS FOR SYMMETRY ANALYSIS
233 % Compute the most opotimum angles mantaining the symmetry of the
234 % CubeSat
235 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
236

237 for ang1=1:length(alpha)


238 power alpha(ang1)=...
239 sum(mean power angles(ang1,(length(mean power angles)+1)/2,[1:4]));
240 power alpha(ang1)=...
241 power alpha(ang1)+...
242 sum(mean power angles((length(mean power angles)+1)/2,...
243 (length(mean power angles)+1)/2,[5:6]));
244 end
245 for ang2=1:length(beta )
246 power beta(ang2)=...
247 sum(mean power angles((length(mean power angles)+1)/2,ang2,[1:4]));
248 power beta(ang2)=...
249 power beta(ang2)+...
250 sum(mean power angles((length(mean power angles)+1)/2,...
251 (length(mean power angles)+1)/2,[5:6]));
252 end
253 alpha max=alpha(find(power alpha==max(power alpha)));
254 alpha max=min(alpha max);
255 beta max=min(beta (find(power beta==max(power beta))));
256

257 if max(power alpha)>max(power beta)


258 alpha symmetry=[alpha max*ones(1,4), 0 0];
259 beta symmetry=zeros(1,6);
260 else
261 alpha symmetry=zeros(1,6);
262 beta symmetry=[beta max*ones(1,4), 0 0];
263 end
264

265

32 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

266 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
267 % 7. COMPUTE THE MEAN POWER PER ORBIT
268 % Compute the mean power per orbit for each type of configuration
269 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
270

271 %Vector with the optimum power values


272 max total power=zeros(1,6);
273 angles alpha=[zeros(1,6);opt alpha;alpha 1dof;alpha symmetry];
274 angles beta=[zeros(1,6);opt beta;beta 1dof;beta symmetry];
275

276

277 %Compute the power obtained for each alpha+beta combination for each face
278 for config=1:4
279 alpha2=angles alpha(config,:);
280 beta2=angles beta(config,:);
281

282 %Components of the vectors defined by two angles


283 v1(faces panels)=sind(alpha2(faces panels)).*cosd(beta2(faces panels));
284 v2(faces panels)=cosd(alpha2(faces panels)).*cosd(beta2(faces panels));
285 v3(faces panels)=sind(beta2(faces panels));
286

287 for N=1:steps


288 if umbra (N)==0
289 power(i,N)=0; %If in umbra, the power absorved is zero
290 else
291 for i=faces panels
292 switch i %Unitary vectors of each solar panel in ECI
293 case 1
294 body ECI(:,N,1)=R BODY ECI(:,:,N)*...
295 [v2(i);v1(i);v3(i)];
296 case 2
297 body ECI(:,N,2)=R BODY ECI(:,:,N)*...
298 [−v2(i);−v1(i);v3(i)];
299 case 3
300 body ECI(:,N,3)=R BODY ECI(:,:,N)*...
301 [−v1(i);v2(i);v3(i)];
302 case 4
303 body ECI(:,N,4)=R BODY ECI(:,:,N)*...
304 [v1(i);−v2(i);v3(i)];
305 case 5
306 body ECI(:,N,5)=R BODY ECI(:,:,N)*...
307 [v3(i);−v1(i);v2(i)];
308 case 6

33 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

309 body ECI(:,N,6)=R BODY ECI(:,:,N)*...


310 [v3(i);v1(i);−v2(i)];
311 end
312 end
313

314 %Sun incidence for each face (6 faces)


315 for i=faces panels
316 cosinus=dot(unit s vec ECI(:,N),...
317 body ECI(:,N,i)); %Cosinus solar cell−Sun postion
318

319 %if cos<0, the cell is not illuminated and is set to 0


320 if (cosinus>0)
321 cosinus (i,N) = cosinus;
322 else
323 cosinus (i,N) = 0;
324 end
325

326 %Compute the power absoved by the face in each timestep


327 power(i,N)=irrad*...
328 celleff*ns*Asol*...
329 cosinus (i,N);
330 end
331 end
332 total power N(config,N)=sum(power(:,N));
333 for j=1:round(tstop/T)
334 if N==j*round(steps/round(tstop/T))
335 mean power T(config,j)=mean(total power N...
336 (config,[N−round(steps/round(tstop/T))+1:N]));
337 end
338 end
339 if N==steps
340 mean power T(config,round(tstop/T))=mean(total power N...
341 (config,[N−round(steps/round(tstop/T))+1:N]));
342 end
343 end
344 mean power(config)=mean(total power N(config,:));
345 end
346

347 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
348 % 8. PLOTS OF THE OPTIMIZATION ANALYSIS (2DOF)
349 % Plot the results obtained with the analysis with two degrees of ...
freedom
350 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−

34 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

351

352 %3D plot of the power obtained by each face vs alpha & beta
353 figure()
354 for i=faces panels
355 subplot(2,3,i);
356 surf(beta ,alpha,mean power angles(:,:,i));
357 xlabel('\beta [deg]'), ylabel('\alpha [deg]'),...
358 zlabel('Mean power [W]'), shading interp,...
359 light, lighting gouraud, material dull;
360 switch i
361 case 1
362 title('Optimization analysis FACE 1');
363 case 2
364 title('Optimization analysis FACE 2');
365 case 3
366 title('Optimization analysis FACE 3');
367 case 4
368 title('Optimization analysis FACE 4');
369 case 5
370 title('Optimization analysis FACE 5');
371 case 6
372 title('Optimization analysis FACE 6');
373 end
374 end
375 sgtitle('Optimization of the solar cells orientation')
376

377

378 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
379 % 9. PLOTS OF THE OPTIMIZATION ANALYSIS (1DOF)
380 % Plot the results obtained with the analysis with 1 degree of freedom
381 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
382

383 figure()
384 for i=faces panels
385 subplot(2,3,i);
386 plot(beta ,...
387 mean power angles((length(mean power angles)+1)/2,:,i)), hold on;
388 plot(alpha,...
389 mean power angles(:,(length(mean power angles)+1)/2,i)), grid on
390 xlabel('angle [deg]'),...
391 ylabel('Mean power [W]'), shading interp,...
392 light, lighting gouraud, material dull,
393 legend('\alpha=0ˆ\circ', '\beta=0ˆ\circ')

35 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

394 switch i
395 case 1
396 title('Optimization analysis FACE 1');
397 case 2
398 title('Optimization analysis FACE 2');
399 case 3
400 title('Optimization analysis FACE 3');
401 case 4
402 title('Optimization analysis FACE 4');
403 case 5
404 title('Optimization analysis FACE 5');
405 case 6
406 title('Optimization analysis FACE 6');
407 end
408 end
409 sgtitle('Optimization of the solar cells orientation with 1DOF')
410

411 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
412 % 10. PLOTS OF THE OPTIMIZATION ANALYSIS (SYMMETRY)
413 % Plot the results obtained with the analysis with 1 degree of freedom
414 % and keeping the symmetry
415 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
416 figure()
417 plot(beta ,power beta), hold on, grid on
418 plot(alpha,power alpha),
419 xlabel('Angle [deg]'), ylabel('Total mean power [W]'),
420 legend('\alpha=0ˆ\circ', '\beta=0ˆ\circ')
421 title('Optimization analysis keeping the symmetry')
422

423 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
424 % 11. PLOTS OF THE OPTIMIZATION ANALYSIS (Mean power vs T per ...
period)
425 % Plot the mean power per period for each configuration
426 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
427

428 figure()
429 if round(tstop/T)̸=1
430 for i=1:4
431 plot(1:round(tstop/T),mean power T(i,:)), hold on
432 end
433 xlabel('Period (T)')
434 ylabel('Mean power per period [W]')

36 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

435 legend('Standard configuraition', 'Optimum 2DOF configuration',...


436 'Optimum 1DOF configuration','Symmetric configuration')
437 title('Evolution of the mean power per period')
438 else
439 for i=1:4
440 plot(1:steps*T SAMPLE,ones(1,steps*T SAMPLE)* mean power T(i,:)),
441 hold on;
442 end
443 ylabel('Mean power [W]')
444 title('Mean power of each configuration')
445 end
446 grid on
447

448 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
449 % 12. PLOTS OF THE OPTIMIZATION ANALYSIS (Power vs time)
450 % Plot the evolution of the power obtained against time for each
451 % configuration
452 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
453

454 figure()
455 for i=1:4
456 plot(1:T SAMPLE:tstop,total power N(i,:)), hold on
457 end
458 grid on
459 legend('Standard configuraition', 'Optimum 2DOF configuration',...
460 'Optimum 1DOF configuration','Symmetric configuration'),
461 ylabel('Power obtained [W]')
462 xlabel('Time')
463 title('Evolution of power with time')
464

465 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
466 % 13. SAVE RESULTS AND VARIABLES EXPLANATION
467 % Save the simulation results for the post−process
468 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
469 disp('−−−−−−Optimum angles−−−−−−')
470

471 disp('First configuration (2DOF):')


472 disp(['Optimum alpha: ', num2str(opt alpha)])
473 disp(['Optimum beta: ', num2str(opt beta)])
474 disp(' ')
475 disp('Second configuration (1DOF):')
476 disp(['Optimum alpha: ', num2str(alpha 1dof)])

37 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

477 disp(['Optimum beta: ', num2str(beta 1dof)])


478 disp(' ')
479 disp('Third configuration (Symmetry):')
480 disp(['Optimum alpha: ', num2str(alpha symmetry)])
481 disp(['Optimum beta: ', num2str(beta symmetry)])
482 disp(' ')
483 disp('−−−−−Mean power per configuration−−−−−−')
484

485 disp(['First configuration (2DOF): ', num2str(mean power(2)),'W'])


486 disp(['Second configuration (1DOF): ', num2str(mean power(3)),'W'])
487 disp(['Third configuration (Symmetry): ', num2str(mean power(4)),'W'])
488 disp(['Standard configuration: ', num2str(mean power(1)),'W'])
489

490

491 save('optimization.mat','opt alpha','opt beta','max total power',...


492 'alpha 1dof','beta 1dof','alpha symmetry','beta symmetry');

C.7 Script 2.2: Main Simulink simulation

1 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 % TFG Ivan Gonzalvez Tamarit: Solar Panel Orientation
3 % SCRIPT 2.2: Main Simulink simulation
4

5 % Director: Javier Gago


6 % Co−director: David Gonzalez
7 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
8 clc, clear all, warning('off','all')
9

10

11 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
12 % 1. INPUT
13 % User definition of the different solver's inputs
14 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
15 load('InputData.mat');
16 load('ML Regression.mat');
17 load('optimization.mat')
18 load('PowerProfile.mat');
19

20 %Initial Date
21 initialYear=2025; %Year

38 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

22 initialMonth=6; %Month (number 1−12)


23 initialDay=5; %Day (number 1−31)
24 initialHour=3; %Hour (number 00−23)
25 initialMinute=7; %Minute (number 0−59)
26 initialSecond=23; %Second (number 0−59)
27

28 %Keplerian Orbital Elements


29 a= 6791000; %Semi−major axis (>0) [m]
30 e=0.00001; %Eccentricity (≥0)
31 Omega=320; %RAAN (0=<Omega<360) [deg]
32 i=75; %Inclination (0≤i<180)[deg]
33 omega=50; %Argument of periapsis (0≤omega<360) [deg]
34 theta 0=230; %Value of the true anomaly at t=0
35

36 %Simulation time (choose between number of orbits or absolute time)


37 sim Days=0; %InitialDays that will be simulated
38 sim Hours=7; %InitialHours that will be simulated
39 sim Minutes=45; %InitialMinutes that will be simulated
40 sim Seconds=10; %InitialSeconds that will be simulated
41 nT=1; %Number of orbits that will be simulated (zero to ...
ignore)
42

43 % Solar cell orientation


44 faces panels=[1,2,3,4,5,6]; %Faces with solar panels
45 alpha sc=alpha 1dof; %Main options: opt alpha, alpha 1dof, alpha symmetry
46 beta sc=beta 1dof; %Main options: opt beta, beta 1dof, beta symmetry
47

48 %Sizing parameters
49 N batt=1; %Number of battery blocks (3p1s)
50 SF Panel1=1; %Sizing factor for the solar panel 1
51 SF Panel2=1; %Sizing factor for the solar panel 2
52 SF Panel3=1; %Sizing factor for the solar panel 3
53 SF Panel4=1; %Sizing factor for the solar panel 4
54 SF Panel5=1; %Sizing factor for the solar panel 5
55 SF Panel6=1; %Sizing factor for the solar panel 6
56

57 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
58 % 2. Previous calculations
59 % Compute some previous calculations for the simulation
60 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
61

62 %Orientation of the Solar Cells for the VR


63 [SolCellRot1, SolCellRot2, SolCellRot3, SolCellRot4, SolCellRot5,...

39 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

64 SolCellRot6, SolCellTrans1, SolCellTrans2, SolCellTrans3,...


65 SolCellTrans4, SolCellTrans5, SolCellTrans6, scale sc]=...
66 SolarCellsVR(l, beta sc, alpha sc, faces panels);
67

68 %Initial date of the simulation


69 initial date=datetime(initialYear,initialMonth,...
70 initialDay,initialHour,initialMinute,initialSecond); %Initial date
71 initialJulian=juliandate(initial date); %Initial Julian Date
72 epochJulian = initialJulian; %Epoch of ECI frame
73 T=sqrt(4*piˆ2/mu*aˆ3); %Orbital period
74

75 %Duration of the simulation


76 if nT==0
77 tstop=sim initialSeconds+60*sim initialMinutes+...
78 60*60*sim initialHours+60*60*24*sim initialDays;
79 else
80 tstop=nT*T;
81 end
82

83 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
84 % 3. Simulation of the mission
85 % Solve the state of the battery at each instant with Simulink
86 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
87

88 %Run the simulation


89 out=sim('SIMULADOR 2021.slx');
90

91 %Load results
92 t=out.t;
93 Vbat=out.Vbat;
94 SOCbat=out.SOCbat;
95 solar power N=out.solar power;
96 power discharge=out.P discharge;
97

98

99 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
100 % 4. PLOT BATTERY DETAILS
101 % Plot the state of the battery computed during the simulation
102 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
103 figure()
104 subplot(1,3,1)
105 plot(linspace(1,max(t)*2/3,length(t)*2/3)/T,...

40 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

106 Vbat(1:length(linspace(1,max(t)*2/3,length(t)*2/3)/T))), grid on


107 xlabel('Period'),ylabel('Battery voltage [V]'),title('Battery Voltage')
108

109 subplot(1,3,2)
110 plot(linspace(1,max(t)*2/3,length(t)*2/3)/T,...
111 SOCbat(1:length(linspace(1,max(t)*2/3,length(t)*2/3)/T))), grid on
112 xlabel('Period'),ylabel('Battery state of charge [%]'),...
113 title('Battery State of Charge')
114

115 subplot(1,3,3)
116 plot(linspace(1,max(t)*2/3,length(t)*2/3)/T,...
117 solar power N(1:length(linspace(1,max(t)*2/3,...
118 length(t)*2/3)/T))), grid on, hold on
119 plot(linspace(1,max(t)*2/3,length(t)*2/3)/T...
120 ,power discharge(1:length(linspace(1,max(t)*2/3,...
121 length(t)*2/3)/T))), grid on
122 xlabel('Period'),ylabel('Power [W]'),...
123 title('Power obtained vs required'),...
124 legend('Power absorbed','Power required')
125

126 sgtitle('Power subsystem simulation results')


127 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
128 % 5. SAVE RESULTS
129 % Save the simulation results for the post−process
130 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
131

132 save('results.mat','solar power N','t','Vbat','SOCbat');

C.8 Function: Location and orientation of solar cells


in the VR

1 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 % TFG Ivan Gonzalvez Tamarit: Solar Panel Orientation
3 % FUNCTION: Location and orientation of solar cells in ...
the VR
4

5 % Director: Javier Gago


6 % Co−director: David Gonzalez
7 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−

41 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

9 function [SolCellRot1, SolCellRot2, SolCellRot3, SolCellRot4, ...


10 SolCellRot5,SolCellRot6, SolCellTrans1, SolCellTrans2,...
11 SolCellTrans3,SolCellTrans4, SolCellTrans5, SolCellTrans6, ...
scale sc]...
12 =SolarCellsVR(l, beta sc, alpha sc, faces panels)
13

14 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
15 % 1. FIRST TRANSLATION + ROTATION
16 % Transation and rotation of the soalr panels to the required ...
faces and
17 % with the required orientation
18 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
19

20

21 for n=1:6
22 switch n
23 case 1
24 theta=90;
25 R11=[cosd(−theta−beta sc(1)), −sind(−theta−beta sc(1)), 0;
26 sind(−theta−beta sc(1)), cosd(−theta−beta sc(1)), 0;
27 0,0,1];
28 R22=[cosd(−alpha sc(1)) 0 sind(−alpha sc(1));
29 0 1 0;
30 −sind(−alpha sc(1)) 0 cosd(−alpha sc(1))];
31 R=R22*R11;
32 SolCellRot1=vrrotmat2vec(R);
33 SolCellTrans1=[l/2,0,0]+[l/2*(abs(sind(alpha sc(1)/2))+...
34 abs(sind(beta sc(1)/2))),0,0]*1.1;
35

36 case 2
37 theta=90;
38 R11=[cosd(theta+beta sc(2)), −sind(theta+beta sc(2)), 0;
39 sind(theta+beta sc(2)), cosd(theta+beta sc(2)), 0;
40 0,0,1];
41 R22=[cosd(−alpha sc(2)) 0 sind(−alpha sc(2));
42 0 1 0;
43 −sind(−alpha sc(2)) 0 cosd(−alpha sc(2))];
44 R=R22*R11;
45 SolCellRot2=vrrotmat2vec(R);
46 SolCellTrans2=[−l/2,0,0]+[−l/2*(abs(sind(alpha sc(2)/2))+...
47 abs(sind(beta sc(2)/2))),0,0]*1.1;
48

42 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

49 case 3
50 theta=90;
51 R11=[1, 0, 0;
52 0, cosd(theta+beta sc(3)), −sind(theta+beta sc(3));
53 0, sind(theta+beta sc(3)), cosd(theta+beta sc(3))];
54 R22=[cosd(−alpha sc(3)) 0 sind(−alpha sc(3));
55 0 1 0;
56 −sind(−alpha sc(3)) 0 cosd(−alpha sc(3))];
57 R=R22*R11;
58 SolCellRot3=vrrotmat2vec(R);
59 SolCellTrans3=[0,0,l/2]+[0,0,l/2*(abs(sind(alpha sc(3)/2))+...
60 abs(sind(beta sc(3)/2)))]*1.1;
61

62 case 4
63 theta=90;
64 R11=[1, 0, 0;
65 0, cosd(−theta−beta sc(4)), −sind(−theta−beta sc(4));
66 0, sind(−theta−beta sc(4)), cosd(−theta−beta sc(4))];
67 R22=[cosd(−alpha sc(4)) 0 sind(−alpha sc(4));
68 0 1 0;
69 −sind(−alpha sc(4)) 0 cosd(−alpha sc(4))];
70 R=R22*R11;
71 SolCellRot4=vrrotmat2vec(R);
72 SolCellTrans4=[0,0,−l/2]+[0,0,−l/2*(abs(sind(alpha sc(4)/2))+...
73 abs(sind(beta sc(4)/2)))]*1.1;
74

75 case 5
76 theta=180;
77 R11=[1, 0, 0;
78 0, cosd(theta+alpha sc(5)), −sind(theta+alpha sc(5));
79 0, sind(theta+alpha sc(5)), cosd(theta+alpha sc(5))];
80 R22=[cosd(beta sc(5)), −sind(beta sc(5)), 0;
81 sind(beta sc(5)), cosd(beta sc(5)), 0;
82 0,0,1];
83 R=R22*R11;
84 SolCellRot5=vrrotmat2vec(R);
85 SolCellTrans5=[0,−l/2,0]+[0,−l/2*(abs(sind(alpha sc(5)/2))+...
86 abs(sind(beta sc(5)/2))),0]*1.1;
87

88 case 6
89 theta=0;
90 R11=[1, 0, 0;
91 0, cosd(theta+alpha sc(6)), −sind(theta+alpha sc(6));
92 0, sind(theta+alpha sc(6)), cosd(theta+alpha sc(6))];

43 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

93 R22=[cosd(−beta sc(6)), −sind(−beta sc(6)), 0;


94 sind(−beta sc(6)), cosd(−beta sc(6)), 0;
95 0,0,1];
96 R=R22*R11;
97 SolCellRot6=vrrotmat2vec(R);
98 SolCellTrans6=[0, l/2, ...
0]+[0,l/2*(abs(sind(alpha sc(6)/2))+...
99 abs(sind(beta sc(6)/2))),0]*1.1;
100 end
101 end
102

103 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
104 % 2. PUT SOLAR PANELS IN THE SELECTED FACES
105 % Delete the solar panels of the faces where no solar panels are ...
included
106 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
107

108 for i=1:6


109 found=any(faces panels==i);
110 if found
111 scale sc(i)=0.75;
112 else
113 scale sc(i)=0;
114 end
115 end
116 scale sc=scale sc';
117

118 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
119 % 3. SECOND TRANSLATION
120 % Translation to situate the panel in the extremes of the faces in the
121 % 1DOF and symmetric configurations
122 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
123

124 for i=1:6


125 switch i
126 case 1
127 if alpha sc(i)==0 && beta sc(i)>0
128 SolCellTrans1=SolCellTrans1−[0,l/2,0]*(1−cosd(beta sc(i)));
129 elseif alpha sc(i)==0 && beta sc(i)<0
130 SolCellTrans1=SolCellTrans1+[0,l/2,0]*(1−cosd(beta sc(i)));
131 end
132 if beta sc(i)==0 && alpha sc(i)>0

44 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

133 SolCellTrans1=SolCellTrans1+[0,0,l/2]*(1−cosd(alpha sc(i)));


134 elseif beta sc(i)==0 && alpha sc(i)<0
135 SolCellTrans1=SolCellTrans1−[0,0,l/2]*(1−cosd(alpha sc(i)));
136 end
137

138

139 case 2
140 if alpha sc(i)==0 && beta sc(i)>0
141 SolCellTrans2=SolCellTrans2−[0,l/2,0]*(1−cosd(beta sc(i)));
142 elseif alpha sc(i)==0 && beta sc(i)<0
143 SolCellTrans2=SolCellTrans2+[0,l/2,0]*(1−cosd(beta sc(i)));
144 end
145 if beta sc(i)==0 && alpha sc(i)>0
146 SolCellTrans2=SolCellTrans2−[0,0,l/2]*(1−cosd(alpha sc(i)));
147 elseif beta sc(i)==0 && alpha sc(i)<0
148 SolCellTrans2=SolCellTrans2+[0,0,l/2]*(1−cosd(alpha sc(i)));
149 end
150

151 case 3
152 if alpha sc(i)==0 && beta sc(i)>0
153 SolCellTrans3=SolCellTrans3−[0,l/2,0]*(1−cosd(beta sc(i)));
154 elseif alpha sc(i)==0 && beta sc(i)<0
155 SolCellTrans3=SolCellTrans3+[0,l/2,0]*(1−cosd(beta sc(i)));
156 end
157 if beta sc(i)==0 && alpha sc(i)>0
158 SolCellTrans3=SolCellTrans3−[l/2,0,0]*(1−cosd(alpha sc(i)));
159 elseif beta sc(i)==0 && alpha sc(i)<0
160 SolCellTrans3=SolCellTrans3+[l/2,0,0]*(1−cosd(alpha sc(i)));
161 end
162

163

164 case 4
165 if alpha sc(i)==0 && beta sc(i)>0
166 SolCellTrans4=SolCellTrans4−[0,l/2,0]*(1−cosd(beta sc(i)));
167 elseif alpha sc(i)==0 && beta sc(i)<0
168 SolCellTrans4=SolCellTrans4+[0,l/2,0]*(1−cosd(beta sc(i)));
169 end
170 if beta sc(i)==0 && alpha sc(i)>0
171 SolCellTrans4=SolCellTrans4+[l/2,0,0]*(1−cosd(alpha sc(i)));
172 elseif beta sc(i)==0 && alpha sc(i)<0
173 SolCellTrans4=SolCellTrans4−[l/2,0,0]*(1−cosd(alpha sc(i)));
174 end
175

176

45 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

177 case 5
178 if alpha sc(i)==0 && beta sc(i)>0
179 SolCellTrans5=SolCellTrans5+[l/2,0,0]*(1−cosd(beta sc(i)));
180 elseif alpha sc(i)==0 && beta sc(i)<0
181 SolCellTrans5=SolCellTrans5−[l/2,0,0]*(1−cosd(beta sc(i)));
182 end
183 if beta sc(i)==0 && alpha sc(i)>0
184 SolCellTrans5=SolCellTrans5−[0,0,l/2]*(1−cosd(alpha sc(i)));
185 elseif beta sc(i)==0 && alpha sc(i)<0
186 SolCellTrans5=SolCellTrans5+[0,0,l/2]*(1−cosd(alpha sc(i)));
187 end
188

189

190 case 6
191 if alpha sc(i)==0 && beta sc(i)>0
192 SolCellTrans6=SolCellTrans6+[l/2,0,0]*(1−cosd(beta sc(i)));
193 elseif alpha sc(i)==0 && beta sc(i)<0
194 SolCellTrans6=SolCellTrans6−[l/2,0,0]*(1−cosd(beta sc(i)));
195 end
196 if beta sc(i)==0 && alpha sc(i)>0
197 SolCellTrans6=SolCellTrans6+[0,0,l/2]*(1−cosd(alpha sc(i)));
198 elseif beta sc(i)==0 && alpha sc(i)<0
199 SolCellTrans6=SolCellTrans6−[0,0,l/2]*(1−cosd(alpha sc(i)));
200 end
201 end
202 end

C.9 Extra Script: Matlab simulation of the standard


configuration

1 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 % TFG Ivan Gonzalvez Tamarit: Solar Panel Orientation
3 % EXTRA SCRIPT: Matlab simulation of the standard configuration
4

5 % Director: Javier Gago


6 % Co−director: David Gonzalez
7 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
8 clc, clear all, close all
9

10

46 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

11 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
12 % 1. INPUT
13 % User definition of the different solver's inputs
14 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
15 load('InputData.mat');
16 load('ML Regression.mat');
17 load('optimization.mat')
18 load('PowerProfile.mat');
19

20

21 %Initial Date
22 initialYear=2025; %Year
23 initialMonth=6; %Month (number 1−12)
24 initialDay=5; %Day (number 1−31)
25 initialHour=3; %Hour (number 00−23)
26 initialMinute=7; %Minute (number 0−59)
27 initialSecond=23; %Second (number 0−59)
28

29 %Keplerian Orbital Elements


30 a= 6791000; %Semi−major axis (>0) [m]
31 e=0.00001; %Eccentricity (≥0)
32 Omega=320; %RAAN (0=<Omega<360) [deg]
33 i=75; %Inclination (0≤i<180)[deg]
34 omega=50; %Argument of periapsis (0≤omega<360) [deg]
35 theta 0=230; %Value of the true anomaly at t=0
36

37 %Simulation time (choose between number of orbits or absolute time)


38 sim initialDays=0; %initialDays that will be simulated
39 sim initialHours=7; %initialHours that will be simulated
40 sim initialMinutes=45; %initialMinutes that will be simulated
41 sim initialSeconds=10; %initialSeconds that will be simulated
42 nT=1; %Number of orbits that will be simulated (zero to ...
ignore)
43

44 % Solar cell orientation


45 alpha sc=opt alpha;
46 beta sc=opt beta;
47 faces panels=[1,2,3,4,5,6]; %Faces with solar panels
48

49

50 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
51 % 2. Previous calculations

47 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

52 % Compute some previous calculations for the simulation


53 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
54

55 %Sizing parameters
56 N batt=1; %Number of battery blocks (3p1s)
57 SF Panel1=1; %Sizing factor for the solar panel 1
58 SF Panel2=1; %Sizing factor for the solar panel 2
59 SF Panel3=1; %Sizing factor for the solar panel 3
60 SF Panel4=1; %Sizing factor for the solar panel 4
61 SF Panel5=1; %Sizing factor for the solar panel 5
62 SF Panel6=1; %Sizing factor for the solar panel 6
63

64 %Orientation of the Solar Cells for the VR


65 [SolCellRot1, SolCellRot2, SolCellRot3, SolCellRot4, SolCellRot5,...
66 SolCellRot6, SolCellTrans1, SolCellTrans2, SolCellTrans3,...
67 SolCellTrans4, SolCellTrans5, SolCellTrans6, scale sc]=...
68 SolarCellsVR(l, beta sc, alpha sc, faces panels);
69

70 %Initial date of the simulation


71 initial date=datetime(initialYear,initialMonth,...
72 initialDay,initialHour,initialMinute,initialSecond); %Initial date
73 initialJulian=juliandate(initial date); %Initial Julian Date
74 epochJulian = initialJulian; %Epoch of ECI frame
75 T=sqrt(4*piˆ2/mu*aˆ3); %Orbital period
76

77 %Duration of the simulation


78 if nT==0
79 tstop=sim initialSeconds+60*sim initialMinutes+...
80 60*60*sim initialHours+60*60*24*sim initialDays;
81 else
82 tstop=nT*T;
83 end
84

85 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
86 % 3. Simulation of the attitude
87 % Solve the attitude at each instant with simulink
88 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
89

90 %Run the simulation


91 out=sim('SIMULADOR 2021.slx');
92

93 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−

48 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

94 % 4. TRUE ANOMALY
95 % Solve the true anomaly at each instant of time
96 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
97

98 %Steps of the simulation


99 steps=length(out.t);
100

101 %Compute t(0) when theta(0)!=0


102 E=2*atan(sqrt((1−e)/(1+e))*tand(theta 0/2));
103 M=E−e*sin(E);
104 n=sqrt(mu/aˆ3);
105 t0=M/n;
106

107 v time=out.t;
108 theta eval=zeros(1,steps);
109 E=0;
110

111 theta eval(1)=theta 0*pi/180;


112 for N=2:steps
113 t=v time(N)+t0;
114 error=1;
115 M=n*t;
116 while(error>tol)
117 E p=E−(E−e*sin(E)−M)/(1−e*cos(E));
118 error=abs(E p−E);
119 E=E p;
120 end
121 theta eval(N)=2*atan(sqrt((1+e)/(1−e))*tan(E/2));
122 if (theta eval(N)−theta eval(N−1))<0
123 theta eval(N)=theta eval(N)+2*pi;
124 end
125 if (theta eval(N)>2*pi)
126 theta eval(N)=theta eval(N)−2*pi;
127 end
128 end
129

130 theta eval=theta eval*180/pi;


131

132 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
133 % 5. SATELLITE IN UMBRA?
134 % Compute when the satellite is in umbra
135 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
136

49 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

137 for N=1:steps


138

139 theta=theta eval(N);


140

141 %Compute date


142 initialSecond N=v time(N);
143 instant(N)=initial date+seconds(initialSecond N);
144

145 %Compute Sun vector (s vec)


146 JD=juliandate(instant(N)); %Julian date
147 n=JD−2451545; %Reduced Julian date
148

149 L=280.459+0.98564736*n; %Mean longitude of ...


the Sun
150 M=357.529+0.98560023*n; %Mean anomaly of the Sun
151

152 epsilon=23.439−3.56*10ˆ(−7)*n; %Ecliptic obliquity


153 lambda=L+1.915*sind(M)+0.02*sind(2*M); %Ecliptic longitude
154

155 %Sun vector in ECI frame


156 unit s vec ECI(1,N)=cosd(lambda);
157 unit s vec ECI(2,N)=cosd(epsilon)*sind(lambda);
158 unit s vec ECI(3,N)=sind(epsilon)*sind(lambda);
159

160 %Distance Sun−Earth


161 d es=(1.00014 − 0.01671*cosd(M)−...
162 0.00014*cosd(2*M))*149600e3*1000; %Distance Earth−Sun
163

164 s vec ECI(N,:)=d es * unit s vec ECI(:,N); %Vector Earth−Sun ECI


165

166 %Compute position and velocity of the satellite in PQW


167 p=a*(1−eˆ2);
168 h=sqrt(p*mu);
169

170 vector r PQW=hˆ2/mu*(1/(1+e*cosd(theta)))*...


171 [cosd(theta);sind(theta);0]; %Position (PQW frame)
172

173 vector v PQW=mu/h*[−sind(theta);...


174 e+cosd(theta);0]; %Velocity (PQW frame)
175

176

177 %Matrix change base to ECI


178 R1=[cosd(Omega), −sind(Omega), 0;
179 sind(Omega), cosd(Omega), 0;

50 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

180 0 0 1];
181 R2=[1,0,0;
182 0, cosd(i), −sind(i);
183 0, sind(i), cosd(i)];
184 R3=[cosd(omega), −sind(omega), 0;
185 sind(omega), cosd(omega), 0;
186 0, 0, 1];
187

188

189 %Position in ECI


190 r=norm(vector r PQW);
191 vector X ECI(:,N)=R1*R2*R3*...
192 [r*cosd(theta); r*sind(theta);0]; %Position of the satellite ...
in ECI
193

194 %Velocity in ECI


195 vector V ECI=R1*R2*R3*mu/h*...
196 [−sind(theta);e+cosd(theta);0]; %Velocity of the satellite ...
in ECI
197

198

199 %Compute if is in umbra or not (see "memoria TFG Ivan Gonzalvez")


200 d ue=(d es *Re)/(Rs−Re);
201 alpha u=asind(Re/d ue);
202 umbraVertexECI=−unit s vec ECI(:,N)* d ue;
203 d usECI=vector X ECI(:,N)−umbraVertexECI;
204 d us=norm(d usECI);
205 cosTheta(N)=(rˆ2−d ueˆ2−d usˆ2)/(−2* d ue * d us);
206 theta u(N)=acosd(cosTheta(N));
207

208 if (r<d ue && alpha u>abs(theta u(N))...


209 && s vec ECI(N,:)* vector X ECI(:,N)<0)
210 umbra(N)=0; %Is not illuminated
211 else
212 umbra(N)=1; %Is illuminated
213 end
214 end
215

216 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
217 % 6. PLOT OF THE UMBRA ANALYSIS
218 % Plot when the satellite is in illuminated (1) or in umbra (0)
219 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
220

51 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

221 figure();
222 plot(v time,umbra), hold on;
223

224 plot(v time,reshape(out.umbra condition,[1,length(v time)])),...


225 xlabel('Time'), ylabel('0−−> Umbra, 1−−> Illuminated'),...
226 title('Umbra analysis'), legend('Matlab','Simulink');
227

228 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
229 % 7. SUN INCIDENCE IN EACH FACE
230 % Compute how does the Sun incide in each face of the cubesat
231 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
232

233 for N=1:steps


234 R ECI BODY(:,:,N)=out.DCM eci2body(:,:,N); %DCM ECI−>BODY
235 R BODY ECI(:,:,N)=R ECI BODY(:,:,N)'; %DCM BODY−>ECI
236

237 %Unitary vectors normal to each face in ECI


238 body ECI X(:,N,1)=R BODY ECI(:,:,N)*[1;0;0];
239 body ECI Y(:,N,2)=R BODY ECI(:,:,N)*[0;1;0];
240 body ECI Z(:,N,3)=R BODY ECI(:,:,N)*[0;0;1];
241 end
242

243 %Sun incidence for each face (6 faces)


244 %Face 1 −−> X direction
245 %Face 2 −−> −X direction
246 %Faces 3 −−> Y direction
247 %Faces 4 −−> −Y direction
248 %Faces 5 −−> Z direction
249 %Faces 6 −−> −Z direction
250

251 for N=1:steps


252 if umbra(N)==0
253 power(i,N)=0; %If in umbra, the power absorved is zero
254 else
255 body ECI(:,N,1)=R BODY ECI(:,:,N)*[1;0;0];
256 body ECI(:,N,3)=R BODY ECI(:,:,N)*[0;1;0];
257 body ECI(:,N,5)=R BODY ECI(:,:,N)*[0;0;1];
258

259 %Angle between each face and the Sun vector


260 for i=1:2:5
261 cosinus=dot(unit s vec ECI(:,N),...
262 body ECI(:,N,i)); %Cosinus face−Sun vector
263 if (cosinus>0)

52 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

264 cosinus (i,N) = cosinus;


265 cosinus (i+1,N) = 0;
266 else
267 cosinus (i,N) = 0;
268 cosinus (i+1,N) = abs(cosinus);
269 end
270 end
271

272 %Power obtained by each face


273 power([1:6],N)=0;
274 for i=faces panels
275 power(i,N)=irrad*...
276 celleff*ns*Asol*...
277 cosinus (i,N); %Power obtained by the face "i"
278 end
279 end
280 solar power N(N)=sum(power(:,N)); %Total power obtained at each step
281 end
282

283 %Total power obtained by each face


284 for i=faces panels
285 power i(i)=sum(power(i,:));
286 end
287

288 %Total power obtained


289 total sun power=sum(solar power N);
290

291 %Power required for the attitude control


292 attitude current=out.attitude current;
293

294 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
295 % 8. PLOT OF THE SUN INCIDENCE IN EACH FACE
296 %Plot of the the cosinus of the angle Sun−face when the face is ...
illuminated
297 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
298

299 figure()
300 for i=1:6
301 plot(v time,power(i,:)), hold on;
302 end
303 legend('X front','X back','Y front','Y back','Z front','Z back'),...
304 xlabel('Time'), ylabel('Power per face');
305

53 Final degree project


Universitat politècnica de Catalunya- Barcelona Tech- UPC

306 figure()
307 plot(v time,solar power N), hold on;
308 xlabel('Time'), ylabel('Power absorved');
309

310 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
311 % 9. SAVE RESULTS
312 % Save the simulation results for the post−process
313 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
314 save('results.mat','solar power N','theta eval','v time',...
315 'attitude current','vector X ECI','Re','instant');

54 Final degree project

You might also like