35 % Properties that correspond to app components
36 properties (Access =
public)
37 OrientationAppUIFigure matlab.ui.Figure
38 gridMain matlab.ui.container.GridLayout
39 gridSliders matlab.ui.container.GridLayout
40 mossFeb2024Label matlab.ui.control.Label
41 Image matlab.ui.control.Image
42 QuaternionEditField matlab.ui.control.EditField
43 QuaternionEditFieldLabel matlab.ui.control.Label
44 SaveOrientationButton matlab.ui.control.Button
45 DefineOrientationLabel matlab.ui.control.Label
46 slidRoll matlab.ui.control.Slider
47 RollLabel matlab.ui.control.Label
48 slidPitch matlab.ui.control.Slider
49 PitchLabel matlab.ui.control.Label
50 slidYaw matlab.ui.control.Slider
51 YawLabel matlab.ui.control.Label
52 poseVisu matlab.ui.control.UIAxes
56 properties (Access = private)
59 quatSave % backup from beginning
62 methods (Access = private)
67 % Callbacks that
handle component events
68 methods (Access = private)
70 % Code that executes after component creation
71 function startupFcn(app, varargin)
84 e = errordlg(
"Invalid number of arguments");
86 app.OrientationAppUIFigureCloseRequest;
89 app.callingApp = caller;
92 app.quat = quaternion(quat);
94 app.quat = quaternion([1,0,0,0]);
97 % save the argument
for backup
98 app.quatSave = app.quat;
100 % set the sliders correctly
101 ang = app.quat.eulerd(
"ZYX",
"frame");
102 app.slidYaw.Value = mod(ang(1) + 360,360);
103 app.slidPitch.Value = mod(ang(2) + 360,360);
104 app.slidRoll.Value = mod(ang(3) + 360,360);
106 % set the quaternion correctly
107 app.QuaternionEditField.Value = sprintf(
"%.2f,%.2f,%.2f,%.2f",app.quat.compact);
110 poseplot(app.poseVisu,app.quat,
"NED",
"MeshFileName",
"jumpSimplified.stl");
111 app.poseVisu.XGrid =
true;
112 app.poseVisu.YGrid =
true;
113 app.poseVisu.ZGrid =
true;
114 app.poseVisu.Children(1).PatchFaceAlpha = 0.7;
115 app.poseVisu.Children(1).Orientation;
116 app.poseVisu.Children(1).PatchFaceColor = [0,0.57,0.82];
117 app.poseVisu.PlotBoxAspectRatioMode =
"manual";
118 app.poseVisu.PlotBoxAspectRatio = [1,1,1];
121 % Value changed function: slidPitch, slidRoll, slidYaw
122 function sliderValChange(app, event)
123 yaw = round(app.slidYaw.Value);
124 pitch = round(app.slidPitch.Value);
125 roll = round(app.slidRoll.Value);
127 app.quat = quaternion([yaw,pitch,roll],
"eulerd",
"ZYX",
"frame");
128 app.poseVisu.Children(1).Orientation = app.quat;
130 app.QuaternionEditField.Value = sprintf(
"%.2f,%.2f,%.2f,%.2f",app.quat.compact);
133 % Button pushed function: SaveOrientationButton
134 function SaveOrientationButtonPushed(app, event)
135 app.quatSave = app.quat;
136 app.OrientationAppUIFigureCloseRequest;
139 % Close request function: OrientationAppUIFigure
140 function OrientationAppUIFigureCloseRequest(app, event)
142 if ~ismissing(app.callingApp)
144 app.callingApp.appReturnValue = app.quatSave.compact;
146 e = errordlg("No Parent App Defined");
155 % Value changed function: QuaternionEditField
156 function QuaternionEditFieldValueChanged(app, event)
157 value = str2double(strsplit(app.QuaternionEditField.Value,','));
160 app.quat = quaternion(value);
161 ang = app.quat.eulerd("ZYX","frame");
162 app.slidYaw.Value = mod(ang(1)+360,360);
163 app.slidPitch.Value = mod(ang(2)+360,360);
164 app.slidRoll.Value = mod(ang(3),360);
167 e = errordlg("Invalid Quaternion Input");
175 % Key release function: OrientationAppUIFigure
176 function OrientationAppUIFigureKeyRelease(app, event)
181 app.SaveOrientationButtonPushed;
183 app.OrientationAppUIFigureCloseRequest;
188 % Component initialization
189 methods (Access = private)
191 % Create UIFigure and components
192 function createComponents(app)
194 % Create OrientationAppUIFigure and hide until all components are created
195 app.OrientationAppUIFigure = uifigure('Visible', 'off');
196 app.OrientationAppUIFigure.Position = [100 100 892 480];
197 app.OrientationAppUIFigure.Name = 'Orientation App';
198 app.OrientationAppUIFigure.Icon = 'logo_zhaw.png';
199 app.OrientationAppUIFigure.CloseRequestFcn = createCallbackFcn(app, @OrientationAppUIFigureCloseRequest, true);
200 app.OrientationAppUIFigure.KeyReleaseFcn = createCallbackFcn(app, @OrientationAppUIFigureKeyRelease, true);
201 app.OrientationAppUIFigure.WindowStyle = 'modal';
204 app.gridMain = uigridlayout(app.OrientationAppUIFigure);
205 app.gridMain.ColumnWidth = {
'2x',
'3x'};
206 app.gridMain.RowHeight = {
'1x'};
209 app.poseVisu = uiaxes(app.gridMain);
210 xlabel(app.poseVisu,
'X')
211 ylabel(app.poseVisu, 'Y')
212 zlabel(app.poseVisu, 'Z')
213 app.poseVisu.Layout.Row = 1;
214 app.poseVisu.Layout.Column = 2;
217 app.gridSliders = uigridlayout(app.gridMain);
218 app.gridSliders.ColumnWidth = {150,
'1x'};
219 app.gridSliders.RowHeight = {
'1x',
'fit',
'fit',
'fit',
'fit',
'fit',
'fit',
'1x', 75};
220 app.gridSliders.Layout.Row = 1;
221 app.gridSliders.Layout.Column = 1;
224 app.YawLabel = uilabel(app.gridSliders);
225 app.YawLabel.HorizontalAlignment =
'right';
226 app.YawLabel.Layout.Row = 3;
227 app.YawLabel.Layout.Column = 1;
228 app.YawLabel.Text =
'Yaw';
231 app.slidYaw = uislider(app.gridSliders);
232 app.slidYaw.Limits = [0 360];
233 app.slidYaw.ValueChangedFcn = createCallbackFcn(app, @sliderValChange,
true);
234 app.slidYaw.Layout.Row = 3;
235 app.slidYaw.Layout.Column = 2;
238 app.PitchLabel = uilabel(app.gridSliders);
239 app.PitchLabel.HorizontalAlignment =
'right';
240 app.PitchLabel.Layout.Row = 4;
241 app.PitchLabel.Layout.Column = 1;
242 app.PitchLabel.Text = {
'Pitch';
''};
245 app.slidPitch = uislider(app.gridSliders);
246 app.slidPitch.Limits = [0 360];
247 app.slidPitch.ValueChangedFcn = createCallbackFcn(app, @sliderValChange,
true);
248 app.slidPitch.Layout.Row = 4;
249 app.slidPitch.Layout.Column = 2;
252 app.RollLabel = uilabel(app.gridSliders);
253 app.RollLabel.HorizontalAlignment =
'right';
254 app.RollLabel.Layout.Row = 5;
255 app.RollLabel.Layout.Column = 1;
256 app.RollLabel.Text =
'Roll';
259 app.slidRoll = uislider(app.gridSliders);
260 app.slidRoll.Limits = [0 360];
261 app.slidRoll.ValueChangedFcn = createCallbackFcn(app, @sliderValChange,
true);
262 app.slidRoll.Layout.Row = 5;
263 app.slidRoll.Layout.Column = 2;
265 % Create DefineOrientationLabel
266 app.DefineOrientationLabel = uilabel(app.gridSliders);
267 app.DefineOrientationLabel.HorizontalAlignment =
'center';
268 app.DefineOrientationLabel.FontSize = 18;
269 app.DefineOrientationLabel.FontWeight =
'bold';
270 app.DefineOrientationLabel.Layout.Row = 2;
271 app.DefineOrientationLabel.Layout.Column = 2;
272 app.DefineOrientationLabel.Text =
'Define Orientation';
274 % Create SaveOrientationButton
275 app.SaveOrientationButton = uibutton(app.gridSliders,
'push');
276 app.SaveOrientationButton.ButtonPushedFcn = createCallbackFcn(app, @SaveOrientationButtonPushed,
true);
277 app.SaveOrientationButton.Layout.Row = 7;
278 app.SaveOrientationButton.Layout.Column = 2;
279 app.SaveOrientationButton.Text =
'Save Orientation';
281 % Create QuaternionEditFieldLabel
282 app.QuaternionEditFieldLabel = uilabel(app.gridSliders);
283 app.QuaternionEditFieldLabel.HorizontalAlignment =
'right';
284 app.QuaternionEditFieldLabel.Layout.Row = 6;
285 app.QuaternionEditFieldLabel.Layout.Column = 1;
286 app.QuaternionEditFieldLabel.Text =
'Quaternion';
288 % Create QuaternionEditField
289 app.QuaternionEditField = uieditfield(app.gridSliders,
'text');
290 app.QuaternionEditField.ValueChangedFcn = createCallbackFcn(app, @QuaternionEditFieldValueChanged,
true);
291 app.QuaternionEditField.HorizontalAlignment =
'center';
292 app.QuaternionEditField.Layout.Row = 6;
293 app.QuaternionEditField.Layout.Column = 2;
294 app.QuaternionEditField.Value =
'0,1,0,0';
297 app.Image = uiimage(app.gridSliders);
298 app.Image.Layout.Row = 9;
299 app.Image.Layout.Column = 1;
300 app.Image.VerticalAlignment =
'bottom';
301 app.Image.ImageSource =
'logo_isc.png';
303 % Create mossFeb2024Label
304 app.mossFeb2024Label = uilabel(app.gridSliders);
305 app.mossFeb2024Label.HorizontalAlignment =
'center';
306 app.mossFeb2024Label.VerticalAlignment =
'bottom';
307 app.mossFeb2024Label.FontColor = [0.502 0.502 0.502];
308 app.mossFeb2024Label.Layout.Row = 9;
309 app.mossFeb2024Label.Layout.Column = 2;
310 app.mossFeb2024Label.Text =
'moss, Feb 2024';
312 % Show the figure after all components are created
313 app.OrientationAppUIFigure.Visible =
'on';
317 % App creation and deletion
318 methods (Access =
public)
323 % Create UIFigure and components
324 createComponents(app)
326 % Register the app with App Designer
327 registerApp(app, app.OrientationAppUIFigure)
329 % Execute the startup function
330 runStartupFcn(app, @(app)startupFcn(app, varargin{:}))
337 % Code that executes before app deletion
340 % Delete UIFigure when app is deleted
341 delete(app.OrientationAppUIFigure)