forked from NCSUCORE/NCSUWaterChannelControl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitializeSystem.m
More file actions
122 lines (104 loc) · 4.14 KB
/
initializeSystem.m
File metadata and controls
122 lines (104 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
%% Script to initialize the NCSU water channel control system
%% DO NOT RUN SECTION
% Please do not move this file
% Get the path to the highest level of the project
baseDir = fileparts(which(mfilename));
% Open the simulink project file
fprintf('\nOpening simulink project WaterChannelControl.prj\n\n')
simulinkproject(fullfile(baseDir,'WaterChannelControl.prj'))
% Set working directory to output
fprintf('\nSetting working directory to output\n')
cd(fullfile(baseDir,'output')) % Set the working directory
% Start timer for execution timeout if build not selected
t = timer('ExecutionMode', 'singleShot', 'StartDelay', 10, 'TimerFcn', @pressEnter);
start(t);
fprintf('\n*******************************')
answer = input([...
'\nWould you like to open models,',...
'\nbuild models, and connect to target?'...
'\nIf yes, make sure targets are on first.\n',...
'\nPrompt will time out after 10s',...
'\nand do nothing.\n',...
'[y/n]:'],'s');
stop(t);
delete(t);
if strcmpi(answer,'y')
% Load parameters structure into base workspace
fprintf('\nLoading params struct\n')
loadParams
while ~ismember('params',evalin('base','who'))
loadParams
end
% Initialize controllers
fprintf('\nLoading controller initialization\n')
controllers_init
% select RGP adaptive controller
CONTROLLER = 2;
% load RGP parameters
RGP_parameters;
while ~ismember('CONTROLLER',evalin('base','who'))
controllers_init
end
createSnellsMinParams;
createRayTraceCtrlBus;
createCoordinateCtrlBus;
fprintf('\nOpening all models\n')
% Window positions determined from using get_param(gcs,'location')
windowPositions = [ -6 0 775 418;...
762 0 1543 418;...
-6 412 775 830;...
762 412 1543 830];
% Open all the individual models
for ii = 2:5
open_system(fullfile(baseDir,'models',sprintf('model%d',ii),sprintf('model%d_cm.slx',ii)))
% Add code here to reposition/resize windows to tile them
set_param(gcs,'location',windowPositions(ii-1,:));
% Zoom to fit
set_param(gcs, 'ZoomFactor','FitSystem')
end
% If this is the host laptop and we're logged in as the generic user
if strcmpi(getenv('computername'),'vermillionlab4') && strcmpi(getenv('username'),'MAE-NCSUCORE')
% Build and connect
fprintf('\nBuilding all models\n')
for ii = 2:5
% Build models:
try
fprintf('\nBuilding model%d_cm.slx\n',ii)
rtwbuild(sprintf('model%d_cm',ii));
% Sometimes the above line results in a bug that locks the
% models from editing etc. To break out of this use: model2_cm([], [], [], 'term')
% You may need to run that multiple times to get it to work.
catch errMsg
rethrow(errMsg)
end
% Connect to targets:
try
fprintf('\nConnecting to target machine %d\n',ii)
set_param(sprintf('model%d_cm',ii),'SimulationCommand','connect');
catch errMsg
rethrow(errMsg)
end
end
end
% Check for appropriate target
% Build and connect
fprintf('\nBuilding all models\n')
% Put code to build models and connect here.
fprintf('\nConnecting to targets\n')
% Check for target first probably ought to use some kind of try/catch
% Open Water Channel Config GUI
waterChannelConfigGUI
% Open Simulink Real-Time Explorer
slrtexplr
end
fprintf('\nDone\n')
clearvars t ii baseDir answer ans windowPositions_px errMsg
function pressEnter(HObj, event)
% Code copied from: https://www.mathworks.com/matlabcentral/answers/119067-how-can-i-set-a-time-for-input-waiting
commandwindow % move the cursor to the command window
import java.awt.*;
import java.awt.event.*;
rob = Robot;
rob.keyPress(KeyEvent.VK_ENTER)
rob.keyRelease(KeyEvent.VK_ENTER)
end