General [M]ayhem

Go Back   General [M]ayhem > Real Time Sub-Forums > CompuGlobalHyperMegaNet
Register Members List Mark Forums Read [M]erchandise Calendar

Reply
 
Thread Tools
JayNeo8
 
using MATLAB to visualize field of view coding question.

I am attempting to the field of view of a robot with 360 degree vision within MATLAB. Basically I want to place the robot somewhere randomly on a 2d with obstacles and show the area in which the obstacles are not blocking the robot's vision.

I have some code but it's not working correctly and Im unsure how to go about fixing it. The basic idea is that the code goes through every point and finds the linear equation that joins those two points. If an obstacles lies on that point it does not that line.
My problem is that the search for an obstacles does not originate at the robot but at the origin instead which gives me bad results. I am not a programmer and don't really know how to go about fixing this. Any help would be greatly appreciated! Thx.

Code:
clc
close all
clear all
img = imread('workspace.png')>1;

for i = 1:size(img,1)
    for j = 1:size(img,2)
        if img(i,j) == 0
            img(i,j) = 1;
        else
            img(i,j) = 0;
        end
    end
end

imagesc(img)
hold on
x_axis = 1:1:size(img,2);
good = 1;
yrz = [];
xz = [];
    
[startx,starty] = ginput(1);
startx = round(startx);
starty = round(starty);

ymax = size(img,1);
xmax = size(img,2);

for ii = 1:ymax %%y
    for jj = 1:xmax %%x
if jj == startx
    y = 1:1:ymax;
    x = ones(1,xmax)*jj;
    yr = round(real(y));
    ind = find(yr <= ymax & yr > 0);
    y = y(ind);
    yr = yr(ind);
    x = x(ind);
   else
    y = ((ii-starty)/(jj-startx))*(x_axis-startx)+starty;
    yr = round(real(y));
    ind = find(yr <= ymax & yr > 0);
    y = y(ind);
    yr = yr(ind);
    x = x_axis(ind);
end
 
 for kk = 1:size(ind,2);
        if img(yr(kk),x(kk)) ==1 && good == 1
                yrz = y(1:kk-1);
                xz = x(1:kk-1);
%               yrz = [yrz,yr(k)];
%               xz =  [xz,x(k)];
                good = 0;
         end
  end
 

 

    plot(xz,yrz,'ro')
    %plot(x,yr,'bs')

    good = 1;
    yrz = [];
    xz = [];
end
end

plot(startx,starty,'gd')
%axis([1 size(img,2) 1 size(img,1)])
hold off

This picture is the environment I am working with. It's basically a .png with white as free space and black as obstacles. This is just an example of an environment space and I would like it to work with any shaped environment.

__________________
THA BREW HA HA PWNES J00!
Old 02-24-2009, 06:01 PM JayNeo8 is offline  
Reply With Quote
#1  

Advertisement [Remove Advertisement]

JayNeo8
 
Just found out that I have been searching for the wrong terms in google. The formal term for this sort of thing is "visibility graphs." Using the right search term I found some algorithms I'm going to try out.
__________________
THA BREW HA HA PWNES J00!
Old 02-25-2009, 07:57 AM JayNeo8 is offline  
Reply With Quote
#2  

Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -7. The time now is 04:11 AM.



Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.