Professional Documents
Culture Documents
Annexes
Annexes
Annexes
Barcelona
Tech - UPC
Document: Annexes
Author:
Spring 2022
Universitat politècnica de Catalunya- Barcelona Tech- UPC
1
Universitat politècnica de Catalunya- Barcelona Tech- UPC
3
Appendix A
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.
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
5. Repeat the step 2. This time it should not appear any error, and a new window will
be opend.
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
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
Matlab Scripts
1 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 % TFG Ivan Gonzalvez Tamarit: Solar Panel Orientation
3 % SCRIPT 0.1: Machine learning−GetData
4
10 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
11 % 1. INPUTS
12 % User definition of the different solver's inputs
13 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
14
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
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
1 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 % TFG Ivan Gonzalvez Tamarit: Solar Panel Orientation
3 % SCRIPT 0.2: Machine learning−Regularization
4
10 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
11 % 1. INPUTS
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
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
94
95 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
96 % 5. PLOT MSE and VARIANCE
97 % Plot the MSE with its mean and its variance. Also a smoothed curve
98 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
99
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
177
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
202 X plot(:,:,1)=meshgrid(ones(size(x1)));
203 X plot(:,:,2)=meshgrid(x1);
204 X plot(:,:,3)=meshgrid(x2)';
205
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
1 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 % TFG Ivan Gonzalvez Tamarit: Solar Panel Orientation
3 % SCRIPT 0.3: Machine learning−PostProcess
4
11 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
12 % 1. INPUT AND LOAD DATA
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
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
55 DATA test=DATA(p(aux2),:);
56
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
85 Yfit Own=Xtest*trainedOwn;
86
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
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');
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')
1 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 % TFG Ivan Gonzalvez Tamarit: Solar Panel Orientation
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]
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
78 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
79 % 4. BATTERY CHARACTERISTICS
80 % User definition of the different battery inputs
81 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
82
88 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
89 % 5. NUMERICAL VARIABLES
90 % User definition of the different numerical inputs
91 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
92
96 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
97 % 6. SAVE
98 % Save the input data
99 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
100 save('InputData')
1 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 % TFG Ivan Gonzalvez Tamarit: Solar Panel Orientation
3 % SCRIPT 1.2: Mission Profile Generator
4
10 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
11 % 1. INPUTS
12 % User definition of the different inputs
13 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
14
15 load("InputData");
16
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
58 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
59 % 3. DATA GENERATOR
60 % Generate arrays with the power information
61 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
62
78 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
79 % 4. SAVE DATA
80 % Save the data generated
81 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
82 save('PowerProfile','power constant','power attitude','power link');
1 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 % TFG Ivan Gonzalvez Tamarit: Solar Panel Orientation
3 % SCRIPT 2.1: Cell orientation optimization
4
10 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
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
43 %Optimization variables
44 alpha=[−90:5:90];
45 beta =[−90:5:90];
46
50 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
51 % 2. PREVIOUS CALCULATIONS
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
95 %Set the power consumption to zero to make sure the simulation finishes
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
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
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
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
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)...
231 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
232 % 6. POSTPROCESS FOR SYMMETRY ANALYSIS
233 % Compute the most opotimum angles mantaining the symmetry of the
234 % CubeSat
235 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
236
265
266 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
267 % 7. COMPUTE THE MEAN POWER PER ORBIT
268 % Compute the mean power per orbit for each type of configuration
269 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
270
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
347 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
348 % 8. PLOTS OF THE OPTIMIZATION ANALYSIS (2DOF)
349 % Plot the results obtained with the analysis with two degrees of ...
freedom
350 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
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')
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]')
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
490
1 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 % TFG Ivan Gonzalvez Tamarit: Solar Panel Orientation
3 % SCRIPT 2.2: Main Simulink simulation
4
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
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
83 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
84 % 3. Simulation of the mission
85 % Solve the state of the battery at each instant with Simulink
86 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
87
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,...
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
1 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 % TFG Ivan Gonzalvez Tamarit: Solar Panel Orientation
3 % FUNCTION: Location and orientation of solar cells in ...
the VR
4
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
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))];
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
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
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
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
1 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 % TFG Ivan Gonzalvez Tamarit: Solar Panel Orientation
3 % EXTRA SCRIPT: Matlab simulation of the standard configuration
4
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
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
49
50 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
51 % 2. Previous calculations
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
85 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
86 % 3. Simulation of the attitude
87 % Solve the attitude at each instant with simulink
88 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
89
93 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
94 % 4. TRUE ANOMALY
95 % Solve the true anomaly at each instant of time
96 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
97
107 v time=out.t;
108 theta eval=zeros(1,steps);
109 E=0;
110
132 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
133 % 5. SATELLITE IN UMBRA?
134 % Compute when the satellite is in umbra
135 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
136
176
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
198
216 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
217 % 6. PLOT OF THE UMBRA ANALYSIS
218 % Plot when the satellite is in illuminated (1) or in umbra (0)
219 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
220
221 figure();
222 plot(v time,umbra), hold on;
223
228 %% ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
229 % 7. SUN INCIDENCE IN EACH FACE
230 % Compute how does the Sun incide in each face of the cubesat
231 %−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
232
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
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');