function varargout = GUI_IO_ASSERV_4(varargin) % GUI_IO_ASSERV_4 MATLAB code for GUI_IO_ASSERV_4.fig % GUI_IO_ASSERV_4, by itself, creates a new GUI_IO_ASSERV_4 or raises the existing % singleton*. % % H = GUI_IO_ASSERV_4 returns the handle to a new GUI_IO_ASSERV_4 or the handle to % the existing singleton*. % % GUI_IO_ASSERV_4('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in GUI_IO_ASSERV_4.M with the given input arguments. % % GUI_IO_ASSERV_4('Property','Value',...) creates a new GUI_IO_ASSERV_4 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before GUI_IO_ASSERV_4_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to GUI_IO_ASSERV_4_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 GUI_IO_ASSERV_4 % Last Modified by GUIDE v2.5 06-Apr-2022 17:21:44 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @GUI_IO_ASSERV_4_OpeningFcn, ... 'gui_OutputFcn', @GUI_IO_ASSERV_4_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_IO_ASSERV_4 is made visible. function GUI_IO_ASSERV_4_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 GUI_IO_ASSERV_4 (see VARARGIN) % Choose default command line output for GUI_IO_ASSERV_4 handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes GUI_IO_ASSERV_4 wait for user response (see UIRESUME) % uiwait(handles.figure1); % /!\ A ETE AJOUTE /!\ global nucleo % prend la variable "nucleo" comme "global" à utiliser le long du code nucleo = serialport('COM8', 115200); % il faudra choisir le bon port. Le deuxième paramètre correspond au BaudRate usuel % --- Outputs from this function are returned to the command line. function varargout = GUI_IO_ASSERV_4_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 choix_Kp_Callback(hObject, eventdata, handles) % hObject handle to choix_Kp (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 choix_Kp as text % str2double(get(hObject,'String')) returns contents of choix_Kp as a double % /!\ A ETE AJOUTE /!\ handles.dataKp = get(hObject,'String'); % récupère au format String la donnée utilisateur handles.KpSamples = str2double(handles.dataKp); % convertit la donnée utilisateur au format Double à renvoyer sur la carte Nucleo guidata(hObject, handles); % même chose pour les autres handles.data de la suite du code % --- Executes during object creation, after setting all properties. function choix_Kp_CreateFcn(hObject, eventdata, handles) % hObject handle to choix_Kp (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 choix_Ki_Callback(hObject, eventdata, handles) % hObject handle to choix_Ki (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 choix_Ki as text % str2double(get(hObject,'String')) returns contents of choix_Ki as a double % % /!\ A ETE AJOUTE /!\ handles.dataKi = get(hObject,'String'); handles.KiSamples = str2double(handles.dataKi); guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function choix_Ki_CreateFcn(hObject, eventdata, handles) % hObject handle to choix_Ki (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 choix_Kd_Callback(hObject, eventdata, handles) % hObject handle to choix_Kd (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 choix_Kd as text % str2double(get(hObject,'String')) returns contents of choix_Kd as a double % % /!\ A ETE AJOUTE /!\ handles.dataKd = get(hObject,'String'); handles.KdSamples = str2double(handles.dataKd); guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function choix_Kd_CreateFcn(hObject, eventdata, handles) % hObject handle to choix_Kd (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 simulate_position. function simulate_position_Callback(hObject, eventdata, handles) % hObject handle to simulate_position (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % /!\ A ETE AJOUTE /!\ % Pour renvoyer sur la carte Nucléo str = sprintf("%f,%f,%f,%f,%f,0",handles.KpSamples,handles.KiSamples,handles.KdSamples,handles.cxSamples,handles.cySamples); % renvoie les donnes utilisateurs sur la carte Nucleo. Le 0 constitue un % booléen qui différencie entre les deux types de simulation global nucleo % il faut remettre "nucleo" en variable globale dans la fonction du bouton writeline(nucleo,str) % écrit sur la carte Nucleo les valeurs utilisateur, ensuite séparées par la carte. % Pour la position du laser cla(handles.axes1) % permet de mettre le tracé sur le graphe dont le tag est (changeable sur la figure) axes1 viscircles(handles.axes1,[0 0],0.005) % trace le cercle sur lequel on représente la position du laser ph = animatedline(handles.axes1,'Marker','o','Color','b'); % permet d'animer la position du laser en temps réel hold on xlim([-0.005 0.005]) ylim([-0.005 0.005]) k = 0; while true % boucle infinie data = readline(nucleo); % lit la tension, donc la position du laser sur la photodiode if mod(k,50) == 0 clearpoints(ph) % pour éviter d'avoir un grand nombre de lignes qui décrivaient la position du laser end try data = double(split(data,","))'; % permet de séparer les valeurs de positions en x et y fournit par la carte Nucleo clearpoints(ph) addpoints(ph,data(1),data(2)); drawnow limitrate; k = k+1; end end function consx_Callback(hObject, eventdata, handles) % hObject handle to consx (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 consx as text % str2double(get(hObject,'String')) returns contents of consx as a double % % /!\ A ETE AJOUTE /!\ handles.datacx = get(hObject,'String'); handles.cxSamples = str2double(handles.datacx); guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function consx_CreateFcn(hObject, eventdata, handles) % hObject handle to consx (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 consy_Callback(hObject, eventdata, handles) % hObject handle to consy (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 consy as text % str2double(get(hObject,'String')) returns contents of consy as a double % /!\ A ETE AJOUTE /!\ handles.datacy = get(hObject,'String'); handles.cySamples = str2double(handles.datacy); guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function consy_CreateFcn(hObject, eventdata, handles) % hObject handle to consy (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 Te_Callback(hObject, eventdata, handles) % hObject handle to Te (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 Te as text % str2double(get(hObject,'String')) returns contents of Te as a double % /!\ A ETE AJOUTE /!\ handles.dataTe = get(hObject,'String'); handles.TeSamples = str2double(handles.dataTe); guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function Te_CreateFcn(hObject, eventdata, handles) % hObject handle to Te (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 simulate_tensions. function simulate_tensions_Callback(hObject, eventdata, handles) % hObject handle to simulate_tensions (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Pour renvoyer sur la carte Nucléo str = sprintf("%f,%f,%f,%f,%f,1",handles.KpSamples,handles.KiSamples,handles.KdSamples,handles.cxSamples,handles.cySamples); global nucleo writeline(nucleo,str) % renvoie les donnes utilisateurs sur la carte Nucleo. Le 1 constitue un % booléen qui différencie entre les deux types de simulation % Pour les graphes des tensions cla(handles.axesA) % permet de mettre le tracé sur le graphe dont le tag est (changeable sur la figure) axesA cla(handles.axesB) cla(handles.axesC) cla(handles.axesD) A = animatedline(handles.axesA,'Color','r'); % pour l'animation des tensions, les avoir en temps réel ylim(handles.axesA,[0 1]) % le premier paramètre est pour mettre tracé sur le graphe dont le tag est (changeable sur la figure) axesA, le second correspond au fait qu'on prend les tensions normalisées B = animatedline(handles.axesB,'Color','r'); ylim(handles.axesB,[0 1]) D = animatedline(handles.axesC,'Color','r'); ylim(handles.axesC,[0 1]) C = animatedline(handles.axesD,'Color','r'); ylim(handles.axesD,[0 1]) k = 0; while true data = readline(nucleo); try data = double(split(data,","))'; addpoints(A,k*handles.TeSamples,data(1)); addpoints(B,k*handles.TeSamples,data(2)); addpoints(C,k*handles.TeSamples,data(3)); addpoints(D,k*handles.TeSamples,data(4)); drawnow limitrate; end k = k+1; end