function varargout = nma_lab3_eme_121(varargin) %main GUI file for lab3 MAE 121, UC Davis % NMA_LAB3_EME_121 MATLAB code for nma_lab3_eme_121.fig % NMA_LAB3_EME_121, by itself, creates a new NMA_LAB3_EME_121 or raises the existing % singleton*. % % H = NMA_LAB3_EME_121 returns the handle to a new NMA_LAB3_EME_121 or the handle to % the existing singleton*. % % NMA_LAB3_EME_121('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in NMA_LAB3_EME_121.M with the given input arguments. % % NMA_LAB3_EME_121('Property','Value',...) creates a new NMA_LAB3_EME_121 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before nma_lab3_eme_121_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to nma_lab3_eme_121_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % this is the GUI main line for EME 121 lab 3 % by Nasser M. Abbasi % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help nma_lab3_eme_121 % Last Modified by GUIDE v2.5 18-Jul-2012 18:18:50 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @nma_lab3_eme_121_OpeningFcn, ... 'gui_OutputFcn', @nma_lab3_eme_121_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 nma_lab3_eme_121 is made visible. function nma_lab3_eme_121_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to nma_lab3_eme_121 (see VARARGIN) % Choose default command line output for nma_lab3_eme_121 handles.output = hObject; set(handles.figure1, 'UserData',[]); set(handles.figure1,'Name','UC Davis, EME 121 lab#3, by Nasser M. Abbasi'); userData.stop = false; set(handles.figure1, 'UserData',userData); % Update handles structure guidata(hObject, handles); % UIWAIT makes nma_lab3_eme_121 wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = nma_lab3_eme_121_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; function mfwTag_Callback(hObject, eventdata, handles) % hObject handle to mfwTag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of mfwTag as text % str2double(get(hObject,'String')) returns contents of mfwTag as a double % --- Executes during object creation, after setting all properties. function mfwTag_CreateFcn(hObject, eventdata, handles) % hObject handle to mfwTag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function fTag_Callback(hObject, eventdata, handles) % hObject handle to fTag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of fTag as text % str2double(get(hObject,'String')) returns contents of fTag as a double % --- Executes during object creation, after setting all properties. function fTag_CreateFcn(hObject, eventdata, handles) % hObject handle to fTag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function zetaTag_Callback(hObject, eventdata, handles) % hObject handle to zetaTag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of zetaTag as text % str2double(get(hObject,'String')) returns contents of zetaTag as a double % --- Executes during object creation, after setting all properties. function zetaTag_CreateFcn(hObject, eventdata, handles) % hObject handle to zetaTag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function torqueTag_Callback(hObject, eventdata, handles) % hObject handle to torqueTag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of torqueTag as text % str2double(get(hObject,'String')) returns contents of torqueTag as a double % --- Executes during object creation, after setting all properties. function torqueTag_CreateFcn(hObject, eventdata, handles) % hObject handle to torqueTag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function rpmTag_Callback(hObject, eventdata, handles) % hObject handle to rpmTag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of rpmTag as text % str2double(get(hObject,'String')) returns contents of rpmTag as a double % --- Executes during object creation, after setting all properties. function rpmTag_CreateFcn(hObject, eventdata, handles) % hObject handle to rpmTag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in runBtn. function runBtn_Callback(hObject, eventdata, handles) % hObject handle to runBtn (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) userData = get(handles.figure1, 'UserData'); userData.stop = false; set(handles.figure1, 'UserData',userData); data.angleInitial=(pi/2)/180; data.angleSpeedInitial=0; data.M=str2num(get(handles.mfwTag,'String')); data.volumeOfCylinder=500*0.000001 ; %convery cc to m^3 data.Dp=3*.0254; data.Ap=(pi/4)*data.Dp^2; data.stroke=data.volumeOfCylinder/data.Ap; data.R=data.stroke/2; data.L=3*data.R; data.I=data.M*data.R^2/2; set(handles.Itag,'String',sprintf('%3.3f',data.I)); data.m=0.25*data.I/data.R^2; set(handles.pistonMassTag,'String',sprintf('%3.3f',data.m)); data.f=str2num(get(handles.fTag,'String')); set(handles.pistonFreqTag,'String',sprintf('%3.3f',data.f)); data.omega=2*pi*data.f; set(handles.pistonWnTag,'String',sprintf('%3.3f',data.omega)); data.dampingRatio=str2num(get(handles.zetaTag,'String')); data.k=data.m*data.omega^2; set(handles.kTag,'String',sprintf('%3.3f',data.k)); data.b=2*data.dampingRatio*data.omega*data.m; set(handles.bTag,'String',sprintf('%3.3f',data.b)); data.torque = str2num(get(handles.torqueTag,'String')); data.maxRPM=str2num(get(handles.rpmTag,'String')); data.maxSimulationTime=str2num(get(handles.simTimeTag,'String')); data.handles=handles; data.currentAngle=data.angleInitial; data.minY=0; data.maxY=4; [g_msg,g_status]=nma_lab3_eme_121(data); % --- Executes on button press in stopTag. function stopTag_Callback(hObject, eventdata, handles) % hObject handle to stopTag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) userData = get(handles.figure1, 'UserData'); userData.stop = true; set(handles.figure1, 'UserData',userData); %enable_all(handles,'on'); function simTimeTag_Callback(hObject, eventdata, handles) % hObject handle to simTimeTag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of simTimeTag as text % str2double(get(hObject,'String')) returns contents of simTimeTag as a double % --- Executes during object creation, after setting all properties. function simTimeTag_CreateFcn(hObject, eventdata, handles) % hObject handle to simTimeTag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit7_Callback(hObject, eventdata, handles) % hObject handle to edit7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit7 as text % str2double(get(hObject,'String')) returns contents of edit7 as a double % --- Executes during object creation, after setting all properties. function edit7_CreateFcn(hObject, eventdata, handles) % hObject handle to edit7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit8_Callback(hObject, eventdata, handles) % hObject handle to edit8 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit8 as text % str2double(get(hObject,'String')) returns contents of edit8 as a double % --- Executes during object creation, after setting all properties. function edit8_CreateFcn(hObject, eventdata, handles) % hObject handle to edit8 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit9_Callback(hObject, eventdata, handles) % hObject handle to edit9 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit9 as text % str2double(get(hObject,'String')) returns contents of edit9 as a double % --- Executes during object creation, after setting all properties. function edit9_CreateFcn(hObject, eventdata, handles) % hObject handle to edit9 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit10_Callback(hObject, eventdata, handles) % hObject handle to edit10 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit10 as text % str2double(get(hObject,'String')) returns contents of edit10 as a double % --- Executes during object creation, after setting all properties. function edit10_CreateFcn(hObject, eventdata, handles) % hObject handle to edit10 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit11_Callback(hObject, eventdata, handles) % hObject handle to edit11 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit11 as text % str2double(get(hObject,'String')) returns contents of edit11 as a double % --- Executes during object creation, after setting all properties. function edit11_CreateFcn(hObject, eventdata, handles) % hObject handle to edit11 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit12_Callback(hObject, eventdata, handles) % hObject handle to edit12 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit12 as text % str2double(get(hObject,'String')) returns contents of edit12 as a double % --- Executes during object creation, after setting all properties. function edit12_CreateFcn(hObject, eventdata, handles) % hObject handle to edit12 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function Itag_Callback(hObject, eventdata, handles) % hObject handle to Itag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of Itag as text % str2double(get(hObject,'String')) returns contents of Itag as a double % --- Executes during object creation, after setting all properties. function Itag_CreateFcn(hObject, eventdata, handles) % hObject handle to Itag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function pistonMassTag_Callback(hObject, eventdata, handles) % hObject handle to pistonMassTag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of pistonMassTag as text % str2double(get(hObject,'String')) returns contents of pistonMassTag as a double % --- Executes during object creation, after setting all properties. function pistonMassTag_CreateFcn(hObject, eventdata, handles) % hObject handle to pistonMassTag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function pistonFreqTag_Callback(hObject, eventdata, handles) % hObject handle to pistonFreqTag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of pistonFreqTag as text % str2double(get(hObject,'String')) returns contents of pistonFreqTag as a double % --- Executes during object creation, after setting all properties. function pistonFreqTag_CreateFcn(hObject, eventdata, handles) % hObject handle to pistonFreqTag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function pistonWnTag_Callback(hObject, eventdata, handles) % hObject handle to pistonWnTag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of pistonWnTag as text % str2double(get(hObject,'String')) returns contents of pistonWnTag as a double % --- Executes during object creation, after setting all properties. function pistonWnTag_CreateFcn(hObject, eventdata, handles) % hObject handle to pistonWnTag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function kTag_Callback(hObject, eventdata, handles) % hObject handle to kTag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of kTag as text % str2double(get(hObject,'String')) returns contents of kTag as a double % --- Executes during object creation, after setting all properties. function kTag_CreateFcn(hObject, eventdata, handles) % hObject handle to kTag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function bTag_Callback(hObject, eventdata, handles) % hObject handle to bTag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of bTag as text % str2double(get(hObject,'String')) returns contents of bTag as a double % --- Executes during object creation, after setting all properties. function bTag_CreateFcn(hObject, eventdata, handles) % hObject handle to bTag (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end