Unwanted line in graph

2 次查看(过去 30 天)
I am doing a mobile robot simulation by solving the differential equation using ode solver and an animated line to show the movement of the robot (robot path)
%Simulation Experiment (kinematics input speed)***************
function mydglcallw6(WR,WL,n)
clf;
tspan = [0 2];initials = zeros(n,3); %start at origin
p = par();
%**************************************************************
%Creating robot path according to input speed******************
for i = 1:n
p.WL = WL(i) ;p.WR = WR(i);
sol(i)= ode23(@mydglw5, tspan, initials(i,:),[],p);
[t,s] = ode23(@mydglw5, tspan, initials(i,:),[],p);
initials(i+1,:) = deval(sol(i),2);
curve = animatedline(0,0,'Color','r','linewidth',2);
axis([-1.5 1.5 -1.5 1.5]);
xlabel('x-position [m]');ylabel('y-position [m]');
title('robot path');
grid on
for j = 1:length(s(:,1))
addpoints(curve,s(j,1),s(j,2))
drawnow
pause(0.02)
end
end
end
%*************************************************************
%Model Parameters*********************************************
function p = par();
p.L = 0.12; %length [m]
p.r = 0.1; %radius of wheel [m]
%p.WL = 2;p.WR = 2.5; %wheel velocities [th/s]
end
%*************************************************************
%Differential Equations***************************************
function dt = mydglw5(t,c,p)
x = c(1);y = c(2);th = c(3);
dx = (((p.r*p.WL)+(p.r*p.WR))/2) * cos(th);
dy = (((p.r*p.WL)+(p.r*p.WR))/2) * sin(th);
dth= ((p.r*p.WL)-(p.r*p.WR))/p.L;
dt = [dx;dy;dth];
in = [x(end);y(end);th(end)]; %compare last value with deval
end
when i use this code, i always get an unwanted line in the graph ?? how can i remove it ?

采纳的回答

Steven Lord
Steven Lord 2017-4-12
Is that unwanted line between the point (0, 0) and the first point in the solution? [I would run the code to see, but you didn't tell us what WR, WL, or n are.] If so try creating the animatedline starting with the point (NaN, NaN). Like most if not all of the plotting functions in MATLAB, points with one or both of the coordinates NaN are not displayed by an animatedline.
h = animatedline(NaN, NaN, 'Color', 'r');
axis([-10 370 -1 1]);
for k = 0:360
addpoints(h, k, cosd(k))
pause(0.01)
end
Compare that with:
figure
h = animatedline(0, 0, 'Color', 'r');
axis([-10 370 -1 1]);
for k = 0:360
addpoints(h, k, cosd(k))
pause(0.01)
end
If that's not the unwanted line you're seeing, please describe in more detail where the unwanted line is located (and/or give us a small sample of data for WR, WL, and n so we can run your example) and we may be able to offer other suggestions.
  1 个评论
Moustafa Aboubakr
Moustafa Aboubakr 2017-4-12
Thanks Steven for your answer, i removed the (0,0) and it worked :) curve = animatedline('Color','r','linewidth',2); WR & WL are the input velocities of the wheels and n is the number of times the differential equation is solved ex: mydglcallw6([1.5 2 2.5 3.5],[2 2.5 3 3.5],4) Thanks again :)

请先登录,再进行评论。

更多回答(1 个)

Moustafa Aboubakr
Moustafa Aboubakr 2017-4-12
I removed the (0,0) and it worked :) curve = animatedline('Color','r','linewidth',2); WR & WL are the input velocities of the wheels and n is the number of times the differential equation is solved ex: mydglcallw6([1.5 2 2.5 3.5],[2 2.5 3 3.5],4)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by