Go Down

Topic: Bitmap Maze (Read 190 times) previous topic - next topic

Osaid

Nov 11, 2014, 03:51 pm Last Edit: Nov 20, 2014, 05:56 pm by Osaid
Hi everyone,

I'm working on an robot that would be able to navigate through a maze, avoid obstacles and  identify some of the objects in it. I have a 52*96 pixel monochromatic bitmap of the maze which can be split into sections. Could that bitmap be converted into an array via the arduino so the wave front algorithm be implemented.
I'm going to be using an arduino mega with the image being read from an SD card.

http://www.societyofrobots.com/programming_wavefront.shtml

Thanks

robtillaart

Quote
Could that bitmap be converted into an array via the arduino so the wave front algorithm be implemented.
yes, why not
a mega has enough memory for that.

But be aware recursive algorithms can exhaust memory quite fast.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Osaid

#2
Nov 11, 2014, 10:15 pm Last Edit: Nov 16, 2014, 12:12 pm by Osaid
True, I'm still fairly new to the arduino platform and C code and have mostly worked with .NET.

Could you provide some examples, on the bitmap conversion , as I'm having a bit of trouble with the code.

Thanks
 



Osaid

Would this work ?

Code: [Select]
void setup() {
  size(200, 200);

  PrintWriter output;
  output = createWriter("output.txt");

  PImage img;
  img = loadImage("input.bmp");
  image(img, 0, 0);

  output.println("static unsigned char PROGMEM bitmapName[] =");
  output.println("{");
  output.print("  ");
  output.print(img.width);
  output.print(",");
  output.print(img.height);
  output.println(", //width and height");

  img.loadPixels();

  for (int y = 0; y<img.height; y++) {
    output.print("  ");
    for (int x = 0; x<img.width; x+=8) {
      output.print("B");
      for (int b = 0; b<8; b++) {
        color thisColor = img.get(x+b, y);
        if (brightness(thisColor) > 100) {
          output.print("0");
          img.set(x+b, y, color(255));
        }
        else {
          output.print("1");
          img.set(x+b, y, color(0));
        }
      }
      output.print(", ");
    }
    output.println();
    if ((y%8)==7) {
      output.println();
    }
  }

  img.updatePixels();
  image(img, 0, 100);

  output.print("};");
  output.flush();
  output.close();
}

void draw() {
}




Credit goes to rodot, here: http://gamebuino.com/forum/viewtopic.php?f=12&t=437&start=10

robtillaart

just run it and you know...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

PaulS

Quote
Would this work ?
Processing code, on an Arduino? No. Processing is based on Java.

You CAN develop C++ classes to replace the Java/Processing classes that do all the work, but that is where the effort comes in.

Osaid

#6
Nov 16, 2014, 12:11 pm Last Edit: Nov 16, 2014, 12:33 pm by Osaid
Well, that makes sense. I was having trouble with my SD shield but now I've got it to work, isn't there a alternative than to write classes.

I think I got somewhere, using frollard's code here , I was able to get this. (file attached)

Code: [Select]
void loadBMPinfo()
{
byte heightByte[4];
height = 0; //start with a zero'd signed long, 4 bytes.
myFile.close();  
myFile = SD.open(fileName, FILE_READ);
//Serial.print("BitmapOffsetStart:");
//Serial.println(bitmapOffset,HEX);
myFile.seek (0x16); //goto start byte of bitmap height
for (int i = 0; i < 4; i++){  //height is a 4 byte integer stored in reverse byte order
heightByte[i] = myFile.read();
} //end for grab
for (int i = 3; i > 0; i--){ //3 2 1 not zero
height = height | heightByte[i]; //add the i'th byte
height = height << 8;            //bitshift everything 1 byte left
}
height = height | heightByte[0];
myFile.seek(0xA);
bitmapOffset = myFile.read();

//myFile.close();
//Serial.print("BitmapOffset:");   //debug if the bitmap data offset is correct
//Serial.println(bitmapOffset,HEX);
//Serial.print("Height:");
//Serial.println(height);
} //end void loadBMPinfo()






Go Up