diff --git a/commonFunctions/miscellaneous/matlab_graphics.m b/commonFunctions/miscellaneous/matlab_graphics.m index 755f255b56fac76f1eb4d53266824774f5e71293..82492f58b134e3a2a6c9aa0d8f25c482259b886d 100644 --- a/commonFunctions/miscellaneous/matlab_graphics.m +++ b/commonFunctions/miscellaneous/matlab_graphics.m @@ -3,34 +3,34 @@ Set graphical values for better looking plots %} %% interpreter: - set(0, 'defaultTextInterpreter', 'latex') set(0, 'defaultAxesTickLabelInterpreter', 'latex') set(0, 'defaultLegendInterpreter', 'latex') %% figure properties: - %colors set(0, 'defaultFigureColormap',turbo(256)); set(0, 'defaultFigureColor', [1; 1; 1]); % grid -set(0,'defaultAxesXGrid','on') -set(0,'defaultAxesYGrid','on') +set(0, 'defaultAxesXGrid','on') +set(0, 'defaultAxesYGrid','on') +% position and scale +screenSize = get(0, 'ScreenSize'); +set(0, 'DefaultFigurePosition', [0.3*screenSize(3), 0.25*screenSize(4), 0.4*screenSize(3), 5/6*0.4*screenSize(3)]); +% set(0, 'DefaultFigurePosition', [100,100,600,400]); %% surfaces: % transparency set(0, 'defaultSurfaceEdgeAlpha', 0.3); %% lines: - defaultLineWidth = 1.5; - % plots set(0,'defaultLineLineWidth', defaultLineWidth); % stairs set(0,'defaultStairLineWidth', defaultLineWidth); % needs a different command for no reason apparently % ylines -% set(0,'defaultYLineLineWidth', defaultLineWidth) +% set(0, 'defaultYLineLineWidth', defaultLineWidth) %% legend: set(0, 'defaultLegendLocation','best'); @@ -47,3 +47,4 @@ set(0, 'defaultAxesFontName', 'Palatino Linotype', 'defaultTextFontName', 'Palat set(0, 'defaultAxesColor', 'none'); % fontSize set(0,'defaultAxesFontSize',16); + diff --git a/simulator/mainSimulator.m b/simulator/mainSimulator.m index fa0bbb6e147e7de5883f92a1dad088d313e9101b..429229d3911e5aee83c82c52fc68a50841a6312c 100644 --- a/simulator/mainSimulator.m +++ b/simulator/mainSimulator.m @@ -25,7 +25,7 @@ REVISIONS: - 5 07/02/2025, update, Stefano Belletti, GNC IPT Samuel Flore, GNC IPT Added new sensor classes and noises, added new noise - analyzer, fix terminal print, fix plots. + analyzer, fix plots. Copyright © 2022, Skyward Experimental Rocketry, SCS department All rights reserved @@ -116,3 +116,6 @@ if settings.flagExportCSV % this is set in configFlags export_HILdataADA export_HILdataNAS end + +% Reset to default plot +reset(groot); diff --git a/simulator/report_images/report_plots.m b/simulator/report_images/report_plots.m index 43f8e0008a482a2a5661aaa452f7f0a9a5932740..d1037042cf6a7e2b8cf694e5492bdae5b325bf5b 100644 --- a/simulator/report_images/report_plots.m +++ b/simulator/report_images/report_plots.m @@ -87,8 +87,8 @@ v_ned = quatrotate(quatconj(structIn.Y(:, 10:13)), structIn.Y(:, 4:6)); if ~settings.electronics contSettings = structIn.contSettings; % because the trajectory are chosen during the simulation, not a priori if not(settings.scenario == "descent") - plot(contSettings.reference.Z, contSettings.reference.Vz(:,1),'DisplayName','Reference 0%') - plot(contSettings.reference.Z, contSettings.reference.Vz(:,2),'DisplayName','Reference 100%') + plot(contSettings.reference.Z, contSettings.reference.Vz(:,1),'DisplayName','Reference 0$\%$') + plot(contSettings.reference.Z, contSettings.reference.Vz(:,2),'DisplayName','Reference 100$\%$') end end plot( -structIn.Y(:, 3), -v_ned(:,3),'DisplayName','Trajectory') @@ -98,7 +98,7 @@ exportStandardizedFigure(figures.ABK_wrt_referenceTrajectory, '[AVN][GNC]ABK_wrt yyaxis right plot( -structIn.Y(:, 3), structIn.Y(:, 14)./settings.servo.maxAngle*100,'DisplayName','ABK') xlabel('Altitude [m]') -ylabel('ABK extension [%]') +ylabel('ABK extension [\%]') set(gca,'YColor','#FDAF00') legend exportStandardizedFigure(figures.ABK_wrt_referenceTrajectory, '[AVN][GNC]ABK_wrt_references',0.6, 'forcedMarkers',10); diff --git a/simulator/src/sensor_plots.m b/simulator/src/sensor_plots.m index 1a008d0c32cd419958cc04cb1ad4c18f9d4868d6..a8d577421e7e54201d5ecabdab5d0d405d7e1b81 100644 --- a/simulator/src/sensor_plots.m +++ b/simulator/src/sensor_plots.m @@ -148,6 +148,8 @@ plot(simOutput.sensors.barometer_sens{1, 3}.time,simOutput.sensors.barometer_sen plot(simOutput.t, P_real, 'g', 'DisplayName', 'Real pressure'); legend title('Barometer measurements') +xlabel("Time [s]"), ylabel("Pressure [Pa]") +drawnow %% Pitot measurements figure("Name", "Pitot measurements") @@ -156,6 +158,8 @@ hold on; plot(simOutput.t, P_real, 'DisplayName', "Real pressure"); legend() title('Pitot static pressure') +xlabel("Time [s]"), ylabel("Pressure [Pa]") +drawnow %% mea pressure vs true pressure if length(simOutput.sensors.mea.time) > 1 @@ -171,6 +175,7 @@ if length(simOutput.sensors.mea.time) > 1 plot(simOutput.t, P_cc_real, 'DisplayName', 'Real cc pressure'); legend() end +drawnow return @@ -201,6 +206,7 @@ hold on; semilogy(f_2,x_2) % subplot(3,1,3) semilogy(f_3,x_3) +drawnow end diff --git a/simulator/src/std_plots.m b/simulator/src/std_plots.m index 833cc4306c66dee8614b25d983236bd54aec5b5a..7b2f2b54cd3fd86a657d4c7814f0d3e8ef508ea7 100644 --- a/simulator/src/std_plots.m +++ b/simulator/src/std_plots.m @@ -67,8 +67,10 @@ if contains(mission.name,'2023') || contains(mission.name,'2024') || contains(mi end end +drawnow + %% ada -figures.ada = figure('Position',[100,100,600,400]); +figures.ada = figure; plot( simOutput.sensors.ada.time, simOutput.sensors.ada.xv(:,1),'DisplayName','$ADA_{z}$') hold on plot( simOutput.sensors.ada.time, simOutput.sensors.ada.xv(:,2),'DisplayName','$ADA_{vz}$') @@ -77,15 +79,17 @@ plot( simOutput.t, -v_ned(:,3),'DisplayName','True Vz') legend; title('ADA vs trajectory') xlabel("Time [s]"), ylabel("Altitude AGL \& Velocity [m, m/s]") +drawnow -figure('Position',[100,100,600,400]) +figure hold on plot( simOutput.sensors.ada.time, simOutput.sensors.ada.xp(:,2),'DisplayName','ADA dp') title('ADA pressure derivative') xlabel("Time [s]") +drawnow %% reference -figure('Position',[100,100,600,400]) +figure yyaxis left hold on if ~settings.electronics @@ -100,12 +104,12 @@ plot( -simOutput.sensors.nas.states(:,3)-environment.z0, -simOutput.sensors.nas % plot( structIn.ADA(:,4), structIn.ADA(:,5),'b','DisplayName','ADA z') yyaxis right plot( -simOutput.Y(:, 3), simOutput.Y(:, 14),'g','DisplayName','arb') - legend xlabel("Altitude AGL [m]") +drawnow %% quaternions -figures.EulerAngles = figure('Name','Euler angles','Position',[100,100,600,400]); +figures.EulerAngles = figure('Name','Euler angles'); % subplot(2,2,1) plot(simOutput.t,simOutput.Y(:,10),'k','DisplayName','$q_w$'); @@ -147,17 +151,15 @@ plot(simOutput.sensors.nas.time,simOutput.sensors.nas.states(:,9),'r','DisplayNa if settings.parafoil && (settings.scenario == "descent" || settings.scenario == "full flight") xline(simOutput.t(simOutput.events.mainChuteIndex),'b--','DisplayName','Parafoil opening') end -legend -ylabel('$q_z$') -xlabel('Time [s]') - +ylabel('$q_z$'), xlabel('Time [s]') legend sgtitle('Quaternions') +drawnow %% Control variable: servo angle + reference values % air brakes if not(settings.scenario == "descent") - figures.servo_angle = figure('Name', 'Servo angle after burning phase','ToolBar','auto','Position',[100,100,600,400]); + figures.servo_angle = figure('Name', 'Servo angle after burning phase','ToolBar','auto'); plot(simOutput.t, simOutput.Y(:,14)); hold on; grid on; stairs(simOutput.ARB.cmdTime,simOutput.ARB.cmdPosition,'r'); @@ -171,22 +173,23 @@ if not(settings.scenario == "descent") if settings.flagExportPLOTS == true exportStandardizedFigure(figures.servo_angle,"report_images\"+mission.name+"\src_servo_angle.pdf",0.9) end + drawnow end % parafoil if settings.parafoil && (settings.scenario == "descent" || settings.scenario == "full flight") - figures.parafoil_servo_action = figure('Name', 'Parafoil deltaA','ToolBar','auto','Position',[100,100,600,400]); + figures.parafoil_servo_action = figure('Name', 'Parafoil deltaA','ToolBar','auto'); plot(simOutput.t,simOutput.Y(:,15),'DisplayName','$\delta_A$'); hold on; stairs(simOutput.PRF.cmdTime,simOutput.PRF.cmddeltaA,'DisplayName','$\Delta_A$ cmd'); xline(simOutput.t(simOutput.events.mainChuteIndex),'--','DisplayName','Parafoil deployment') legend title('Parafoil control action') - xlabel('Time [s]') - ylabel('Normalized control action [-]') + xlabel('Time [s]'), ylabel('Normalized control action [-]') + drawnow end %% Trajectory -figures.trajectory = figure('Name', 'Trajectory','ToolBar','auto','Position',[100,100,600,400]); +figures.trajectory = figure('Name', 'Trajectory','ToolBar','auto'); plot3(simOutput.Y(1:end-10, 2), simOutput.Y(1:end-10, 1), -simOutput.Y(1:end-10, 3),'DisplayName','True trajectory'); hold on; grid on; plot3(simOutput.sensors.nas.states(1:end-10, 2), simOutput.sensors.nas.states(1:end-10, 1), -simOutput.sensors.nas.states(1:end-10, 3)-environment.z0,'DisplayName','NAS trajectory'); @@ -215,6 +218,7 @@ legend if settings.flagExportPLOTS == true exportStandardizedFigure(figures.trajectory,"report_images\"+mission.name+"\src_trajectory.pdf",0.49) end +drawnow %% Velocities BODY w.r.t. time against NAS @@ -278,6 +282,7 @@ legend if settings.flagExportPLOTS == true exportStandardizedFigure(figures.velocities_BODY,"report_images\"+mission.name+"\src_velocities_BODY.pdf",0.9) end +drawnow %% Velocities NED w.r.t. time against NAS @@ -318,6 +323,7 @@ legend if settings.flagExportPLOTS == true exportStandardizedFigure(figures.velocities_NED,"report_images\"+mission.name+"\src_velocities_NED.pdf",0.9) end +drawnow %% check consistency of NAS: altitude = simOutput.sensors.nas.states(:,3)+environment.z0; @@ -339,13 +345,14 @@ plot(simOutput.t,simOutput.Y(:,3),'DisplayName','Altitude Simulation') plot(simOutput.t,v_int_simulation,'DisplayName','Velocity simulation integrated') legend xlabel("Time [s]"), ylabel("-Altitude AGL [m]") +drawnow %% euler angles eul_NAS = quat2eul(simOutput.sensors.nas.states(:,[10,7:9])); eul_NAS = flip(eul_NAS,2); eul_NAS = unwrap(eul_NAS); eul_NAS = rad2deg(eul_NAS); -figures.EulerAngles = figure('Name','Euler angles','Position',[100,100,600,400]); +figures.EulerAngles = figure('Name','Euler angles'); % subplot(3,1,1) plot(simOutput.t,eul(:,1),'DisplayName','$\phi$'); @@ -378,9 +385,10 @@ ylabel('Yaw [deg]') legend sgtitle('Euler angles') xlabel('Time [s]') +drawnow %% angular rotations -figures.velocities = figure('Name', 'Angular rotations BODY','ToolBar','auto','Position',[100,100,600,400]); +figures.velocities = figure('Name', 'Angular rotations BODY','ToolBar','auto'); % subplot(3,1,1) plot(simOutput.t, simOutput.Y(:, 7),'DisplayName','p') @@ -425,6 +433,7 @@ legend if settings.flagExportPLOTS == true exportStandardizedFigure(figures.velocities,"report_images\"+mission.name+"\src_Angular_rotations_BODY.pdf",0.9) end +drawnow %% euler angles vs altitude figure @@ -437,6 +446,7 @@ legend title('Euler angles wrt altitude') xlabel('Altitude [m]') ylabel('Angle [deg]') +drawnow end