Help me: Matlab and Arduino serial monitor processing for building Ultrasonic Radar System
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Programme:
clear;
clc;
delete(instrfind);
figure;
for theta=0:1:180
for i=1:1:50
x1(i)=i*cos(theta*3.14/180);
y1(i)=i*sin(theta*3.14/180);
end
plot(0,0,x1,y1,'color','g','LineWidth',10);
hold on;
end
xlabel('Distance (cm)');
for R=10:10:50
k=1;
for i=0:1:180
x(k)=R*cos(i*3.14/180);
y(k)=R*sin(i*3.14/180);
k=k+1;
end
plot(x,y,'color','k','LineWidth',4);
hold on;
end
for theta=0:30:180
for i=1:1:50
x11(i)=i*cos(theta*3.14/180);
y11(i)=i*sin(theta*3.14/180);
end
plot(0,0,x11,y11,'color','k','LineWidth',4);
hold on;
end
labels=cellstr(num2str([0:30:180]'));
text([50*cos(0);50*cos(3.18/6);50*cos(2*3.18/6);50*cos(3*3.18/6);50*cos(4*3.18/6);50*cos(5*3.18/6);50*cos(3.18)],[50*sin(0);50*sin(3.18/6);50*sin(2*3.18/6);50*sin(3*3.18/6);50*sin(4*3.18/6);50*sin(5*3.18/6);50*sin(3.18)],labels,'BackgroundColor',[.7 .9 .7]);
s=serial('COM3');
s.BaudRate=9600;
fopen(s);
while(1)
if (fscanf(s,'%f')=='.')==[1 0 0]
angle=fscanf(s,'%f');
distance=fscanf(s,'%f');
elseif (fscanf(s,'%f')=='.')==[1 0 0]
angle=fscanf(s,'%f');
distance=fscanf(s,'%f');
else
fscanf(s,'%f');
angle=fscanf(s,'%f');
distance=fscanf(s,'%f');
end
if distance>50
distance=50;
end
x3=distance*cos(angle*3.14/180);
y3=distance*sin(angle*3.14/180);
x4=50*cos(angle*3.14/180);
y4=50*sin(angle*3.14/180);
x5=distance*cos((angle+2)*3.14/180);
y5=distance*sin((angle+2)*3.14/180);
x6=50*cos((angle+2)*3.14/180);
y6=50*sin((angle+2)*3.14/180);
x7=distance*cos((angle-2)*3.14/180);
y7=distance*sin((angle-2)*3.14/180);
x8=50*cos((angle-2)*3.14/180);
y8=50*sin((angle-2)*3.14/180);
x9=distance*cos((angle+3)*3.14/180);
y9=distance*sin((angle+3)*3.14/180);
x10=50*cos((angle+3)*3.14/180);
y10=50*sin((angle+3)*3.14/180);
x11=distance*cos((angle-3)*3.14/180);
y11=distance*sin((angle-3)*3.14/180);
x12=50*cos((angle-3)*3.14/180);
y12=50*sin((angle-3)*3.14/180);
X3=distance*cos(angle*3.14/180);
Y3=distance*sin(angle*3.14/180);
X4=50*cos(angle*3.14/180);
Y4=50*sin(angle*3.14/180);
X5=0;
Y5=0;
X6=50*cos((angle+2)*3.14/180);
Y6=50*sin((angle+2)*3.14/180);
X7=0;
Y7=0;
X8=50*cos((angle-2)*3.14/180);
Y8=50*sin((angle-2)*3.14/180);
X9=0;
Y9=0;
X10=50*cos((angle+3)*3.14/180);
Y10=50*sin((angle+3)*3.14/180);
X11=0;
Y11=0;
X12=50*cos((angle-3)*3.14/180);
Y12=50*sin((angle-3)*3.14/180);
hold on;
n=plot([X3,X4,X5,X6,X7,X8,X9,X10,X11,X12],[Y3,Y4,Y5,Y6,Y7,Y8,Y9,Y10,Y11,Y12],'color','y','LineWidth',20);
m=plot([x3,x4,x5,x6,x7,x8,x9,x10,x11,x12],[y3,y4,y5,y6,y7,y8,y9,y10,y11,y12],'color','r','LineWidth',20);
drawnow;
delete(m,n);
end
fclose(s);
ERROR :
Warning: Unsuccessful read: Matching failure in format..
Warning: Unsuccessful read: A timeout occurred before the Terminator was reached..
Error using ==
Matrix dimensions must agree.
Error in Untitled (line 41)
elseif (fscanf(s,'%f')=='.')==[1 0 0]
Réponses (0)
Voir également
Catégories
En savoir plus sur Graphics Performance dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!