function varargout = RR(varargin)
% RR MATLAB code for RR.fig
%      RR, by itself, creates a new RR or raises the existing
%      singleton*.
%
%      H = RR returns the handle to a new RR or the handle to
%      the existing singleton*.
%
%      RR('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in RR.M with the given input arguments.
%
%      RR('Property','Value',...) creates a new RR or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before RR_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to RR_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 RR

% Last Modified by GUIDE v2.5 22-Dec-2013 14:14:22

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @RR_OpeningFcn, ...
                   'gui_OutputFcn',  @RR_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 RR is made visible.
function RR_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 RR (see VARARGIN)

% Choose default command line output for RR
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);
axis([-15 15 -15 15])
hold on
% slider_step = [5 10];
set(handles.Theta11,'max',180,'min',0,'value',90);
set(handles.Theta21,'max',180,'min',0,'value',90);
set(handles.P11,'max',10,'min',0,'value',5);
a=[0 0];
theta11=get(handles.Theta11,'Value');
theta21=get(handles.Theta21,'Value');
d11=get(handles.P11,'Value');
a11=5;
a21=6;
xe=a(1)+(a11*cos(theta11*(pi/180)))+((a21+d11)*cos(theta21*(pi/180)));
ye=a(2)+(a11*sin(theta11*(pi/180)))+((a21+d11)*sin(theta21*(pi/180)));
cla;
plot([a(1) (a11*cos(theta11*(pi/180))) xe],[a(2) (a11*sin(theta11*(pi/180))) ye])



% UIWAIT makes RR wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = RR_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;


% --- Executes on slider movement.
function Theta11_Callback(hObject, eventdata, handles)
% hObject    handle to Theta11 (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% axis([-50 50 -50 50])
% hold
a=[0 0];
theta11=get(handles.Theta11,'Value')
% set(handles.Theta11_Display,'string',double2str(theta11));
% while theta21==90 do
    
theta21=get(handles.Theta21,'Value')
d11=get(handles.P11,'Value')
    
    % end

% set(handles.Theta21_Display,'string',double2str(theta21));
a11=5;
a21=6;
xe=a(1)+(a11*cos(theta11*(pi/180)))+((a21+d11)*cos(theta21*(pi/180)));
ye=a(2)+(a11*sin(theta11*(pi/180)))+((a21+d11)*sin(theta21*(pi/180)));
cla;
plot([a(1) (a11*cos(theta11*(pi/180))) xe],[a(2) (a11*sin(theta11*(pi/180))) ye])


% --- Executes during object creation, after setting all properties.
function Theta11_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Theta11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function Theta21_Callback(hObject, eventdata, handles)
% hObject    handle to Theta21 (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% axis([-50 50 -50 50])
% hold
a=[0 0];
theta11=get(handles.Theta11,'Value')
% set(handles.Theta11_Display,'string',double2str(theta11));
theta21=get(handles.Theta21,'Value')
d11=get(handles.P11,'Value')
% set(handles.Theta21_Display,'string',double2str(theta21));
a11=5;
a21=6;
xe=a(1)+(a11*cos(theta11*(pi/180)))+((a21+d11)*cos(theta21*(pi/180)));
ye=a(2)+(a11*sin(theta11*(pi/180)))+((a21+d11)*sin(theta21*(pi/180)));
cla;
plot([a(1) (a11*cos(theta11*(pi/180))) xe],[a(2) (a11*sin(theta11*(pi/180))) ye])

% --- Executes during object creation, after setting all properties.
function Theta21_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Theta21 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes during object creation, after setting all properties.
function Theta11_Display_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Theta11_Display (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called



% --- Executes during object creation, after setting all properties.
function Theta21_Display_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Theta21_Display (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called




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




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


% --- Executes on slider movement.
function P11_Callback(hObject, eventdata, handles)
% hObject    handle to P11 (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
a=[0 0];
theta11=get(handles.Theta11,'Value')
% set(handles.Theta11_Display,'string',double2str(theta11));
% while theta21==90 do
    
theta21=get(handles.Theta21,'Value')
d11=get(handles.P11,'Value')
    
    % end

% set(handles.Theta21_Display,'string',double2str(theta21));
a11=5;
a21=6;
xe=a(1)+(a11*cos(theta11*(pi/180)))+((a21+d11)*cos(theta21*(pi/180)));
ye=a(2)+(a11*sin(theta11*(pi/180)))+((a21+d11)*sin(theta21*(pi/180)));
cla;
plot([a(1) (a11*cos(theta11*(pi/180))) xe],[a(2) (a11*sin(theta11*(pi/180))) ye])


% --- Executes during object creation, after setting all properties.
function P11_CreateFcn(hObject, eventdata, handles)
% hObject    handle to P11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end
