I'm having issues with the rectangle function. The error statement I'm getting for the code below is: ''Error using rectangle: Value must be numeric'' and I can't figure it out. I'm trying to get a simulated UAV to a goalpoint, but it keeps stopping
Show older comments
x=0;
filename='Zoe';
t=1000;
figure(1)
center=[0,0];
r=5;
ball_rad=0.4;
for count=1:1:10
%Vint=50+5.*rand(1,1)
loc_x=0;
loc_y=0;
loc_x=start_x;
Vres=Vself
clf;
x_target=20+10*rand(1,1)
y_target=20+10*rand(1,1)
rectangle('Position',[x_target-ball_rad_2,y_target -ball_rad_2, ball_rad_2*2, ball_rad_2*2],...
'Curvature',[1,1],...
'Facecolor','b');
for sdx=1:1:num_images
ball_rad=0.4;
rectangle('Position',[loc_x-ball_rad,loc_y-ball_rad,ball_rad*2,ball_rad*2],...
'Curvature',[1,1],...
'Facecolor','g');
fisr=readfis('Get_to_Goal')
distance_s=((loc_x-x_target)^2)+((loc_y-y_target)^2)
distance=sqrt(distance_s)
angle=atand(((y_target-loc_y))/(x_target-loc_x))
AnimationOutput=evalfis([distance angle],fisr)
r=distance*(sind(AnimationOutput(:,2)))
r2=distance*(cosd(AnimationOutput(:,2)))
if angle==0
if loc_x_previous==x_target
loc_x=x_target
loc_y=loc_y+r2*(loc_y-y_target)/(abs(y_target-loc_y))
elseif loc_y_previous==y_target
loc_y=y_target
loc_x=loc_x+r*(loc_x-x_target)/(abs(x_target-loc_x))
end
end
if loc_x>=x_target
loc_x=x_target
end
if loc_y>=y_target
loc_y=y_target
end
if y_target-loc_y<=0
angle=0;
if x_target-loc_x>0
loc_x=loc_x-r*0.5*(loc_x-x_target)/(abs(x_target-loc_x));
else
loc_x=loc_x-r*0.5*(loc_x-x_target)/(abs(x_target-loc_x));
end
end
axis([-22 42 -22 42]);
title('MC Goal')
drawnow;
%%most of the rest of the code is a video writer
Answers (2)
Image Analyst
on 6 Jun 2018
Edited: Image Analyst
on 6 Jun 2018
Right before the for loop, put these lines of code with no semicolons. Tell us what you see in the command window:
whos x_target ball_rad y_target ball_rad_2
x_target
y_target
ball_rad
ball_rad_2
12 Comments
Image Analyst
on 6 Jun 2018
Can you answer my question? Please put those lines of code in and let me know what it says.
Walter Roberson
on 6 Jun 2018
Are you using symbolic variables anywhere? What is showing up for
class([loc_x-ball_rad,loc_y-ball_rad,ball_rad*2,ball_rad*2])
Zoe Lee
on 6 Jun 2018
Image Analyst
on 6 Jun 2018
No, those lines of code are supposed to come even before rectangle() is even executed. So what do they say?
Zoe Lee
on 6 Jun 2018
Zoe Lee
on 6 Jun 2018
Zoe Lee
on 6 Jun 2018
Image Analyst
on 6 Jun 2018
I get this:
To use 'readfis', the following product must be licensed, installed, and enabled:
Fuzzy Logic Toolbox
Error in test4 (line 64)
fisr=readfis('Get_to_Goal')
So I've added the Fuzzy Toolbox to the product list in the upper right of this screen.
Also, you had the lines in there before rectangle() but you had a % in front of them all which means they were commented out. Not sure why you did that but when I uncommented them I get this:
Name Size Bytes Class Attributes
ball_rad 1x1 8 double
ball_rad_2 1x1 8 double
x_target 1x1 8 double
y_target 1x1 8 double
x_target =
28.4071725598366
y_target =
22.5428217897153
ball_rad =
0.4
ball_rad_2 =
0.2
And it works for the first two calls to rectangle(). After that however, you call the fuzzy function and I can't continue. So you're just going to have to put these lines immediately before each call to rectangle:
clc;
whos x_target ball_rad y_target ball_rad_2
x_target
y_target
ball_rad
ball_rad_2
and see what happens. Tell us what you see in the command window right before rectangle() throws the error.
Walter Roberson
on 7 Jun 2018
I need your Get_to_Goal.fis to test.
Zoe Lee
on 7 Jun 2018
Zoe Lee
on 7 Jun 2018
Categories
Find more on Fuzzy Logic in Simulink 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!