-
Notifications
You must be signed in to change notification settings - Fork 2
/
GUI_MWBH_1Bottle.m
1206 lines (1019 loc) · 53.2 KB
/
GUI_MWBH_1Bottle.m
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% Magic Wine Bottle Holder - 1 Bottle
% Written by: JoshTheEngineer
% Started: 05/15/16
% Updated: 05/15/16 - Transferring code over from Wine_Bottle_Holder_1Bottle.m
% 05/23/16 - Everything works as expected
% - Bottle angle plotting based on hole diameter works
function varargout = GUI_MWBH_1Bottle(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @GUI_MWBH_1Bottle_OpeningFcn, ...
'gui_OutputFcn', @GUI_MWBH_1Bottle_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before GUI_MWBH_1Bottle is made visible.
function GUI_MWBH_1Bottle_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = GUI_MWBH_1Bottle_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
% INITIALIZE VARIABLES
inchToM = 0.0254; % Convert in to m
mToInch = 1/0.0254; % Convert m to in
mmToM = 1/1000; % Convert mm to m
cmToM = 1/100; % Convert cm to m
ccToL = 0.001; % Convert cm^3 to L
bHeight = str2double(get(handles.editHeight,'String')); % Total height [in]
bLBody = str2double(get(handles.editBodyLength,'String')); % Length of body [in]
bDNeck = str2double(get(handles.editNeckDiameter,'String')); % Neck diameter [in]
bLNeck = str2double(get(handles.editNeckLength,'String')); % Neck length [in]
bDBase = str2double(get(handles.editBaseDiameter,'String')); % Base diameter [in]
bLcg = str2double(get(handles.editCGfromBase,'String')); % Base to CG length [in]
bRho = str2double(get(handles.editWineDensity,'String')); % Wine density [kg/L]
bV = str2double(get(handles.editWineVolume,'String')); % Wine volume [L]
wVolume = str2double(get(handles.editWoodVolume,'String')); % Wood volume [in^3]
wMass = str2double(get(handles.editWoodMass,'String')); % Wood mass [kg]
wRho = wMass/(wVolume*inchToM^3);
set(handles.editWoodDensity,'String',num2str(wRho));
% wRho = str2double(get(handles.editWoodDensity,'String')); % Wood density [kg/m^3]
wT = str2double(get(handles.editWoodThickness,'String')); % Wood thickness [in]
wW = str2double(get(handles.editWoodWidth,'String')); % Wood width [in]
useMinAngle = get(handles.checkUseMinAngle,'Value'); % FLAG: Use minimum angle [1] or not [0]
pctLAdd = str2double(get(handles.editAddLength,'String')); % Add percentage of length [%]
theta = str2double(get(handles.editAngle,'String')); % Angle of wood w.r.t. table [deg]
iterMax = str2double(get(handles.editMaxIterations,'String')); % Maximum number of iterations [#]
errorTol = str2double(get(handles.editErrorTolerance,'String')); % Error tolerance - stopping criteria [#]
oldTheta = theta;
% Assign variables into base workspace
assignin('base','bHeight',bHeight);
assignin('base','bLBody',bLBody);
assignin('base','bDNeck',bDNeck);
assignin('base','bLNeck',bLNeck);
assignin('base','bDBase',bDBase);
assignin('base','bLcg',bLcg);
assignin('base','bRho',bRho);
assignin('base','bV',bV);
assignin('base','wVolume',wVolume);
assignin('base','wMass',wMass);
assignin('base','wRho',wRho);
assignin('base','wT',wT);
assignin('base','wW',wW);
assignin('base','useMinAngle',useMinAngle);
assignin('base','pctLAdd',pctLAdd);
assignin('base','theta',theta);
assignin('base','oldTheta',oldTheta);
assignin('base','iterMax',iterMax);
assignin('base','errorTol',errorTol);
assignin('base','inchToM',inchToM);
assignin('base','mToInch',mToInch);
assignin('base','mmToM',mmToM);
assignin('base','cmToM',cmToM);
assignin('base','ccToL',ccToL);
% ----------------------------------------------------------------------- %
% ----------------------------------------------------------------------- %
% --------------------------- INITIALIZATION ---------------------------- %
% ----------------------------------------------------------------------- %
% ----------------------------------------------------------------------- %
% POP --------------------- Select Wine Bottle ----------------------------
function popBottle_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% POP --------------------- Select Wood Type ------------------------------
function popWood_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% POP ------------------ Units: Total Height ------------------------------
function popUnitsHeight_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% POP ----------------- Units: Body Length --------------------------------
function popUnitsBodyLength_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% POP ----------------- Units: Neck Diameter ------------------------------
function popUnitsNeckDiameter_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% POP ----------------- Units: Neck Length --------------------------------
function popUnitsNeckLength_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% POP ---------------- Units: Base Diameter -------------------------------
function popUnitsBaseDiameter_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% POP --------------- Units: CG from Base ---------------------------------
function popUnitsCGfromBase_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% POP ------------------ Units: Wine Density ------------------------------
function popUnitsWineDensity_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% POP -------------------- Units: Wine Volume -----------------------------
function popUnitsWineVolume_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% POP ------------------ Units: Wood Volume -------------------------------
function popUnitsWoodVolume_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% POP ------------------ Units: Wood Mass ---------------------------------
function popUnitsWoodMass_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% POP ------------------ Units: Wood Density ------------------------------
function popUnitsWoodDensity_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% POP -------------------- Units: Wood Thickness --------------------------
function popUnitsWoodThickness_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% POP -------------------- Units: Wood Width ------------------------------
function popUnitsWoodWidth_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% POP -------------------- Units: Angle -----------------------------------
function popUnitsAngle_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% EDIT ---------------------- Bottle Height -------------------------------
function editHeight_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% EDIT ----------------------- Body Length --------------------------------
function editBodyLength_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% EDIT ----------------------- Neck Diameter ------------------------------
function editNeckDiameter_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% EDIT ------------------- Neck Length ------------------------------------
function editNeckLength_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% EDIT ------------------- Base Diameter ----------------------------------
function editBaseDiameter_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% EDIT ----------------- CG Distance from Base ----------------------------
function editCGfromBase_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% EDIT -------------------- Wine Density ----------------------------------
function editWineDensity_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% EDIT -------------------- Wine Volume -----------------------------------
function editWineVolume_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% EDIT ----------------------- Wood Volume --------------------------------
function editWoodVolume_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% EDIT ------------------------ Wood Mass ---------------------------------
function editWoodMass_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% EDIT ------------------------ Wood Density ------------------------------
function editWoodDensity_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% EDIT ------------------ Add Length Percentage ---------------------------
function editAddLength_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% EDIT ---------------- Wood Angle w.r.t Table ----------------------------
function editAngle_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% EDIT ------------------- Maximum Iterations -----------------------------
function editMaxIterations_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% EDIT --------------------- Error Tolerance ------------------------------
function editErrorTolerance_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% EDIT -------------------- Wood Width ------------------------------------
function editWoodWidth_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% EDIT --------------------- Wood Thickness -------------------------------
function editWoodThickness_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% SLIDER ------------------- Set the Hole Diameter ------------------------
function sliderHoleD_CreateFcn(hObject, eventdata, handles)
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% ----------------------------------------------------------------------- %
% ----------------------------------------------------------------------- %
% ----------------------------- CALLBACKS ------------------------------- %
% ----------------------------------------------------------------------- %
% ----------------------------------------------------------------------- %
% EDIT ---------------------- Bottle Height -------------------------------
function editHeight_Callback(hObject, eventdata, handles)
bHeight = str2double(get(hObject,'String'));
assignin('base','bHeight',bHeight);
% EDIT ----------------------- Body Length --------------------------------
function editBodyLength_Callback(hObject, eventdata, handles)
bLBody = str2double(get(hObject,'String'));
assignin('base','bLBody',bLBody);
% EDIT ----------------------- Neck Diameter ------------------------------
function editNeckDiameter_Callback(hObject, eventdata, handles)
bDNeck = str2double(get(hObject,'String'));
assignin('base','bDNeck',bDNeck);
% EDIT ------------------- Neck Length ------------------------------------
function editNeckLength_Callback(hObject, eventdata, handles)
bLNeck = str2double(get(hObject,'String'));
assignin('base','bLNeck',bLNeck);
% EDIT ------------------- Base Diameter ----------------------------------
function editBaseDiameter_Callback(hObject, eventdata, handles)
bDBase = str2double(get(hObject,'String'));
assignin('base','bDBase',bDBase);
% EDIT ----------------- CG Distance from Base ----------------------------
function editCGfromBase_Callback(hObject, eventdata, handles)
bLcg = str2double(get(hObject,'String'));
assignin('base','bLcg',bLcg);
% EDIT -------------------- Wine Density ----------------------------------
function editWineDensity_Callback(hObject, eventdata, handles)
bRho = str2double(get(hObject,'String'));
asssignin('base','bRho',bRho);
% EDIT -------------------- Wine Volume -----------------------------------
function editWineVolume_Callback(hObject, eventdata, handles)
bV = str2double(get(hObject,'String'));
assignin('base','bV',bV);
% EDIT ----------------------- Wood Volume --------------------------------
function editWoodVolume_Callback(hObject, eventdata, handles)
wVolume = str2double(get(hObject,'String'));
assignin('base','wVolume',wVolume);
% EDIT ------------------------ Wood Mass ---------------------------------
function editWoodMass_Callback(hObject, eventdata, handles)
wMass = str2double(get(hObject,'String'));
assignin('base','wMass',wMass);
% EDIT ------------------------ Wood Density ------------------------------
function editWoodDensity_Callback(hObject, eventdata, handles)
wRho = str2double(get(hObject,'String'));
assignin('base','wRho',wRho);
% EDIT ------------------ Add Length Percentage ---------------------------
function editAddLength_Callback(hObject, eventdata, handles)
pctLAdd = str2double(get(hObject,'String'));
assignin('base','pctLAdd',pctLAdd);
% EDIT ---------------- Wood Angle w.r.t Table ----------------------------
function editAngle_Callback(hObject, eventdata, handles)
theta = str2double(get(hObject,'String'));
assignin('base','theta',theta);
% EDIT ------------------- Maximum Iterations -----------------------------
function editMaxIterations_Callback(hObject, eventdata, handles)
iterMax = str2double(get(hObject,'String'));
assignin('base','iterMax',iterMax);
% EDIT --------------------- Error Tolerance ------------------------------
function editErrorTolerance_Callback(hObject, eventdata, handles)
errorTol = str2double(get(hObject,'String'));
assignin('base','errorTol',errorTol);
% EDIT --------------------- Wood Thickness -------------------------------
function editWoodThickness_Callback(hObject, eventdata, handles)
wT = str2double(get(hObject,'String'));
assignin('base','wT',wT);
% EDIT ----------------------- Wood Width ---------------------------------
function editWoodWidth_Callback(hObject, eventdata, handles)
wW = str2double(get(hObject,'String'));
assignin('base','wW',wW);
% CHECK ------------------ Use Minimum Angle ------------------------------
function checkUseMinAngle_Callback(hObject, eventdata, handles)
if (get(hObject,'Value') ~= get(hObject,'Max'))
oldTheta = evalin('base','oldTheta');
set(handles.editAngle,'String',num2str(oldTheta),...
'BackgroundColor',[1 1 1],...
'ForegroundColor','k');
end
% CHECK -------------------- Show CG Plots --------------------------------
function checkShowCGPlots_Callback(hObject, eventdata, handles)
% CHECK ----------------- Solution in Metric Units ------------------------
function checkMetricUnits_Callback(hObject, eventdata, handles)
% POP --------------------- Select Wine Bottle ----------------------------
function popBottle_Callback(hObject, eventdata, handles)
% Set values for each bottle type
if (get(hObject,'Value') == 1) % BORDEAUX
bHeight = 12; % Total height [in]
bLBody = 7.5; % Length of body [in]
bDNeck = 1; % Neck diameter [in]
bLNeck = 3.5; % Neck length [in]
bDBase = 3; % Base diameter [in]
bLcg = 4.5; % Length from base to CG [in]
bRho = 0.9755; % Wine density [kg/L]
bV = 0.75; % Wine volume [L]
elseif (get(hObject,'Value') == 2) % BURGUNDY
bHeight = 11.75; % Total height [in]
bLBody = 5.5; % Length of body [in]
bDNeck = 1.25; % Neck diameter [in]
bLNeck = 2.5; % Neck length [in]
bDBase = 3; % Base diameter [in]
bLcg = 4.25; % Length from base to CG [in]
bRho = 0.9755; % Wine density [kg/L]
bV = 0.75; % Wine volume [L]
elseif (get(hObject,'Value') == 3) % CUSTOM BOTTLE
% User enters in custom values
end
% Update the edit text boxes and pop menus appropriately
if (get(hObject,'Value') == 3)
% Set the background color to yellow and allow users to edit values
set(handles.editHeight,'BackgroundColor','y','Enable','On');
set(handles.editBodyLength,'BackgroundColor','y','Enable','On');
set(handles.editNeckDiameter,'BackgroundColor','y','Enable','On');
set(handles.editNeckLength,'BackgroundColor','y','Enable','On');
set(handles.editBaseDiameter,'BackgroundColor','y','Enable','On');
set(handles.editCGfromBase,'BackgroundColor','y','Enable','On');
set(handles.editWineDensity,'BackgroundColor','y','Enable','On');
set(handles.editWineVolume,'BackgroundColor','y','Enable','On');
% Allow users to change the units
set(handles.popUnitsHeight,'Enable','On');
set(handles.popUnitsBodyLength,'Enable','On');
set(handles.popUnitsNeckDiameter,'Enable','On');
set(handles.popUnitsNeckLength,'Enable','On');
set(handles.popUnitsBaseDiameter,'Enable','On');
set(handles.popUnitsCGfromBase,'Enable','On');
set(handles.popUnitsWineDensity,'Enable','On');
set(handles.popUnitsWineVolume,'Enable','On');
else
% Update the values in the edit text box
set(handles.editHeight,'String',num2str(bHeight));
set(handles.editBodyLength,'String',num2str(bLBody));
set(handles.editNeckDiameter,'String',num2str(bDNeck));
set(handles.editNeckLength,'String',num2str(bLNeck));
set(handles.editBaseDiameter,'String',num2str(bDBase));
set(handles.editCGfromBase,'String',num2str(bLcg));
set(handles.editWineDensity,'String',num2str(bRho));
set(handles.editWineVolume,'String',num2str(bV));
% Set the background color to white and make it inactive so user
% can't change values
set(handles.editHeight,'BackgroundColor',[1 1 1],...
'Enable','Inactive');
set(handles.editBodyLength,'BackgroundColor',[1 1 1],...
'Enable','Inactive');
set(handles.editNeckDiameter,'BackgroundColor',[1 1 1],...
'Enable','Inactive');
set(handles.editNeckLength,'BackgroundColor',[1 1 1],...
'Enable','Inactive');
set(handles.editBaseDiameter,'BackgroundColor',[1 1 1],...
'Enable','Inactive');
set(handles.editCGfromBase,'BackgroundColor',[1 1 1],...
'Enable','Inactive');
set(handles.editWineDensity,'BackgroundColor',[1 1 1],...
'Enable','Inactive');
set(handles.editWineVolume,'BackgroundColor',[1 1 1],...
'Enable','Inactive');
% Reset the units back to their default and make them inactive so
% the user can't change inputs
set(handles.popUnitsHeight,'Value',1,'Enable','Inactive');
set(handles.popUnitsBodyLength,'Value',1,'Enable','Inactive');
set(handles.popUnitsNeckDiameter,'Value',1,'Enable','Inactive');
set(handles.popUnitsNeckLength,'Value',1,'Enable','Inactive');
set(handles.popUnitsBaseDiameter,'Value',1,'Enable','Inactive');
set(handles.popUnitsCGfromBase,'Value',1,'Enable','Inactive');
set(handles.popUnitsWineDensity,'Value',1,'Enable','Inactive');
set(handles.popUnitsWineVolume,'Value',1,'Enable','Inactive');
% Assign variables into base workspace
assignin('base','bHeight',bHeight);
assignin('base','bLBody',bLBody);
assignin('base','bDNeck',bDNeck);
assignin('base','bLNeck',bLNeck);
assignin('base','bDBase',bDBase);
assignin('base','bLcg',bLcg);
assignin('base','bRho',bRho);
assignin('base','bV',bV);
end
% POP --------------------- Select Wood Type ------------------------------
function popWood_Callback(hObject, eventdata, handles)
inchToM = evalin('base','inchToM');
% Set values for each wood type
if (get(hObject,'Value') == 1) % PALLET
wVolume = 90; % Wood volume [in^3]
wMass = 0.500; % Wood mass [kg]
wRho = wMass/(wVolume*(inchToM^3)); % Wood density [kg/m^3]
elseif (get(hObject,'Value') == 2) % MAPLE
wVolume = 90; % Wood volume [in^3]
wMass = 1.070; % Wood mass [kg]
wRho = wMass/(wVolume*(inchToM^3)); % Wood density [kg/m^3]
elseif (get(hObject,'Value') == 3) % CHERRY
wVolume = 90; % Wood volume [in^3]
wMass = 0.870; % Wood mass [kg]
wRho = wMass/(wVolume*(inchToM^3)); % Wood density [kg/m^3]
elseif (get(hObject,'Value') == 4) % LOWES MAPLE
wVolume = 42.6125; % Wood volume [in^3]
wMass = 0.494; % Wood mass [kg]
wRho = wMass/(wVolume*(inchToM^3)); % Wood density [kg/m^3]
elseif (get(hObject,'Value') == 5) % CUSTOM (Volume/Mass)
% User enters custom volume and mass
elseif (get(hObject,'Value') == 6) % CUSTOM (Density)
% User enters a custom density
end
% Update the edit text boxes and pop menus appropriately
if (get(hObject,'Value') == 5)
% Set the background color to yellow and allow user to change values
set(handles.editWoodVolume,'BackgroundColor','y','Enable','On');
set(handles.editWoodMass,'BackgroundColor','y','Enable','On');
set(handles.editWoodDensity,'BackgroundColor',[1 1 1],...
'Enable','Inactive');
% Allow user to change the units
set(handles.popUnitsWoodVolume,'Enable','On');
set(handles.popUnitsWoodMass,'Enable','On');
set(handles.popUnitsWoodDensity,'Enable','Inactive');
elseif (get(hObject,'Value') == 6)
% Set the background color to yellow and allow user to change values
set(handles.editWoodVolume,'BackgroundColor',[1 1 1],...
'Enable','Inactive');
set(handles.editWoodMass,'BackgroundColor',[1 1 1],...
'Enable','Inactive');
set(handles.editWoodDensity,'BackgroundColor','y','Enable','On');
% Allow user to change the units
set(handles.popUnitsWoodVolume,'Enable','Inactive');
set(handles.popUnitsWoodMass,'Enable','Inactive');
set(handles.popUnitsWoodDensity,'Enable','On');
else
% Update the edit text box values
set(handles.editWoodVolume,'String',num2str(wVolume));
set(handles.editWoodMass,'String',num2str(wMass));
set(handles.editWoodDensity,'String',num2str(wRho));
% Change background color to white and make inactive so user
% can't change values
set(handles.editWoodVolume,'BackgroundColor',[1 1 1],...
'Enable','Inactive');
set(handles.editWoodMass,'BackgroundColor',[1 1 1],...
'Enable','Inactive');
set(handles.editWoodDensity,'BackgroundColor',[1 1 1],...
'Enable','Inactive');
% Set default units and make inactive so user can't change units
set(handles.popUnitsWoodVolume,'Value',1,'Enable','Inactive');
set(handles.popUnitsWoodMass,'Value',1,'Enable','Inactive');
set(handles.popUnitsWoodDensity,'Value',1,'Enable','Inactive');
% Assign variables into base workspace
assignin('base','wVolume',wVolume);
assignin('base','wMass',wMass);
assignin('base','wRho',wRho);
end
% POP ------------------ Units: Total Height ------------------------------
function popUnitsHeight_Callback(hObject, eventdata, handles)
% POP ----------------- Units: Body Length --------------------------------
function popUnitsBodyLength_Callback(hObject, eventdata, handles)
% POP ----------------- Units: Neck Diameter ------------------------------
function popUnitsNeckDiameter_Callback(hObject, eventdata, handles)
% POP ----------------- Units: Neck Length --------------------------------
function popUnitsNeckLength_Callback(hObject, eventdata, handles)
% POP ---------------- Units: Base Diameter -------------------------------
function popUnitsBaseDiameter_Callback(hObject, eventdata, handles)
% POP --------------- Units: CG from Base ---------------------------------
function popUnitsCGfromBase_Callback(hObject, eventdata, handles)
% POP ------------------ Units: Wine Density ------------------------------
function popUnitsWineDensity_Callback(hObject, eventdata, handles)
% POP -------------------- Units: Wine Volume -----------------------------
function popUnitsWineVolume_Callback(hObject, eventdata, handles)
% POP ------------------ Units: Wood Volume -------------------------------
function popUnitsWoodVolume_Callback(hObject, eventdata, handles)
% POP ------------------ Units: Wood Mass ---------------------------------
function popUnitsWoodMass_Callback(hObject, eventdata, handles)
% POP ------------------ Units: Wood Density ------------------------------
function popUnitsWoodDensity_Callback(hObject, eventdata, handles)
% POP -------------------- Units: Wood Thickness --------------------------
function popUnitsWoodThickness_Callback(hObject, eventdata, handles)
% POP -------------------- Units: Wood Width ------------------------------
function popUnitsWoodWidth_Callback(hObject, eventdata, handles)
% POP ----------------------- Units: Angle --------------------------------
function popUnitsAngle_Callback(hObject, eventdata, handles)
% SLIDER ------------------- Set the Hole Diameter ------------------------
function sliderHoleD_Callback(hObject, eventdata, handles)
% Evaluate in relevant variables
holeDArr = evalin('base','holeDArr');
% Get the current value of the slider selection
sliderVal = get(handles.sliderHoleD,'Value');
sliderInd = floor(sliderVal);
assignin('base','sliderInd',sliderInd);
% Set background color if we get too far off the horizontal
if (sliderInd < 15)
set(hObject,'BackgroundColor','r');
elseif (sliderInd >= 15 && sliderInd < 30)
set(hObject,'BackgroundColor','y');
elseif (sliderInd >= 30);
set(hObject,'BackgroundColor','g');
end
% Set the hole diameter selected in the text box indicator
set(handles.textHoleDVal,'String',[num2str(holeDArr(floor(sliderVal))) ' in']);
% Call the function that plots the wood/bottle system
plotSystem(handles);
% PUSH ---------------- Design Wine Bottle Holder -------------------------
function pushDesignBottleHolder_Callback(hObject, eventdata, handles)
% Load relevant variables into this callback
inchToM = evalin('base','inchToM');
mToInch = evalin('base','mToInch');
mmToM = evalin('base','mmToM');
cmToM = evalin('base','cmToM');
ccToL = evalin('base','ccToL');
bHeight = evalin('base','bHeight');
bLBody = evalin('base','bLBody');
bDNeck = evalin('base','bDNeck');
bLNeck = evalin('base','bLNeck');
bDBase = evalin('base','bDBase');
bLcg = evalin('base','bLcg');
bRho = evalin('base','bRho');
bV = evalin('base','bV');
wVolume = evalin('base','wVolume');
wMass = evalin('base','wMass');
wRho = evalin('base','wRho');
wT = evalin('base','wT');
wW = evalin('base','wW');
theta = evalin('base','theta');
pctLAdd = evalin('base','pctLAdd');
iterMax = evalin('base','iterMax');
errorTol = evalin('base','errorTol');
% ==============================================
% ===== PopUp Menu and CheckBox Selections =====
% ==============================================
bType = get(handles.popBottle,'Value'); % Bottle type
wType = get(handles.popWood,'Value'); % Wood type
uH = get(handles.popUnitsHeight,'Value'); % Units: Height
uBL = get(handles.popUnitsBodyLength,'Value'); % Units: Body length
uND = get(handles.popUnitsNeckDiameter,'Value'); % Units: Neck diameter
uNL = get(handles.popUnitsNeckLength,'Value'); % Units: Neck length
uBD = get(handles.popUnitsBaseDiameter,'Value'); % Units: Base diameter
uCGfB = get(handles.popUnitsCGfromBase,'Value'); % Units: CG from base
uWineD = get(handles.popUnitsWineDensity,'Value'); % Units: Wine density
uWineV = get(handles.popUnitsWineVolume,'Value'); % Units: Wine volume
uWoodV = get(handles.popUnitsWoodVolume,'Value'); % Units: Wood volume
uWoodM = get(handles.popUnitsWoodMass,'Value'); % Units: Wood mass
uWoodD = get(handles.popUnitsWoodDensity,'Value'); % Units: Wood density
uWT = get(handles.popUnitsWoodThickness,'Value'); % Units: Wood thickness
uWW = get(handles.popUnitsWoodWidth,'Value'); % Units: Wood width
uAngle = get(handles.popUnitsAngle,'Value'); % Units: Angle w.r.t. table
useMinAngle = get(handles.checkUseMinAngle,'Value'); % FLAG: [1] Use minimum angle
% [0] Do not use minimum angle
showCGPlots = get(handles.checkShowCGPlots,'Value'); % FLAG: [1] Show CG plots on external plot
% [0] Do not show external CG plots
metricUnits = get(handles.checkMetricUnits,'Value'); % FLAG: [1] Show solution using metric units
% [0] Show solution using English units
% =======================================
% ===== GET EVERYTHING READY TO RUN =====
% =======================================
set(handles.editAngle,'BackgroundColor',[1 1 1],...
'ForegroundColor','k');
textInfo = [];
set(handles.textInfo,'String',textInfo);
% ============================
% ===== UNIT CONVERSIONS =====
% ============================
% --- Bottle variables ---
if (uH == 1) % Height
bHeight = bHeight*inchToM; % From [in]
elseif (uH == 2)
bHeight = bHeight*mmToM; % From [mm]
elseif (uH == 3)
bHeight = bHeight*cmToM; % From [cm]
end
if (uBL == 1) % Body length
bLBody = bLBody*inchToM; % From [in]
elseif (uBL == 2)
bLBody = bLBody*mmToM; % From [mm]
elseif (uBL == 3)
bLBody = bLBody*cmToM; % From [cm]
end
if (uND == 1) % Neck diameter
bDNeck = bDNeck*inchToM; % From [in]
elseif (uND == 2)
bDNeck = bDNeck*mmToM; % From [mm]
elseif (uND == 3)
bDNeck = bDNeck*cmToM; % From [cm]
end
if (uNL == 1) % Neck length
bLNeck = bLNeck*inchToM; % From [in]
elseif (uNL == 2)
bLNeck = bLNeck*mmToM; % From [mm]
elseif (uNL == 3)
bLNeck = bLNeck*cmToM; % From [cm]
end
if (uBD == 1) % Base diameter
bDBase = bDBase*inchToM; % From [in]
elseif (uBD == 2)
bDBase = bDBase*mmToM; % From [mm]
elseif (uBD == 3)
bDBase = bDBase*cmToM; % From [cm]
end
if (uCGfB == 1) % CG from Base
bLcg = bLcg*inchToM; % From [in]
elseif (uCGfB == 2)
bLcg = bLcg*mmToM; % From [mm]
elseif (uCGfB == 3)
bLcg = bLcg*cmToM; % From [cm]
end
if (uWineV == 2) % Wine volume
bV = bV*ccToL; % From [cm^3]
end
% --- Wood variables ---
if (get(handles.popWood,'Value') == 5)
% Convert volume and mass
if (uWoodV == 1)
wVolume = wVolume*(inchToM^3);
elseif (uWoodV == 2)
wVolume = (wVolume*mmToM)*(mToInch^3);
elseif (uWoodV == 3)
wVolume = (wVolume*cmToM)*(mToInch^3);
end
if (uWoodM == 2)
wMass = wMass/1000;
elseif (uWoodM == 3)
wMass = wMass*1;
end
% Compute density
wRho = wMass/wVolume;
elseif (get(handles.popWood,'Value') == 6)
% Convert density
if (uWoodD == 2)
wRho = wRho*27679.9; % From [lbm/in^3]
end
end
% --- Run variables ---
if (uWT == 1) % Wood thickness
wT = wT*inchToM; % [in]
elseif (uWT == 2)
wT = wT*mmToM; % [mm]
elseif (uWT == 3)
wT = wT*cmToM; % [cm]
end
if (uWW == 1) % Wood width
wW = wW*inchToM; % [in]
elseif (uWW == 2)
wW = wW*mmToM; % [mm]
elseif (uWW == 3)
wW = wW*cmToM; % [cm]
end
if (uAngle == 2) % Angle w.r.t table
theta = theta*(180/pi); % [rad]
end
% ====================================
% ===== WINE BOTTLE COMPUTATIONS =====
% ====================================
% Calculated
bWShol = (bDBase-bDNeck)/2; % Width of shoulder [m]
bHShol = bHeight-bLBody-bLNeck; % Height of shoulder [m]
bNeckToCG = bHeight-bLcg-(0.5*bLNeck); % Length from neck center to cg [m]
% Mass and weight of the wine bottle
bMass = bRho*bV; % Mass of wine bottle [kg]
bWeight = bMass*9.81; % Weight of wine bottle [N]
% Initial values
bLPivot = 0; % Distance from wine bottle CG to pivot [m]
% ======================================
% ===== MINIMUM ANGLE CALCULATIONS =====
% ======================================
% Extra angles needed
del = 90-theta; % Complementary angle [deg]
oldTheta = theta; % Remember this theta when min angle no checked [deg]
assignin('base','oldTheta',oldTheta); % Needs to be available to checkUseMinAngle
% First computation with smallest possible thickness
num = 0.5*bDBase; % Numerator
den = ((0.5*bLNeck)-(wT/2)) + bHShol; % Denominator
minAngle = atand(num/den); % Initial min angle [deg]
% Recompute with updated thickness based on angle
actualT = (wT/2)/sind(minAngle); % Adjusted thickness
den = ((0.5*bLNeck)-actualT) + bHShol; % Denominator
minAngle = atand(num/den); % Actual min angle [deg]
% If the user wants to use the minimum angle for calculations
if (useMinAngle == 1)
% Set minimum angle [deg]
theta = minAngle;
% Complmentary angle used in computations [deg]
del = 90-theta;
% Set the value in the angle edit text box
set(handles.editAngle,'String',num2str(theta),...
'BackgroundColor','r',...
'ForegroundColor',[1 1 1]);
else
% If the theta requested is smaller than the minimum angle
if (theta < minAngle)
textInfo{1} = 'Angle requested is too small (not possible)!'; % Set the info text
set(handles.textInfo,'String',textInfo); % Make the info text visible in GUI
set(handles.editAngle,'BackgroundColor','r',... % Make the edit text box red to show error
'ForegroundColor',[1 1 1]);
drawnow(); % Make sure everything displays now
return; % Stop running the program
else
end
end
% ==================================
% ===== COMPUTATION ITERATIONS =====
% ==================================
% Clear old data from figure if calculating again
if (showCGPlots == 1)
figure(1);
cla;
end
% Iterative loop to converge on pivot distance
for i = 1:1:iterMax
% For error comparison later (initial value is zero)
% - Initially zero so bottle cg is over base
bLPivotOld = bLPivot;
% Minimum length to have bottle CG over base of wood
wLHole = (bNeckToCG-bLPivot)/sind(del);
if (i == 1)
fprintf('Maximum Board Length: %2.2f [in]\n\n',wLHole*mToInch);
end
% Length adjustements
wL = wLHole + (0.5*bDNeck); % Add half diameter of bottle neck to enclose bottle neck in wood
wL = wL + (pctLAdd/100)*wL; % Add specified percentage to length
wL = wL + (wT/tand(theta)); % Added length due to thickness and angle
% Wood volume
wVolume = wT*wW*wL; % Volume of wood [m^3]
% Calculate mass and weight of wood board
wMass = wRho*wVolume; % Wood mass [kg]
wWeight = wMass*9.81; % Wood weight [N]
% Distance (magnitude) of wood cg to pivot [m]
wLPivot = (wL/2)*cosd(theta);
% Calculate needed distance from bottle cg to pivot [m]
bLPivot = (wWeight*wLPivot)/bWeight;
fprintf('Wood/Bottle Pivot: %2.2f/%2.2f [in]\n',...
wLPivot*mToInch,bLPivot*mToInch);
% Check if new solution is within error tolerance
if (abs(bLPivotOld-bLPivot) <= errorTol)
fprintf('Solution Converged after %i iterations!\n\n',i);
break;
end
% Plot bottle/wood CG distances to show convergence
if (showCGPlots == 1)
figure(1);
subplot(1,2,1);
hold on;
plot(-wLPivot,i,'ko');
axis auto;
title('Wood Board CG');
xlabel('Distance [m]');
ylabel('Iteration []');
subplot(1,2,2);
hold on;
plot(bLPivot,i,'ro');
axis auto;
title('Bottle CG');
xlabel('Distance [m]');
ylabel('Iteration []');
end
end
if (i == iterMax)
fprintf('No solution found!\n');
fprintf('- Increase iterations\n');
fprintf('- Increase error tolerance\n\n');
end
% Compute clearance of bottle and ground
clearance = wLHole*sind(theta)-(0.5*bDBase);
if (clearance <= 0)
fprintf('Bottle will touch the ground!\n\n');
else
fprintf('Clearance : %2.2f [in]\n',clearance*mToInch);
end
% =========================
% ===== HOLE DRILLING =====
% =========================
% Absolute minimum hole diameter
minHoleD = bDNeck;
% Maximum hole diameter (corresponds to flat hole diameter)
a = bDNeck/sind(theta); % Due solely to neck diameter and angle of wood
b = wT/tand(theta); % Due solely to thickness and angle of wood
maxHoleD = a + b; % Addition of both effects
% Range for hole diameters
numHoles = 100;
holeDArr = linspace(minHoleD,maxHoleD,numHoles)';
alpha = zeros(length(holeDArr),1);
beta = zeros(length(holeDArr),1);
% Solve for zero of function to get alpha
for i = 1:1:length(holeDArr)
h = holeDArr(i);
b = bDNeck;
w = wT;
myfun = @(h,w,a,b) (h*sind(a))-(cosd(a)*w)-b;
fun = @(a) myfun(h,w,a,b);
alpha(i) = fzero(fun,0);
beta(i) = 90-alpha(i);
end
assignin('base','beta',beta);
% Convert the hole diameter array to inches