How to plot in real time data acquisition from force sensor ?
조회 수: 8 (최근 30일)
이전 댓글 표시
Hi all, I am trying to plot in real time of data through USB of the force sensor. but the only plot, not exact data that is shown in force it is plot different data may be because it sends continuously. and how to save the plot and data. thanks all. here is the code:
%%function p=realtimeplot(T)
%%Create the serial object
%{serialPort = 'COM7';
%serialObject = serial(serialPort, 'BaudRate', 19200);
%fopen(serialObject);
%Setup serial interface
%%Set up the figure window
time = 0;
w1 = 0;
target1 = 0;
sample = 0;
%figureHandle = figure('NumberTitle','off',...
% 'Name','Viteza unghiulara a motorului',...
% 'Color',[0 0 0],'Visible','off');
figureHandle = figure('NumberTitle','off',...
'Name','Viteza unghiulara a motorului',...
'Visible','off');
% Set axes
%axesHandle = axes('Parent',figureHandle,...
% 'YGrid','on',...
% 'YColor',[0.9725 0.9725 0.9725],...
% 'XGrid','on',...
% 'XColor',[0.9725 0.9725 0.9725],...
% 'Color',[0 0 0]);
axesHandle = axes('Parent',figureHandle,'YGrid','on','XGrid','on');
hold on;
plotHandle = plot(axesHandle,time,w1,time,target1,'LineWidth',2);
%xlim(axesHandle,[min(time) max(time+0.001)]);
% Create xlabel
xlabel('ss','FontWeight','bold','FontSize',14,'Color',[0 0 1]);
% Create ylabel
ylabel('ts','FontWeight','bold','FontSize',14,'Color',[0 0 1]);
% Create title
title('loadcell','FontSize',15,'Color',[0 0 1]);
% microcontroller - time between each value sent on RS232
sampleTime = 0.05;%0.1;
% interval pause for PC data collection
pauseInterval = sampleTime / 2;
%%Collect data
count = 1;
set(figureHandle,'Visible','on');
hf=figure('position',[0 0 eps eps],'menubar','none');
delete(instrfind);
s = serial('COM7');
set(s,'BaudRate',19200);
fopen(s);
while 1
ch = get(hf,'currentcharacter');
if strcmp(ch, 'q') %quit
close(hf)
break
end
if strcmp(ch, 'c') %clear
time = 0;
w1 = 0;
target1 = 0;
count = 1;
end
%sample = fscanf(serialObject, '%d-%d\n');
time(count) = count * sampleTime;
Q=fscanf(s);
w1(count) = str2num(Q); %%sample(1);
% target1(count) = 0;%%sample(2);
%set(plotHandle, {'YData'}, {w1;target1}, {'XData'}, {time;time});
set(plotHandle, {'YData'}, {w1}, {'XData'}, {time});
pause(pauseInterval);
count = count + 1;
end
%%Clean up the serial object
%{
fclose(serialObject);
delete(serialObject);
clear serialObject;
%}
%clear all;
%disp(['n! = ' num2str(f)])
fclose(s);
close all;
clear all;
%delete(s)
%save('mydata.mat','ss','ts'); %MYA
%clear s
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!