Skip to content

Commit

Permalink
Added all project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
smiller01985 committed Oct 16, 2019
1 parent e205a85 commit 4871579
Show file tree
Hide file tree
Showing 497 changed files with 2,529 additions and 0 deletions.
71 changes: 71 additions & 0 deletions Scripts_Data/sm_aileron_actuator_plot4ctrlcircavgpwm.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
% Code to plot simulation results from sm_aileron_actuator
%% Plot Description:
%
% The plots below show the effects of implementing the control algorithm
% using an analog circuit.
%
% Copyright 2018-2019 The MathWorks, Inc.

% Reuse figure if it exists, else create new figure
if ~exist('h4_sm_aileron_actuator', 'var') || ...
~isgraphics(h4_sm_aileron_actuator, 'figure')
h4_sm_aileron_actuator = figure('Name', 'sm_aileron_actuator');
end
figure(h4_sm_aileron_actuator)
temp_colororder = get(gca,'defaultAxesColorOrder');
clf(h4_sm_aileron_actuator)

config_set = {'E Cir Avg','E Cir PWM'};
stopti_set = {'0.002','0.002'};
clrind_set = [4 5];
modelname = 'sm_aileron_actuator';

open_system('sm_aileron_actuator/Actuator/Electric');
for i=1:length(config_set)
sm_aileron_actuator_configModel(modelname,config_set{i})
set_param(modelname,'StopTime',stopti_set{i});
sim(modelname)
% Get simulation results
simlog_t = simlog_sm_aileron_actuator.Mechanical.Cyl_MC_BrkLAil.Rz.q.series.time;
simlog_qAil = simlog_sm_aileron_actuator.Mechanical.Cyl_MC_BrkLAil.Rz.q.series.values('deg');
simlog_actFrc = logsout_sm_aileron_actuator.get('force_act');
simlog_qCmd = logsout_sm_aileron_actuator.get('qCmd');
simlog_iMot = simlog_sm_aileron_actuator.Actuator.Electric.Leadscrew_1.DC_Motor.i.series.values('A');

% Plot results
simlog_handles(1) = subplot(2, 1, 1);
hold on
%if(i==1)
% plot(simlog_qCmd.Values.Time, simlog_qCmd.Values.Data, 'k-.', 'LineWidth', 1)
%end
plot(simlog_t, simlog_qAil, 'LineWidth', 1,'Color',temp_colororder(clrind_set(i),:));

simlog_handles(2) = subplot(2, 1, 2);
hold on
plot(simlog_t,simlog_iMot, 'LineWidth', 1, 'Color',temp_colororder(clrind_set(i),:))
end
set_param(modelname,'StopTime','10');

grid(simlog_handles(1),'on');
box(simlog_handles(1),'on');
grid(simlog_handles(2),'on');
box(simlog_handles(2),'on');

title(simlog_handles(1),'Aileron Angle')
ylabel(simlog_handles(1),'Angle (deg)')
legend(simlog_handles(1),{'Average','PWM'},'Location','Best');

title(simlog_handles(2),'Motor Current')
ylabel(simlog_handles(2),'Current (A)')
xlabel(simlog_handles(2),'Time (s)')

linkaxes(simlog_handles, 'x')

set(simlog_handles(2),'XLim',[0 str2num(stopti_set{2})]);

hold(simlog_handles(1),'off')
hold(simlog_handles(2),'off')

% Remove temporary variables
%clear simlog_t simlog_handles temp_colororder
clear simlog_actFrc simlog_qCmd simlog_qAil
10 changes: 10 additions & 0 deletions Scripts_Data/startup_sm_aileron_actuator.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
% Startup script for project Aileron_Act.prj
% Copyright 2018-2019 The MathWorks, Inc.

AAC_HomeDir = pwd;

sm_aileron_actuator_PARAM
load sm_aileron_actuator_Ang2Ext

sm_aileron_actuator
web('sm_aileron_actuator_Demo_Script.html');
106 changes: 106 additions & 0 deletions Workflows/IP_Protect/sm_aileron_actuator_IP_Protect.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
% Protect model containing Simscape components
% and test with varying parameters.

% Copyright 2013-2019 The MathWorks(TM), Inc.

% Open model, create copy
orig_mdl = 'sm_aileron_actuator';
mdl = 'sm_aileron_actuator_protected';
refmdl = 'Aileron_System';
refsys = [mdl '/' refmdl];
open_system(orig_mdl);
save_system(orig_mdl,mdl);
set_param(mdl,'SystemTargetFile','grt.tlc');
sm_aileron_actuator_configModel(mdl,'Hydraulic')

%% Configure test and parameters
%Aileron_EH_Final_Values;
sm_aileron_actuator_configRTParams(mdl,'Hydraulic')

%% Create subsystem to be protected
bh(1) = get_param([mdl '/Actuator'],'Handle');
bh(2) = get_param([mdl '/Mechanical'],'Handle');
bh(3) = get_param([mdl '/Aero Load'],'Handle');
bh(4) = get_param([mdl '/qMGoto'],'Handle');
bh(5) = get_param([mdl '/qMFrom1'],'Handle');
bh(6) = get_param([mdl '/qMFrom2'],'Handle');
Simulink.BlockDiagram.createSubSystem(bh);
set_param([mdl '/Subsystem'],...
'Name',refmdl,...
'Position',[-250 -24 -25 64]);

set_param([mdl '/Flight Cycle'],...
'Position',[-315 -81 -270 -39]);
set_param([mdl '/Goto1'],...
'Position',[25 -8 45 8]);


%% Create Reference Model
set_param(refsys,'TreatAsAtomicUnit','on');

Simulink.SubSystem.convertToModelReference(...
refsys,refmdl, ...
'AutoFix',true,...
'ReplaceSubsystem',true);

%% Configure Reference Model
open_system(refmdl);
set_param(refmdl,'SimscapeLogType','none');
set_param(refmdl,'SimMechanicsOpenEditorOnUpdate','off');
set_param(refmdl,'ModelReferenceNumInstancesAllowed','single');
save_system(refmdl);

%% Create and reference protected model
[harnessHandle, neededVars] = ...
Simulink.ModelReference.protect(refmdl,...
'Harness', false,...
'Webview',true);
set_param(refsys,'ModelName',[refmdl '.slxp']);
bdclose(refmdl);

save_system(mdl);

%% Run simulation with modified parameter value
hydr_supply_pressure.Value = 2e6;
sim(mdl)
y_run1 = Angles_Forces.signals(1).values(:,1);
t_run1 = Angles_Forces.time;
y_ref = logsout_sm_aileron_actuator.get('qCmd');

hydr_supply_pressure.Value = 2e6*0.7;
sim(mdl);
y_run2 = Angles_Forces.signals(1).values(:,1);
t_run2 = Angles_Forces.time;

if ~exist('h5_sm_aileron_actuator_ipprotect', 'var') || ...
~isgraphics(h5_sm_aileron_actuator_ipprotect, 'figure')
h5_sm_aileron_actuator_ipprotect = figure('Name', 'sm_aileron_actuator');
end
figure(h5_sm_aileron_actuator_ipprotect)
clf(h5_sm_aileron_actuator_ipprotect)

temp_colororder = get(gca,'defaultAxesColorOrder');

plot(y_ref.Values.Time,y_ref.Values.Data,'Color','k','LineWidth',1,'LineStyle','--');
hold on
plot(t_run1, y_run1,'LineWidth',1,'Color',temp_colororder(1,:));
plot(t_run2, y_run2,'LineWidth',1,'Color',temp_colororder(2,:));
hold off
title('Supply Pressure Test');
xlabel('Time (s)');ylabel('Angle (deg)');
legend({'Command','Full','Reduced'},'Location','Best');
grid on


%% Close model and clean up directory
%{
bdclose(mdl);
delete([mdl '.slx']);
delete([mdl '.slxc']);
bdclose(refmdl);
delete([refmdl '.slx']);
delete([refmdl '.slxp']);
delete([refmdl '_msp.mexw64']);
!rmdir slprj /S/Q
%}

Binary file not shown.
13 changes: 13 additions & 0 deletions Workflows/Optimize/sm_aileron_actuator_resp_opt.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
% Copyright 2013-2019 The MathWorks(TM), Inc.

% Initial values
Kp = 0.03;
Ki = 0.03;

% Configure model
set_param('sm_aileron_actuator','FastRestart','on');
set_param('sm_aileron_actuator','SimMechanicsOpenEditorOnUpdate','off');

% Load session
load sm_aileron_actuator_sdosession
sdotool(SDOSessionData);
Binary file not shown.
Binary file not shown.
Binary file added Workflows/Param_Est/Elec/Motor_Param_Est.slx
Binary file not shown.
Binary file added Workflows/Param_Est/Elec/Motor_Param_Est_Data.mat
Binary file not shown.
Binary file not shown.
16 changes: 16 additions & 0 deletions Workflows/Param_Est/Elec/sn_motor_params_setparams.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function sn_motor_params_setparams(initialtuned)
% Copyright 2012-2019 The MathWorks(TM), Inc.

if (strcmp(initialtuned,'Initial'))
evalin('base','DC_Motor_R = 3;');
evalin('base','DC_Motor_L = 0.01;');
evalin('base','DC_Motor_K = 0.02;');
evalin('base','DC_Motor_J = 0.01;');
evalin('base','DC_Motor_B = 0.5;');
else
evalin('base','DC_Motor_R = 4.0162;');
evalin('base','DC_Motor_L = 2.0536e-04;');
evalin('base','DC_Motor_K = 1.0363;');
evalin('base','DC_Motor_J = 0.1306;');
evalin('base','DC_Motor_B = 1.0630;');
end
Binary file added Workflows/Param_Est/Hydr/HS_Param_Est_Data.mat
Binary file not shown.
42 changes: 42 additions & 0 deletions Workflows/Param_Est/Hydr/HS_Param_Est_Slide_Prep.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
% Copyright 2014-2019 The MathWorks, Inc.
time = HS_Param_Est_Input_DATA.time;
Input_Data = HS_Param_Est_Input_DATA.signals.values;
Cyl_Pos_Data = logsout_Hydraulic_System_Param_Est.get('Piston_Position');
Cyl_Pos_Sim_Data = Cyl_Pos_Data.Values.Data(:,1);
Cyl_Pos_Meas_Data = Cyl_Pos_Data.Values.Data(:,2);
Cyl_Pos_time = Cyl_Pos_Data.Values.time;

figure(1);
clf;
temp_colorOrder = get(gca,'DefaultAxesColorOrder');

new_sb211_h = 336;
set(gcf,'Position',[765 189 449 new_sb211_h]);
%POSITION_211 = [0.15 0.583837 0.775 0.341163*522/new_sb211_h];
subplot(211)
set(gca,'Position',[0.1300 0.48 0.7750 0.4]);

pos2_h = plot(Cyl_Pos_time,Cyl_Pos_Meas_Data,'LineWidth',3,'Color',temp_colorOrder(1,:));
hold on
pos_h = plot(Cyl_Pos_time,Cyl_Pos_Sim_Data,'LineWidth',3,'Color',temp_colorOrder(2,:));

title_h = title('Cylinder Position (m)');
ylabel_h = ylabel('Position (m)');
set(title_h,'FontSize',14);
set(ylabel_h,'FontSize',12);
grid on
set(gca,'Box','on');
axis([time(1) time(end) -1.4 .4]);
legend({'Measured','Simulated'},'Location','Best')

subplot(212)
set(gca,'Position',[0.1300 0.1100 0.7750 0.2]);
pos_h = stairs(time,Input_Data,'LineWidth',3);
title_h = title('Input Signal (PB | close | PA)');
set(gca,'YTickLabel',{'PA','close','PB'});
set(title_h,'FontSize',14);
set(ylabel_h,'FontSize',12);
grid on
set(gca,'Box','on');
axis([time(1) time(end) -1.2 1.2]);

5 changes: 5 additions & 0 deletions Workflows/Param_Est/Hydr/HS_Param_Final_Values.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
% Copyright 2014-2019 The MathWorks, Inc.
HS_Valve_Max_Opening=0.002;
HS_Valve_Max_Area=200;
HS_Piston_Area_A=0.0174;
HS_Piston_Area_B=0.0108;
5 changes: 5 additions & 0 deletions Workflows/Param_Est/Hydr/HS_Param_Start_Values.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
% Copyright 2014-2019 The MathWorks, Inc.
HS_Valve_Max_Opening=0.002;
HS_Valve_Max_Area=100;
HS_Piston_Area_A=0.0176;
HS_Piston_Area_B=0.02;
Binary file not shown.
Binary file not shown.
34 changes: 34 additions & 0 deletions Workflows/Param_Sweep/Generate_Sim_Settings.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
function [simCmdParamValStructs] = Generate_Sim_Settings(param_vals,param_name,rtp)

% Copyright 2012-2019 The MathWorks(TM), Inc.

numParamSets = length(param_vals);

% Create parameter sets:
paramSets = cell(1, numParamSets);
for k = 1:numParamSets
paramSets{k} = ...
Simulink.BlockDiagram.modifyTunableParameters(rtp, ...
param_name,param_vals(k));
end

%% Step 5: Create SIM Command Argument Sets

numSimCmdArgStructs = numParamSets;
simCmdParamValStructs = cell(1, numSimCmdArgStructs);

%paramValStruct.SaveTime = 'on';
%paramValStruct.SaveOutput = 'on';
%paramValStruct.LoadExternalInput = 'on';
% 'externalInput' is the name of the base workspace variable of
% the MATLAB worker sessions containing the external inputs data
%paramValStruct.ExternalInput = 'externalInput';
paramValStruct.RapidAcceleratorUpToDateCheck = 'off';
paramValStruct.RapidAcceleratorParameterSets = [];
paramValStruct.SimulationMode = 'rapid';

for paramSetsIdx = 1:numParamSets
simCmdParamValStructs{paramSetsIdx} = paramValStruct;
simCmdParamValStructs{paramSetsIdx}.RapidAcceleratorParameterSets = ...
paramSets{paramSetsIdx};
end
12 changes: 12 additions & 0 deletions Workflows/Param_Sweep/Initialize_MLPool.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
% Copyright 2013-2019 The MathWorks, Inc.
TempSimSettings = SimSettings;
Temppool = gcp;
Temppoolsize = Temppool.NumWorkers;

for i = 1:Temppoolsize
TempSimSettings{i}.StopTime = '0.01';
end

parfor i = 1:Temppoolsize
out{i} = sim(mdl, TempSimSettings{i});
end
7 changes: 7 additions & 0 deletions Workflows/Param_Sweep/PCT_Simulation_Slide_Prep.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
% Copyright 2012-2019 The MathWorks(TM), Inc.

set(gcf,'Position',[765 405 449 336]);
box on
text(200,25,'Testing Time (normal): 93.2 sec','FontSize',12,'FontWeight','Bold');
text(200,15,'Testing Time (two cores): 53.4 sec','FontSize',12,'FontWeight','Bold');
axis([0 1200 0 100])

0 comments on commit 4871579

Please sign in to comment.