필터 지우기
필터 지우기

problem with my obstacle avoidance code

조회 수: 1 (최근 30일)
arjun ramanujam
arjun ramanujam 2015년 6월 6일
댓글: Walter Roberson 2018년 8월 20일
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
passioncoding
passioncoding 2018년 8월 20일
Can you kindly share your matlab code for collision avoidance.

댓글을 달려면 로그인하십시오.

답변 (2개)

Image Analyst
Image Analyst 2015년 6월 6일
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 2015년 6월 6일
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
Walter Roberson
Walter Roberson 2018년 2월 22일
Testing a square is easy if it is aligned with the axes: left <= x & x <= right & bottom <= y & y <= top
Walter Roberson
Walter Roberson 2018년 8월 20일
Note: effective R2016b it became possible to define functions at the bottom of script files.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by