Can't see quiver plot
Show older comments
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)
Accepted Answer
More Answers (1)
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(:))
Categories
Find more on Vector Fields in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


