problem with my obstacle avoidance code

3 Ansichten (letzte 30 Tage)
arjun ramanujam
arjun ramanujam am 6 Jun. 2015
Kommentiert: Walter Roberson am 20 Aug. 2018
hi i am using this code for circle generation
function h = circle(x,y,r)
hold on
th = 0:pi/50:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
h = plot(xunit, yunit);
hold off
  1. The obstacles are defined as circles
  2. when i try to callt the function from another script file it seemed fine at once but the next time when i tried doing it i got this error
"Error in ci1 (line 2)
circle =ci(300,500,20);
function h = ci(x,y,r)
Error: Function definitions are not permitted in this context."
i have developed the logic for the collision avoidance that is
if %touching internally
if(c= = rless)
disp('there is collison');
% circles intersecting
else
if (c>=rless)
disp('there is collision');
%touching externally
else
if (c= = rsum)
disp('there is a collision');
% circle inside another circle
else
if (c< rmod)
disp('there is a collison');
% if there is no collision
if(c>rsum)
disp('there is no collision');
end
end
end
end
end
% where rless=|r1-r2|
% where rsum=r1+r2
%rmod=|r2-r1|
%where c is the distance between two circle centers (x1,y1) and(x2,y2)
  • # This is just the rough idea of the logic i intend to apply at the calling script file
  • # That is where the function of the circles are called can you please help me sort this out
thank you in advance
  1 Kommentar
passioncoding
passioncoding am 20 Aug. 2018
Can you kindly share your matlab code for collision avoidance.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Image Analyst
Image Analyst am 6 Jun. 2015
What does line 1 say? It better say
function ci1()
or else you'd get that error. Also, you can't do this
if(c= = rless)
you cannot have a space in between two equal signs. You probably want
if c == rless

Walter Roberson
Walter Roberson am 6 Jun. 2015
Functions need to be stored in .m files to be called upon.
Also in any one .m file, you can have functions (the file starts with "function"), or class definitions (the file starts with "classdef"), or script instruction (the file starts with anything else), but you cannot mix those. A script file cannot also define a function. You can have multiple functions in one .m though:
function ci1
circle = ci(300,500,20);
end
function h = ci(x,y,r)
...
end
  3 Kommentare
Walter Roberson
Walter Roberson am 22 Feb. 2018
Testing a square is easy if it is aligned with the axes: left <= x & x <= right & bottom <= y & y <= top
Walter Roberson
Walter Roberson am 20 Aug. 2018
Note: effective R2016b it became possible to define functions at the bottom of script files.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by