Read continuous reading from Potentiometer and plot graph issues
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi everyone, I have an issue that i still can't figure it out and really need helps from experts. I try to read continuous reading from 2 potentiometers and plotted it in 1 figure. i tried to use animatedplot, however, i still don't find the best solutions for it. Thus, i stick to this easy (for me) but problematic code as below. The problem is, it runs very slow and after run about few minutes, the Matlab become crash. It give me "Matlab experienced unexpected error" for several times already and i think the code might be the cause. Can someone help and guide me,please?
clear all
clc
opengl('save', 'software');
a = arduino('COM3','Uno','Libraries','Servo'); %only needed if arduino not connected
NumberOfReadings = 100; %Set number of readings
analog1 = zeros(1,NumberOfReadings); %holds voltage reads
analog2 = zeros(1,NumberOfReadings); %holds voltage reads
while 1==1 % continually run
for index = 1:NumberOfReadings % run values 2 through 99
analog1(index) = readVoltage(a,'A3'); % Servo A
analog2(index) = readVoltage(a,'A1'); % Servo B
AllValues_A = analog1(index)+AllValues_A; %adds all values for test
AllValues_B = analog2(index)+AllValues_B; %
pause (.0005); %slow down read speed
%% VOLTAGE PLOT
subplot (1,2,1)
plot(analog1) %plot values
hold on
plot(analog2)
legend('Potentiometer A','Potentiometer B')
hold off
ylim([0 5]); %set y limits of plot
ylabel('Voltage'); %label Y axis
%% DISPLAY VALUE IN BIT
%AnalogRead1 = analog1(index) * (1023 / 5);
%AnalogRead2 = analog2(index) * (1023 / 5);
%fprintf('\n Potentiometer: A= %.2f B= %.2f ',AnalogRead1,AnalogRead2);
%% CHANGE OF ANGULAR DISPLACEMENT PLOT
AnalogRead_Hip = analog1(index) * (360 / 5);
AnalogRead_Knee = analog2(index) * (360 / 5);
subplot (1,2,2)
plot(index,AnalogRead_Hip,'Color','b','LineWidth',2);
hold on
plot(index,AnalogRead_Knee,'Color','k','LineWidth',2);
legend('Hip Angle','Knee Angle')
hold off
ylim([0 360]); %set y limits of plot
xlim([0 100]);
ylabel('Change of Angular Displacement'); %label Y axis
fprintf('\n Reading: A= %.2f B= %.2f ',AnalogRead_Hip,AnalogRead_Knee);
end
end % end while loop
3 Commenti
Risposte (0)
Vedere anche
Categorie
Scopri di più su Graphics Performance in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!