Intelligent Maze Navigation

Hi guys

In this piece of code Sparki measures the distances of the maze walls and is programmed to turn the appropriate direction based on the amount of space available.

If the space is restricted Sparki knows that this means there is an object to be picked up. The accuracy of this could be improved by using the line sensors to detect a particular area where the object will be positioned or by appropriate measuring from the human. Sparki could also use his line sensor to understand that he has brought the object to the desired place and to deposit it. I didn’t actually think of that earlier when writing the program.

The way the code is written Sparki could essentially master any maze that uses walls and fins his way out (as long as the maze was wide enough for Sparki to fit through)!

Here is the SparkiDuino code:

#include <Sparki.h> // include the sparki library

void setup()
{
  delay(100);
}

void loop()
{
    sparki.clearLCD();
    int mazeF = 0;
    int mazeR = 0;
    int mazeL =0;
    sparki.servo(0);
    sparki.ping();
    mazeF = sparki.ping(); // measures the distance 
    delay(2000);
    sparki.print("mazeF= "); 
    sparki.println(mazeF); 
    sparki.updateLCD();
    delay(2000);
        if(mazeF > 14) // if the distance measured is more than 9 centimeters
        {
            sparki.beep(); // beep!
             int moveF = mazeF-8; //calculate distance to move through maze
                 sparki.print("moveF= "); //print distance on LCD
                 sparki.println(moveF); 
                 sparki.updateLCD();
                 delay(2000);
                 sparki.moveForward(moveF);
        }
        sparki.servo(85);//face right
        delay(2000);
        sparki.ping();
       mazeR = sparki.ping(); // measures the distance
    delay(2000);
    sparki.print("mazeR= "); 
    sparki.println(mazeR); 
    sparki.updateLCD();
    delay(2000);
        if((mazeF < 16) && ( mazeR > 14))
       {
         sparki.beep(); // beep!
             int moveR = mazeR-8; 
                 sparki.print("moveR= "); 
                 sparki.println(moveR); 
                 sparki.updateLCD();
                 delay(2000);
                 sparki.moveRight(90);
                 sparki.moveForward(moveR);
       }
       sparki.servo(-85);
        delay(2000);
        sparki.ping();
       mazeL = sparki.ping(); // measures the distance 
    delay(2000);
    sparki.print("mazeL= "); 
    sparki.println(mazeL); 
    sparki.updateLCD();
    delay(2000);
        if((mazeF < 16)&&( mazeR<16) &&(mazeL>14))
       {
         sparki.beep(); // beep!
             int moveL = mazeL-8; 
                 sparki.print("moveL= "); 
                 sparki.println(moveL); 
                 sparki.updateLCD();
                 delay(2000);
                 sparki.moveLeft(90);
                 sparki.moveForward(moveL);
       }
       if((mazeF < 16)&&( mazeR<16) &&(mazeL<16))
       {
         sparki.beep();
         sparki.gripperClose(3);
         delay(1000);
         sparki.moveRight(180);
       }
        
    
    
    sparki.clearLCD();
    delay(100); // wait 0.1 seconds (100 milliseconds)
}

Here is a video of Sparki navigating a maze using this code:

https://drive.google.com/file/d/0B6y9ITteBcqLTWJGNnJDNHFQOE0/view?usp=sharing

And here is another photo of the cute robot:

DSC_0243_1

Let me know what you think 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s