Area visited with robot

1 view (last 30 days)
Amat3r
Amat3r on 26 Nov 2015
Answered: Image Analyst on 26 Nov 2015
Hello!
I am struggling with an implementation problem. I have a robot with differential drive driving trough a mxn square area. I want to calculate how much area has it already covered.
I have the x,y coordinates of where the robot currently is. I need to know how much area has the robot covered (in %) and how many times has it visited each grid square.
Lets say that area is 5x5 meters. Robot size is a circle with r = 5 cm. One square is then 10x10 cm. So we have an accumulator 50x50 that stores +1 in accu(1,1) if robot is at position, lets say, q = (0.4545, 0.748). Therefore 4% has been visited. How do I figure in what square the robot is and when it is already in another?
Another problem would be how to prevent adding +1 for each itteration of the loop. So if robot stays in one square for a longer time it still counts as +1. But if it moves to another square and comes back, then its +1 again.
Thank you for helping me think :)

Answers (1)

Image Analyst
Image Analyst on 26 Nov 2015
Create an image of all zeros that is 5 by 5 with sufficient resolution, say 2000 by 2000 pixels or something. Then loop over moves. So at each move you'll have a new x and y location. Then use the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F to draw a circle of the robot's diameter into the image. Afterwards, simple add up all the non zero pixels with nnz().
To get the bin number or tile number that the centroid is in, simply divide by the location and scale/bin. Like if it's a 2000 pixel wide image that represents 5 meters, and it's at x = 23 cm, that would be bin 5. See this code snippet for spatial calibration:
columns = 2000 % 5 meters, 500 cm
pixelsPerCm = 2000 / 500;
% Find out how many pixels are in a 10 cm tile
pixelsPerTile = 10 * pixelsPerCm % Will be 40 pixels
% Define the x location in pixels (if that's what you get from your robot)
xInPixels = 99 % in pixels
% Get the x location in cm
xInCm = xInPixels / pixelsPerCm
% Find out what tile it is in.
tileNumber = floor(xInCm / 5) + 1 % Should be 5 for x=99 pixels
% Or if you already have x in cm rather than pixels, do this:
% Define the x location in cm (if that's what you get from your robot)
xInCm = 24 % in cm
% Find out what tile it is in.
tileNumber = floor(xInCm / 5) + 1 % Should be tile #5 for x=24 cm

Community Treasure Hunt

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

Start Hunting!