Code covered by the BSD License  

Highlights from
Rigid Body Project

image thumbnail
from Rigid Body Project by Ferat Bulatov
The project demonstrates a rotation of a rigid body about a fixed point. Author: Ferat Talat oglu

RBInputData(varargin)
function varargout = RBInputData(varargin)
% RBINPUTDATA M-file for RBInputData.fig
%      RBINPUTDATA, by itself, creates a new RBINPUTDATA or raises the existing
%      singleton*.
%
%      H = RBINPUTDATA returns the handle to a new RBINPUTDATA or the handle to
%      the existing singleton*.
%
%      RBINPUTDATA('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in RBINPUTDATA.M with the given input arguments.
%
%      RBINPUTDATA('Property','Value',...) creates a new RBINPUTDATA or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before RBInputData_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to RBInputData_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help RBInputData

% Last Modified by GUIDE v2.5 25-Nov-2011 17:31:13

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @RBInputData_OpeningFcn, ...
                   'gui_OutputFcn',  @RBInputData_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


end


% --- Executes just before RBInputData is made visible.
function RBInputData_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 RBInputData (see VARARGIN)
%set(hObject,'KeyPressFcn',@myCallback);
% Choose default command line output for RBInputData
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes RBInputData wait for user response (see UIRESUME)
% uiwait(handles.figure1);

set(handles.popupmenu1, 'Value', 2 )

global st tr

set(handles.edit1,'String','1');
TOP.md = 1; 
set(handles.edit6,'String','1');
TOP.mL = 1; 
set(handles.edit7,'String','2');
TOP.d = 2;
set(handles.edit8,'String','2');
TOP.L = 2; 

TOP.m = 1; 
TOP.a = 2; 
TOP.b = 2;
set(handles.edit9,'String','0.1');
TOP.c = 0.1; 

k =  pi / 180;

set(handles.edit25,'String','30');
TOP.theta = 30 * k;
set(handles.edit26,'String','0');
TOP.phi = 0 * k; 
set(handles.edit27,'String','0');
TOP.psi = 0 * k; 
set(handles.edit34,'String','0');
TOP.dtheta = 0; 
set(handles.edit35,'String','0');
TOP.dphi = 0; 
set(handles.edit36,'String','40');
TOP.dpsi = 40;

TOP.q0 = [ 0, 0, 40 ];

set(handles.edit16,'String','0');
set(handles.edit17,'String','0');
set(handles.edit18,'String','1');

TOP.rc = [ 0, 0, 1 ];
set(handles.edit39,'String','9.81');
TOP.g =  9.81; 

set(handles.edit44,'String','60');
set(handles.edit49,'String','0.001');
TOP.T =  60;
TOP.dt = 0.001;
TOP.n = floor(TOP.T / TOP.dt);

st = set_st(st, TOP );

set(handles.edit40,'String','0');
set(handles.edit41,'String','0');
set(handles.edit42,'String','2');
TR.point = [ 0, 0, 2, 1]';

V(4,TOP.n) = 0;
TR.trajectory = V;

set(handles.edit50,'String','500');
set(handles.edit51,'String','10');

TR.tr_L = 500;
TR.tr_S = 10;

tr = set_tr(tr, TR);

end


function myCallback(src,eventdata)

myhandles = guidata(gcbo);
myhandles.ApplyButton;
set(myhandles.ApplyButton, 'BackgroundColor', [1, 0, 0]);

end


function varargout = RBInputData_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;


 fn = fieldnames(handles);
 
 for k = 1:length(fn)
   if ~ isempty(strfind(fn{k}, 'edit'))
       set(getfield(handles, fn{k}),'KeyPressFcn',@myCallback);       
   end    
 end

% create structure of handles
myhandles = guihandles(handles.figure1); 
% add some additional data
myhandles.ApplyButton = handles.pushbutton2; 
% save the structure
guidata(handles.figure1,myhandles) ;

end



% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu1

function st_switch_at(x)
switch x
    case 'st'
        set(handles.edit9,'Visible', 'off')
        set(handles.text9,'Visible', 'off')        
        set(handles.edit6,'Visible', 'on')
        set(handles.text6,'Visible', 'on')        
        set(handles.text1,'String', 'md')
        set(handles.text7,'String', 'd')
        set(handles.text8,'String', 'L')
    case 'at'
        set(handles.edit9,'Visible', 'on')
        set(handles.text9,'Visible', 'on')        
        set(handles.edit6,'Visible', 'off')
        set(handles.text6,'Visible', 'off')        
        set(handles.text1,'String', 'm')
        set(handles.text7,'String', 'a')
        set(handles.text8,'String', 'b')      
end

end

set_ = [ 2 3 4 8 9 10];

function set_RB(x)
    
    example_ = get_example(x);
    
    if ismember(x, set_)     
        set(handles.edit1,'String',num2str(example_.md));
        set(handles.edit6,'String',num2str(example_.mL));
        set(handles.edit7,'String',num2str(example_.d));
        set(handles.edit8,'String',num2str(example_.L));      
    else
        set(handles.edit1,'String',num2str(example_.m));
        set(handles.edit7,'String',num2str(example_.a));
        set(handles.edit8,'String',num2str(example_.b));
        set(handles.edit9,'String',num2str(example_.c));        
    end
    
    set(handles.edit25,'String',num2str(example_.theta));
    set(handles.edit26,'String',num2str(example_.phi));
    set(handles.edit27,'String',num2str(example_.psi));
    set(handles.edit34,'String',num2str(example_.qx));
    set(handles.edit35,'String',num2str(example_.qy));
    set(handles.edit36,'String',num2str(example_.qz));
    set(handles.edit16,'String',num2str(example_.rx));
    set(handles.edit17,'String',num2str(example_.ry));
    set(handles.edit18,'String',num2str(example_.rz));
    set(handles.edit40,'String',num2str(example_.px));
    set(handles.edit41,'String',num2str(example_.py));
    set(handles.edit42,'String',num2str(example_.pz));
    set(handles.edit44,'String',num2str(example_.T));
    set(handles.edit49,'String',num2str(example_.dt));
    set(handles.edit39,'String',num2str(example_.g));
    set(handles.edit50,'String',num2str(example_.tr_L));
    set(handles.edit51,'String',num2str(example_.tr_S));

end

popup_sel_index = get(handles.popupmenu1, 'Value');

if ismember(popup_sel_index, set_)
            st_switch_at('st');
else
            st_switch_at('at');
end

set_RB(popup_sel_index); 

myhandles = guidata(gcbo);
set(myhandles.ApplyButton, 'BackgroundColor', [1, 0, 0]);
    
end


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global st  at
global tr
global copy_1  copy_2

k =  pi / 180;

TOP.theta = k * str2double(get(handles.edit25,'String')); 
TOP.phi = k * str2double(get(handles.edit26,'String')); 
TOP.psi = k * str2double(get(handles.edit27,'String')); 
TOP.dtheta = str2double(get(handles.edit34,'String')); 
TOP.dphi = str2double(get(handles.edit35,'String')); 
TOP.dpsi = str2double(get(handles.edit36,'String')); 

TOP.rc = [ str2double(get(handles.edit16,'String')),  str2double(get(handles.edit17,'String')),  str2double(get(handles.edit18,'String')) ]; 
TOP.g =  str2double(get(handles.edit39,'String')) ; 

TOP.T =  str2double(get(handles.edit44,'String')) ; 
TOP.dt =  str2double(get(handles.edit49,'String')) ;
TOP.n = floor(TOP.T / TOP.dt);

TOP.md = str2double(get(handles.edit1,'String')); 
TOP.mL = str2double(get(handles.edit6,'String')); 
TOP.d = str2double(get(handles.edit7,'String')); 
TOP.L = str2double(get(handles.edit8,'String')); 

TOP.m = str2double(get(handles.edit1,'String')); 
TOP.a = str2double(get(handles.edit7,'String')); 
TOP.b= str2double(get(handles.edit8,'String')); 
TOP.c = str2double(get(handles.edit9,'String')); 

popup_sel_index = get(handles.popupmenu1, 'Value');

set_ = [ 2 3 4 8 9 10 ];
if ismember(popup_sel_index, set_)
            st = set_st(st, TOP );
            copy_1 = st;
else
            at = set_at(at, TOP );
            copy_1 = at;
end

if isobject(copy_2) && ( isequal(get_rb(copy_1,'all_recalculation_need'),...
         get_rb(copy_2,'all_recalculation_need')) )    
else
    handle_1 = findobj('UserData','Calculate');
    set(handle_1, 'BackgroundColor', [1 0 0] );
    handle_2 = findobj('UserData','Done');
    set(handle_2, 'String', '' );
end

copy_2= copy_1;

TR.point = [ str2double(get(handles.edit40,'String')),  str2double(get(handles.edit41,'String')),  str2double(get(handles.edit42,'String')), 1 ]'; 
V(4,TOP.n) = 0;
TR.trajectory = V;

TR.tr_L = str2double(get(handles.edit50,'String')); 
TR.tr_S = str2double(get(handles.edit51,'String')); 

tr = set_tr(tr, TR);

set(get(RBInterface,'CurrentAxes'), 'xlim', [-2 2] );
set(get(RBInterface,'CurrentAxes'), 'ylim', [-2 2] );
set(get(RBInterface,'CurrentAxes'), 'zlim', [-3 3] );

text(-0.1, 0 ,'#','Color','black');

myhandles = guidata(gcbo);
set(myhandles.ApplyButton, 'BackgroundColor', [1, 1, 1]);

end


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

open('List_of_symbols.html');

end


function edit25_Callback(hObject, eventdata, handles)
% hObject    handle to edit25 (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 edit25 as text
%        str2double(get(hObject,'String')) returns contents of edit25 as a double

str = get(hObject,'String');

[x status] = str2num(str);

handle_ = findobj('UserData','Calculate');

if status == 0
    msgbox('Only numbers are alowed.', 'RBMessage', 'modal');  
    set(hObject,'BackgroundColor','Red');
    set(handle_, 'Enable', 'off');    
    set(handles.pushbutton2, 'Enable', 'off');    
else
    set(hObject,'BackgroundColor','White');  
    set(handle_, 'Enable', 'on');
    set(handles.pushbutton2, 'Enable', 'on');    
end

end



function edit49_Callback(hObject, eventdata, handles)
% hObject    handle to edit49 (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 edit49 as text
%        str2double(get(hObject,'String')) returns contents of edit49 as a double

str = get(hObject,'String');

[x status] = str2num(str);

handle_ = findobj('UserData','Calculate');

if status == 0
    msgbox('Only numbers are alowed.', 'RBMessage', 'modal');  
    set(hObject,'BackgroundColor','Red');
    set(handle_, 'Enable', 'off');    
    set(handles.pushbutton2, 'Enable', 'off');    
else
    if abs(x) > 0.1 || x<=0
        msgbox('dt must be positive and less than 0.1 ', 'RBMessage', 'modal');  
        set(hObject,'BackgroundColor','Red');
        set(handle_, 'Enable', 'off');    
        set(handles.pushbutton2, 'Enable', 'off');    
    else
        set(hObject,'BackgroundColor','White');  
        set(handle_, 'Enable', 'on');
        set(handles.pushbutton2, 'Enable', 'on');    
    end

end

end



function edit44_Callback(hObject, eventdata, handles)
% hObject    handle to edit44 (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 edit44 as text
%        str2double(get(hObject,'String')) returns contents of edit44 as a double
str = get(hObject,'String');

[x status] = str2num(str);

handle_ = findobj('UserData','Calculate');

if status == 0
    msgbox('Only numbers are alowed.', 'RBMessage', 'modal');  
    set(hObject,'BackgroundColor','Red');
    set(handle_, 'Enable', 'off');    
    set(handles.pushbutton2, 'Enable', 'off');    
else
    if  x<=0
        msgbox('T must be positive', 'RBMessage', 'modal');  
        set(hObject,'BackgroundColor','Red');
        set(handle_, 'Enable', 'off');    
        set(handles.pushbutton2, 'Enable', 'off');    
    else
        set(hObject,'BackgroundColor','White');  
        set(handle_, 'Enable', 'on');
        set(handles.pushbutton2, 'Enable', 'on');    
    end

end


end


Contact us