MACCHINA UNIVERSALE DI TRAZIONE – ACQUISIZIONE MISURE

Le macchine universali presenti nei laboratori di tecnologia presentano un sistema geniale per la registrazione della curva di trazione su di un supporto cartaceo. L’asse degli allungamenti viene percorso dalla matita facendo ruotare un rullo. Il rullo è collegato tramite una puleggia ed una funicella al telaio che allunga il provino. Lo spostamento della matita lungo l’asse delle forze avviene con un asta che è collegata tramite un pignoncino del dinamometro. L’unico punto debole in questo sistema è proprio il pennino o la matita che viene premuta sul rotolo di carta millimetrata. Con due trasduttori elettronici ed un convertitore di segnale da analogico a digitale è possibile acquisire direttamente le due grandezze forza e allungamento  
  1. % Autori
  2. % Prof. Paolo Sordi IPSIA A. Pacinotti, Pontedera (Pisa)
  3. % Prof. Danilo Pasquini IPSIA Paolo Parodi Delfino, Colleferro (Roma)
  4. %
  5. function varargout = trazione(varargin)
  6. % TRAZIONE M-file for trazione.fig
  7. %      TRAZIONE, by itself, creates a new TRAZIONE or raises the existing
  8. %      singleton*.
  9. %
  10. %      H = TRAZIONE returns the handle to a new TRAZIONE or the handle to
  11. %      the existing singleton*.
  12. %
  13. %      TRAZIONE('CALLBACK',hObject,eventData,handles,...) calls the local
  14. %      function named CALLBACK in TRAZIONE.M with the given input arguments.
  15. %
  16. %      TRAZIONE('Property','Value',...) creates a new TRAZIONE or raises
  17. %      the
  18. %      existing singleton*.  Starting from the left, property value pairs are
  19. %      applied to the GUI before trazione_OpeningFunction gets called.  An
  20. %      unrecognized property name or invalid value makes property application
  21. %      stop.  All inputs are passed to trazione_OpeningFcn via varargin.
  22. %
  23. %      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
  24. %      instance to run (singleton)".
  25. %
  26. % See also: GUIDE, GUIDATA, GUIHANDLES
  27.  
  28. % Edit the above text to modify the response to help trazione
  29.  
  30. % Last Modified by GUIDE v2.5 20-Sep-2011 13:20:03
  31.  
  32. % Begin initialization code - DO NOT EDIT
  33. gui_Singleton = 1;
  34. gui_State = struct('gui_Name',       mfilename, ...
  35.                    'gui_Singleton',  gui_Singleton, ...
  36.                    'gui_OpeningFcn', @trazione_OpeningFcn, ...
  37.                    'gui_OutputFcn',  @trazione_OutputFcn, ...
  38.                    'gui_LayoutFcn',  [] , ...
  39.                    'gui_Callback',   []);
  40. if nargin && ischar(varargin{1})
  41.     gui_State.gui_Callback = str2func(varargin{1});
  42. end
  43. if nargout
  44.     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  45. else
  46.     gui_mainfcn(gui_State, varargin{:});
  47. end
  48. % End initialization code - DO NOT EDIT
  49.  
  50.  
  51. % --- Executes just before trazione is made visible.
  52. function trazione_OpeningFcn(hObject, eventdata, handles, varargin)
  53. % This function has no output args, see OutputFcn.
  54. % hObject    handle to figure
  55. % eventdata  reserved - to be defined in a future version of MATLAB
  56. % handles    structure with handles and user data (see GUIDATA)
  57. % varargin   command line arguments to trazione (see VARARGIN)
  58.  
  59. % Choose default command line output for trazione
  60. handles.output = hObject;
  61.  
  62. % Update handles structure
  63. guidata(hObject, handles);
  64.  
  65. % UIWAIT makes trazione wait for user response (see UIRESUME)
  66. % uiwait(handles.figure1);
  67.  
  68.  
  69.  
  70. % --- Executes on button press in pushbutton1.
  71. function pushbutton1_Callback(hObject, eventdata, handles)
  72. % hObject    handle to pushbutton1 (see GCBO)
  73. % eventdata  reserved - to be defined in a future version of MATLAB
  74. % handles    structure with handles and user data (see GUIDATA)
  75. global reset_lunghezza
  76. global reset_forza
  77. spegni_tutti_i_pulsanti (handles)
  78. set(handles.pushbutton7,'Enable','on');
  79. set(handles.pushbutton4,'Enable','on');
  80. [forza,lunghezza] = preleva_segnali(handles)
  81. save lunghezza lunghezza
  82. reset_lunghezza = lunghezza;
  83. reset_forza = forza;
  84. set(handles.edit23,'String',num2str(reset_lunghezza));
  85. set(handles.edit22,'String',num2str(reset_forza));
  86.  
  87.  
  88.  
  89. % --- Executes on button press in pushbutton4.
  90. function pushbutton4_Callback(hObject, eventdata, handles)
  91. % hObject    handle to pushbutton4 (see GCBO)
  92. % eventdata  reserved - to be defined in a future version of MATLAB
  93. % handles    structure with handles and user data (see GUIDATA)
  94. global s
  95. global continua_accendi
  96. global vettore_lunghezze
  97. global vettore_forze
  98. global vettore_lunghezze_bit
  99. global vettore_forze_bit
  100. global vettore_tempi 
  101. global continua_acquisizione
  102. spegni_tutti_i_pulsanti (handles)
  103. set(handles.pushbutton5,'Enable','on');
  104. axes(handles.axes3)
  105. cla
  106. continua_accendi = 0;
  107. pause(1)
  108. vettore_lunghezze = [];
  109. vettore_forze = [];
  110. vettore_lunghezze_bit = [];
  111. vettore_forze_bit = [];
  112. vettore_tempi =[];
  113. %vettore_lunghezze (1) = 0;
  114. %vettore_forze (1) = 0 ;
  115. %vettore_tempi (1) = 0;
  116. tic
  117. reset_forza = str2num(get (handles.edit22,'String'))
  118. reset_lunghezza = str2num(get (handles.edit23,'String'))
  119. coefficiente_lunghezza = str2num(get (handles.edit17,'String'))
  120. coefficiente_forza = str2num(get (handles.edit18,'String'))
  121. continua_acquisizione = 1;
  122. while (continua_acquisizione)
  123.     [forza,lunghezza] = preleva_segnali(handles)
  124.       vettore_lunghezze_bit (end+1) = lunghezza ; 
  125.     vettore_forze_bit (end+1) = forza ;
  126.     X_LUN= (lunghezza- reset_lunghezza)*coefficiente_lunghezza
  127.     X_FOR= (forza- reset_forza)*coefficiente_forza
  128.     vettore_lunghezze (end+1) = (X_LUN); 
  129.     vettore_forze (end+1) = (X_FOR);
  130.     vettore_tempi (end+1) = toc;
  131.     tic
  132.     axes(handles.axes3)
  133.         plot (vettore_lunghezze,vettore_forze)
  134.         grid
  135.         xlabel('Delta L [mm]')
  136.         ylabel('Forza [N]')
  137.     drawnow
  138. %      tic
  139. %      while (toc<1)
  140. %      end
  141. end
  142.  
  143. % --- Executes on button press in pushbutton5.
  144. function pushbutton5_Callback(hObject, eventdata, handles)
  145. % hObject    handle to pushbutton5 (see GCBO)
  146. % eventdata  reserved - to be defined in a future version of MATLAB
  147. % handles    structure with handles and user data (see GUIDATA)
  148. global vettore_lunghezze
  149. global vettore_forze
  150. global vettore_lunghezze_bit
  151. global vettore_forze_bit
  152. global vettore_tempi 
  153. global continua_acquisizione
  154. spegni_tutti_i_pulsanti (handles)
  155. set(handles.pushbutton6,'Enable','on');
  156. continua_acquisizione = 0;
  157. cartella_esperimento = [date ' ' num2str(ceil(rand*1000000))] 
  158. direttorio = cd
  159. mkdir (cartella_esperimento) 
  160. cd (cartella_esperimento)
  161. lunghezza_matrice = length(vettore_tempi)
  162. coefficiente_lunghezza = str2num (get(handles.edit17,'String'));
  163. coefficiente_forza = str2num (get(handles.edit18,'String'));
  164. reset_lunghezza = str2num (get(handles.edit23,'String'));
  165. reset_forza = str2num (get(handles.edit22,'String'));
  166. sezione = str2num (get(handles.edit29,'String'));
  167. lunghezza = str2num (get(handles.edit32,'String'));
  168. matrice_excel  = cell (lunghezza_matrice+20,30);
  169. matrice_excel {1,1} = 't[s]';
  170. matrice_excel {1,2} = 'F[bit]';
  171. matrice_excel {1,3} = 'L[bit]';
  172. matrice_excel {1,5} = 'F[N]';
  173. matrice_excel {1,7} = 'Delta L[mm]';
  174. matrice_excel {1,10} = 'Sigma[N/mm²]';
  175. matrice_excel {1,12} = 'Epsilon[]';
  176. matrice_excel {1,6} = 'coeff. lunghezza';
  177. matrice_excel {2,6} = coefficiente_lunghezza;
  178. matrice_excel {3,6} = 'reset lunghezza';
  179. matrice_excel {4,6} = reset_lunghezza;
  180. matrice_excel {1,4} = 'coeff. forza';
  181. matrice_excel {2,4} = coefficiente_forza;
  182. matrice_excel {3,4} = 'reset forza';
  183. matrice_excel {4,4} = reset_forza;
  184. matrice_excel {3,9} = 'Sezione[mm²]';
  185. matrice_excel {4,9} = sezione;
  186. matrice_excel {3,11} = 'Lunghezza[mm]';
  187. matrice_excel {4,11} = lunghezza;
  188. for i=1:lunghezza_matrice
  189.     matrice_excel {i+10,1} = vettore_tempi(i);
  190.     matrice_excel {i+10,2} = vettore_forze_bit(i) ;
  191.     matrice_excel {i+10,3} = vettore_lunghezze_bit(i);
  192. end
  193. xlswrite('Dati_prova_solo_bit.xls', matrice_excel,'Trazione','A3')
  194. for i=1:lunghezza_matrice
  195.     matrice_excel {i+10,5} = vettore_forze(i);
  196.     matrice_excel {i+10,7} = vettore_lunghezze(i);
  197. end
  198. xlswrite('Dati_prova_solo_bit_forza_lunghezze.xls', matrice_excel,'Trazione','A3')
  199. for i=1:lunghezza_matrice
  200.     matrice_excel {i+10,10} = vettore_forze(i) / sezione;
  201.     matrice_excel {i+10,12} = vettore_lunghezze(i) / lunghezza;
  202. end
  203. save dati_esperimenti
  204. xlswrite('Dati_prova_completo.xls', matrice_excel,'Trazione','A3')
  205. cd (direttorio)
  206. pushbutton7_Callback(hObject, eventdata, handles)
  207. comando = ['explorer ' cartella_esperimento]
  208. dos(comando)
  209.  
  210.  
  211. % --- Executes on button press in pushbutton6.
  212. function pushbutton6_Callback(hObject, eventdata, handles)
  213. % hObject    handle to pushbutton6 (see GCBO)
  214. % eventdata  reserved - to be defined in a future version of MATLAB
  215. % handles    structure with handles and user data (see GUIDATA)
  216. global s
  217. global continua_accendi
  218. global vettore_lunghezze_ADC
  219. global vettore_forze_ADC
  220. global lunghezza_vettore
  221. spegni_tutti_i_pulsanti (handles)
  222. set(handles.pushbutton7,'Enable','on');
  223. set(handles.pushbutton1,'Enable','on');
  224. axes(handles.axes1)
  225. cla
  226. continua_accendi = 1
  227. s = serial('COM4');
  228. set(s,'BaudRate',9600);
  229. set(s,'DataBits',8);
  230. set(s,'StopBits',1);
  231. try 
  232.     fopen(s);
  233. catch
  234.     msgbox('Apertura connessione non riuscita')
  235.     fclose(s)
  236.     fdelete(s)
  237. end
  238. pause(1)
  239. vettore_lunghezze_ADC = [];
  240. vettore_forze_ADC = [];
  241. vettore_lunghezze_ADC(1) = 0;
  242. vettore_forze_ADC(1) = 0;
  243. while (continua_accendi)
  244. %    save eventdata
  245.     [forza,lunghezza] = preleva_segnali(handles);
  246.     drawnow
  247. %      tic
  248. %      while (toc<1)
  249. %      end
  250. end
  251.  
  252.  
  253. % --- Executes on button press in pushbutton7.
  254. function pushbutton7_Callback(hObject, eventdata, handles)
  255. % hObject    handle to pushbutton7 (see GCBO)
  256. % eventdata  reserved - to be defined in a future version of MATLAB
  257. % handles    structure with handles and user data (see GUIDATA)
  258. global s
  259. global continua_accendi
  260. spegni_tutti_i_pulsanti (handles)
  261. set(handles.pushbutton6,'Enable','on');
  262. continua_accendi = 0
  263. fclose(s)
  264. delete(s)
  265. clear s
  266.  
  267.  
  268. % --- Executes on mouse press over figure background, over a disabled or
  269. % --- inactive control, or over an axes background.
  270. function figure1_WindowButtonDownFcn(handles)
  271. % hObject    handle to figure1 (see GCBO)
  272. % eventdata  reserved - to be defined in a future version of MATLAB
  273. % handles    structure with handles and user data (see GUIDATA)
  274. % beep
  275. % msgbox('rimpicciolisco')
  276.  
  277.  
  278. function [forza,lunghezza] = preleva_segnali(handles)
  279. global s
  280. global vettore_lunghezze_ADC
  281. global vettore_forze_ADC
  282. global lunghezza_vettore
  283. global continua_accendi 
  284. global continua_acquisizione 
  285. global coefficiente_lunghezza
  286. global coefficiente_forza
  287. numero_letture_per_grandezza = 5;
  288. try 
  289.     fprintf(s,'%s','R');
  290.     parola = fscanf(s)
  291. catch 
  292.     msgbox('lettura non riuscita')
  293.     fclose(s)
  294.     delete(s)
  295.     forza = 0
  296.     lunghezza = 0
  297.     continua_accendi = 0
  298.     continua_acquisizione = 0
  299.     return
  300. end
  301. tempo_di_acquisizione = str2num(get (handles.edit21,'String'));
  302. pause(tempo_di_acquisizione/1000);
  303. % variabile parola acquisita tramite seriale da arduino
  304. [aux,lunghezza_stringa] = size(parola);
  305. vettore_lunghezza_statistica = [];
  306. vettore_forza_statistica = [];
  307. forza = 0;
  308. [aux,lunghezza_stringa] = size(parola);
  309. i = 0;
  310. conta_lunghezze = 0 ;
  311. while i < lunghezza_stringa 
  312.     i = i + 1;
  313. %    disp (['i',num2str(i)]);
  314.     disp(['parola ' ,parola]);
  315.     if parola(i) == ' ' 
  316.         i = i + 1;
  317.         numerostringa = [];
  318.         numerostringa = parola (i);
  319.         finito = 1;
  320.         while finito
  321.              i = i + 1;
  322.              if i < lunghezza_stringa
  323.                  numerostringa = [numerostringa, parola(i)];
  324.              else 
  325.                  numerostringa = [numerostringa, parola(i)];
  326.                  finito = 0;
  327.              end
  328.              if parola (i) == ' '
  329.                  finito = 0;
  330.                  i = i-1;
  331.              end
  332.         end
  333.         str2num(numerostringa);
  334.         conta_lunghezze = conta_lunghezze + 1;  
  335.         if conta_lunghezze <= numero_letture_per_grandezza vettore_lunghezza_statistica (end+1) = str2num(numerostringa); end if conta_lunghezze > numero_letture_per_grandezza && conta_lunghezze <= numero_letture_per_grandezza*2 vettore_forza_statistica(end+1) = str2num(numerostringa); end end end lunghezza = median (vettore_lunghezza_statistica); lunghezza= 2^13-lunghezza forza = median (vettore_forza_statistica); reset_lunghezza = str2num (get(handles.edit23,'String')); reset_forza = str2num (get(handles.edit22,'String')); vettore_reset_lunghezza = reset_lunghezza .* ones(lunghezza_vettore,1); vettore_reset_forza = reset_forza .* ones(lunghezza_vettore,1); lunghezza_vettore = str2num (get(handles.edit24,'String')); vettore_forze_ADC(end+1) = forza; set(handles.edit19,'String',lunghezza); length(vettore_forze_ADC); while length(vettore_forze_ADC) >= lunghezza_vettore
  336.     vettore_forze_ADC(1) = [];
  337.     vettore_reset_forza (1) = []; 
  338. end
  339. hold on
  340. axes(handles.axes2)
  341. cla
  342. plot (vettore_forze_ADC)
  343. plot (vettore_reset_forza,'r')
  344.    xlabel('misure')
  345.         ylabel('Forza [bit]')
  346.  
  347. ylim([0 8192])
  348. % grafico vettore lunghezze        
  349. set(handles.edit14,'String',forza);
  350. vettore_lunghezze_ADC(end+1) = lunghezza;
  351. length(vettore_lunghezze_ADC);
  352. while length(vettore_lunghezze_ADC) >= lunghezza_vettore
  353.     vettore_lunghezze_ADC(1) = []; 
  354.     vettore_reset_lunghezza (1) = []; 
  355. end
  356. hold on
  357. axes(handles.axes1)
  358. cla
  359. plot (vettore_lunghezze_ADC)
  360. plot (vettore_reset_lunghezza,'r')
  361. ylim([0 8192])
  362. xlabel('misure')
  363. ylabel('Lunghezza [bit]')
  364. coefficiente_lunghezza = str2num (get(handles.edit17,'String'));
  365. coefficiente_forza = str2num (get(handles.edit18,'String'));
  366. X_LUN= (lunghezza- reset_lunghezza)*coefficiente_lunghezza
  367. X_FOR= (forza- reset_forza)*coefficiente_forza
  368. set(handles.edit11,'String',num2str(X_LUN));
  369. set(handles.edit12,'String',num2str(X_FOR));
  370. Sezione = str2num (get(handles.edit29,'String'));
  371. lunghezza_provetta = str2num (get(handles.edit32,'String'));
  372. X_SIGMA  = X_FOR / Sezione
  373. X_eps  = X_LUN / lunghezza_provetta
  374. set(handles.edit30,'String',num2str(X_SIGMA));
  375. set(handles.edit31,'String',num2str(X_eps));
  376.  
  377.  
  378. function spegni_tutti_i_pulsanti (handles)
  379. set(handles.pushbutton1,'Enable','off');
  380. set(handles.pushbutton2,'Enable','off');
  381. set(handles.pushbutton4,'Enable','off');
  382. set(handles.pushbutton5,'Enable','off');
  383. set(handles.pushbutton6,'Enable','off');
  384. set(handles.pushbutton7,'Enable','off');