Unwanted line in graph
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Moustafa Aboubakr
le 12 Avr 2017
Réponse apportée : Moustafa Aboubakr
le 12 Avr 2017
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 ?
0 commentaires
Réponse acceptée
Steven Lord
le 12 Avr 2017
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.
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Multibody Modeling 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!