How do I create a semicircular live RADAR plot?

조회 수: 5 (최근 30일)
Usamath Pallikkachalil
Usamath Pallikkachalil 2016년 11월 13일
답변: othmane kribia 2023년 1월 26일
I use an ultrasonic sensor mounted on a servomotor to obtain the distance from objects around it.
I use the code attached to use the serial data (through Arduino) and plot a live RADAR. The catch is that I'm trying to design a plot that has an arm that moves back and forth in sync with the servomotor and then darken the area beneath the distance measured to produce the Radar effect.
Code:-
clc;
clear all;
%Customize graph
figure('units','normalized','outerposition',[0 0 1 1]);
whitebg('black');
%Draw Scale Data
th = linspace(0,pi,1000);
R = 10:10:50;
for i=1:length(R);
x = R(i)*cos(th);
y = R(i)*sin(th);
plot(x,y,'Color', [0.603922 , 0.803922 , 0.196078] ,'LineWidth',1);
hold on;
end
%Draw Axis data
x0 = [0 100 0 0 0 0 ];
x1 = [0 100 86.60 50 -50 -86.60];
y0 = [0 0 0 0 0 0];
y1 = [100 0 50 86.60 86.60 50];
for i=1:length(x0);
hold on;
plot([x0(i),x1(i)],[y0(i),y1(i)] ,'Color', [0.603922 , 0.803922 , 0.196078],'LineWidth',2);
end
h=zeros(100,100);
%Draw Sonar default data
for i=1:180
hold on;
[x, y] = pol2cart(i*0.0174532925, 100);
h(i) = plot([0,x],[0,y],'g','LineWidth',1);
hold on;
end;
%define serial port
s1 =serial('COM4');
s1.BaudRate=9600;
fopen(s1);
%Draw Sonar Data
while(1)
data = fgets(s1);
[th, r] = strtok(data);
th= real(str2double(th));
r = str2double(r);
set(th,'color',r);
[x0, y0] = pol2cart(th*0.0174532925, 100);
[x, y] = pol2cart(th*0.0174532925, r);
set(h(th),'String','XData',[x0,x]);
set(h(th),'String',[y0,y]);
m = plot([0,x0],[0,y0],'g','LineWidth',3);
drawnow;
delete(m);
end;
fclose(s1);
I get an error in the line set(th,'color',r);

답변 (1개)

othmane kribia
othmane kribia 2023년 1월 26일
just try this: set(h(th),'color','r');

카테고리

Help CenterFile Exchange에서 Detection and Tracking Statistics에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by