Can't see quiver plot

5 vues (au cours des 30 derniers jours)
기홍 박
기홍 박 le 3 Mai 2023
I'm currently trying to make a code of potential field for path planning.
I defined potential energy(u_att, u_rep) and then force(fxa,fya,fxr,fyr) by using 'gradient'.
To the best of my knowledge, force vector(fxa,fya,fxr,fyr) is properly calculated,
but when I plot that force vector with 'quiver', I couldn't see anything on the plot.
How can I fix this?
Code for potential field is attached below
Thank you.
close all; clear; clc;
figure, hold on;
axis([0 100 0 100]), axis square, box on;
xlabel('x'), ylabel('y');
obslist = [60 60 15;
20 40 7;
70 30 5];
x_start = [10 10];
x_goal = [90 90];
plot(x_start(1),x_start(2),'rx','linewidth',2);
plot(x_goal(1),x_goal(2),'bo','linewidth',2);
angs = (0:pi/50:2*pi)';
xpu = cos(angs); ypu = sin(angs);
for i=1:size(obslist,1)
xp = obslist(i,1) + obslist(i,3)*xpu;
yp = obslist(i,2) + obslist(i,3)*ypu;
fill(xp,yp,'y');
plot(xp,yp,'k');
end
% Above code is from KAIST Spring 2023 ME652 lecture
% -------------------------------------------------------------------------
slice = 1;
[X, Y] = meshgrid(0:slice:100, 0:slice:100);
Ka = 5;
u_att = 0.5*Ka*sqrt((X-x_goal(1)).^2 + (Y-x_goal(2)).^2);
[fxa,fya] = gradient(u_att,slice,slice);
Kr = 500;
u_rep = zeros(size(X));
for i=1:size(obslist,1)
u_rep = u_rep + 0.5.*Kr*(1./sqrt((X-obslist(i,1)).^2 + (Y-obslist(i,2)).^2) - 1./sqrt((obslist(i,3)+2))).^2;
end
[fxr,fyr] = gradient(u_rep,slice,slice);
fX = - fxr - fxa;
fY = - fyr - fya;
quiver(X,Y,fX,fY, 'k')
% contour(X,Y,u_att+u_rep,25)

Réponse acceptée

chicken vector
chicken vector le 3 Mai 2023
Modifié(e) : chicken vector le 3 Mai 2023
Because there are too many arrows and they overlap, causing the automatic scaling to not display anything.
Set the scale to 'off'with:
quiver(X,Y,fX,fY,0)
And adjust the values of fX and fY accordingly.
You can see an example in the comments.
  2 commentaires
chicken vector
chicken vector le 3 Mai 2023
close all; clear; clc;
figure, hold on;
axis([0 100 0 100]), axis square, box on;
xlabel('x'), ylabel('y');
obslist = [60 60 15;
20 40 7;
70 30 5];
x_start = [10 10];
x_goal = [90 90];
plot(x_start(1),x_start(2),'rx','linewidth',2);
plot(x_goal(1),x_goal(2),'bo','linewidth',2);
angs = (0:pi/50:2*pi)';
xpu = cos(angs); ypu = sin(angs);
for i=1:size(obslist,1)
xp = obslist(i,1) + obslist(i,3)*xpu;
yp = obslist(i,2) + obslist(i,3)*ypu;
fill(xp,yp,'y');
plot(xp,yp,'k');
end
% Above code is from KAIST Spring 2023 ME652 lecture
% -------------------------------------------------------------------------
slice = 1;
[X, Y] = meshgrid(0:slice:100, 0:slice:100);
Ka = 5;
u_att = 0.5*Ka*sqrt((X-x_goal(1)).^2 + (Y-x_goal(2)).^2);
[fxa,fya] = gradient(u_att,slice,slice);
Kr = 500;
u_rep = zeros(size(X));
for i=1:size(obslist,1)
u_rep = u_rep + 0.5.*Kr*(1./sqrt((X-obslist(i,1)).^2 + (Y-obslist(i,2)).^2) - 1./sqrt((obslist(i,3)+2))).^2;
end
[fxr,fyr] = gradient(u_rep,slice,slice);
fX = - fxr - fxa;
fY = - fyr - fya;
quiver(X,Y,fX/5,fY/5,0,'Color','k')
기홍 박
기홍 박 le 3 Mai 2023
Thanks for your help!

Connectez-vous pour commenter.

Plus de réponses (1)

Chunru
Chunru le 3 Mai 2023
figure, hold on;
axis([0 100 0 100]), axis square, box on;
xlabel('x'), ylabel('y');
obslist = [60 60 15;
20 40 7;
70 30 5];
x_start = [10 10];
x_goal = [90 90];
plot(x_start(1),x_start(2),'rx','linewidth',2);
plot(x_goal(1),x_goal(2),'bo','linewidth',2);
angs = (0:pi/50:2*pi)';
xpu = cos(angs); ypu = sin(angs);
for i=1:size(obslist,1)
xp = obslist(i,1) + obslist(i,3)*xpu;
yp = obslist(i,2) + obslist(i,3)*ypu;
fill(xp,yp,'y');
plot(xp,yp,'k');
end
% Above code is from KAIST Spring 2023 ME652 lecture
% -------------------------------------------------------------------------
slice = 1;
[X, Y] = meshgrid(0:slice:100, 0:slice:100);
Ka = 5;
u_att = 0.5*Ka*sqrt((X-x_goal(1)).^2 + (Y-x_goal(2)).^2);
[fxa,fya] = gradient(u_att,slice,slice);
Kr = 500;
u_rep = zeros(size(X));
for i=1:size(obslist,1)
u_rep = u_rep + 0.5.*Kr*(1./sqrt((X-obslist(i,1)).^2 + (Y-obslist(i,2)).^2) - 1./sqrt((obslist(i,3)+2))).^2;
end
[fxr,fyr] = gradient(u_rep,slice,slice);
fX = - fxr - fxa;
fY = - fyr - fya;
% quiver(X,Y,fX,fY, 'k')
figure
quiver(X,Y,fX,fY,0)
% Check your code, fX and fY has inf values so that the autoscale is not
% working
max(fX(:)),max(fY(:))
ans = Inf
ans = Inf
  1 commentaire
기홍 박
기홍 박 le 3 Mai 2023
Thanks for your help!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programming 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!

Translated by