Can't see quiver plot

5 ビュー (過去 30 日間)
기홍 박
기홍 박 2023 年 5 月 3 日
編集済み: chicken vector 2023 年 5 月 3 日
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)

採用された回答

chicken vector
chicken vector 2023 年 5 月 3 日
編集済み: chicken vector 2023 年 5 月 3 日
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 件のコメント
chicken vector
chicken vector 2023 年 5 月 3 日
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')
기홍 박
기홍 박 2023 年 5 月 3 日
Thanks for your help!

サインインしてコメントする。

その他の回答 (1 件)

Chunru
Chunru 2023 年 5 月 3 日
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 件のコメント
기홍 박
기홍 박 2023 年 5 月 3 日
Thanks for your help!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by