Loading...
Logo
Processing Forum

Map for Robot - good approach?

in General Discussion  •  Other  •  8 months ago  

Hi,
I am building a program for steering my robot and mapping the environment.
My question is about drawing and storing the map.

What I want:

  • 1cm resolution
  • 10x10 meter map size (or dynamically expanding if possible)
  • rotatable and zoomable

My approach would be to create a 1000x1000 byte array (store not scanned, clear, blocked).
If I want to rotate the map, I need to recalculate position of each pixel.

If I zoom I read only a smaller portion of the array and draw dots with arrayvalue*zoom in size.

I store the map in a csv (all array values). I could also store only scanned points. But as I would need store position, the amount of date would be equal or even more.


Is this the best or at least a good approach? Does someone has tips or a demo project?

Thanks
Robert

Replies(3)



hi,

it sounds ok. The 2D array would be fairly big, but ok.
Alternatively you could store the objects you find (x,y,width and height).
But then you need more intelligence e.g. merging two objects when he notices that two objects he encountered separately are in fact one. That could be a bit of hassle.


If I want to rotate the map, I need to recalculate position of each pixel.


Or you just use rotate and paint the map normally?

Greetings, Chrisir   



Thanks for your response.

I think both tips depend on identifying objects as such. I only identify a positive reading within a distance and angle. By this I know that the path (so the pixels) till this point are not blocked.

Finding objects out of all the free/blocked points is an own challenge. Once this would be done, rotating and storing the data would be indeed much easier. J


Thanks
Robert

Hmm. I did some first tests and it seems the array approach is too heavy.
With the demo code below I only get 4FPS.
Is it possible to do it in a smarter way?


Copy code
  1. float a;
  2. int Size=500;

  3. int [][] map= new int [Size][Size];

  4. void setup(){
  5.   size(Size,Size,P2D);
  6.   smooth();
  7.   noStroke();
  8.   //frameRate(10);
  9.   
  10.     for(int x=0;x<Size;x++){
  11.     for(int y=0;y<Size;y++){
  12.     map[x][y]=int(random(256));
  13.       }
  14.     }
  15.   
  16. }

  17. void draw(){
  18.   background(100);
  19.   for(int x=0;x<Size;x++){
  20.     for(int y=0;y<Size;y++){
  21.     stroke(map[x][y]);
  22.       point(x,y);
  23.       }
  24.     }
  25. println(frameRate);

  26. }
Thanks
Robert