Object Removal Within An Area- Arduino

Hi everyone

Today I’m posting a code which is again based on one of the example codes provided by Arcbotics. In this example, Sparki moves objects out of particular area, keeping one area tidy.

You can see how this would be useful in real life, within warehouses for example where boxes and cardboard may need to be moved.

To accomplish this the example code looks like this: 

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

void setup()
{
  sparki.servo(SERVO_CENTER); // makes the ultrasonic sensor to point forward
}

void loop()
{
  while (sparki.ping() > 15)  // here we can set different distances to detect objects, 
                              //depending on the size of our perimeter
  {
    sparki.moveLeft(); // rotates the robot to the left
    delay(150); // this brief delay is to give enough time to the ultrasonic sensor to work
  }
  delay(250); // instead of stopping immediately, rotates a bit more to center the object

  sparki.moveStop(); // stops all the robot's movements
  delay(100); //waits a few milliseconds before start moving, just to be nice with the motors
  
  while (sparki.lineCenter() > 700)  // here we can set different thresholds to detect the line
  {
    sparki.moveForward(); 
  }

  sparki.moveStop(); // stops all the robot's movements
  delay(100); //waits a few milliseconds before start moving, just to be nice with the motors    
  
  sparki.moveBackward();
  delay(1000); // the bigger this number is, the bigger the distance that the Sparki goes backward
  
  sparki.moveLeft(); // just in case: with this, we prevent Sparki to detect again the same object
  delay(400);
}

Here is my modified code:

#include <Sparki.h>  // include the sparki library
void setup()
{
sparki.servo(0);
}

void loop()
{
sparki.clearLCD();
delay(1000);
sparki.servo(0);
sparki.ping();
while(sparki.ping() > 10)
{
sparki.moveLeft(10); //I want Sparki to move left at short intervals so as not to miss an object
delay(100);
}
delay(100);
sparki.moveStop();//If Sparki detects an object I definitely want him to stop
sparki.RGB(RGB_BLUE);//just a status indicator
sparki.ping();
int moveTo = (sparki.ping()- 2);//if Sparki moves this far I know he will stop just slightly before the object yet close enough to grasp the object between grippers
delay(2000);
sparki.print("moveTo =");//status indicator to show on screen how far he will move
sparki.println(moveTo);
sparki.updateLCD();
delay(1000);
sparki.moveLeft(5);//There are two delays before Sparki stops moving, this step is to counteract this and move in line with the object
sparki.moveForward(moveTo);
delay(1000);
sparki.gripperClose(3);
int edgeLeft= sparki.edgeLeft();
int lineCenter = sparki.lineCenter();
sparki.print("Edge Left: ");
sparki.println(edgeLeft);
sparki.print("Line Center: ");
sparki.println(lineCenter);
sparki.updateLCD();
delay(1000);
if((edgeLeft > 700) && (lineCenter > 700))// this means he is still in the white section (a while loop would probably work here too)
{
sparki.moveForward(5);//the square I have is small and so this can be changed depending on size of area. 5 is only a small amount so it allows the line sensors to check at regular intervals
delay(100);
}
else
{
int edgeLeft= sparki.edgeLeft();
int lineCenter = sparki.lineCenter();
if((edgeLeft < 700) && (lineCenter < 700))//Sparki has reached the black line-edge of the intended area
{
delay(1000);
sparki.moveStop();//after the delay of 1000 Sparki will have continued to move forward and so will take the object past the black lines and into the space beyond
sparki.RGB(RGB_RED);//status indicator
sparki.gripperOpen(3);
sparki.beep();
sparki.RGB(RGB_GREEN);//status indicator
delay(100);
sparki.moveBackward(15);//This is an important part of the program. My area is basically a 30 by 30 square and so to keep Sparki roughly in the centre he is around the 15 mark. There are much more accurate ways to do this although perhaps not with the sensors I have at the current time. A real tile clock for example to time the movements and move backwards for that amount of time.
sparki.moveLeft(20);//this just makes sure the object is not seen again
}

}}

Here is my code in action:

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

And here is Sparki posing for a photo whilst completing his task:

IMG_20150618_195355

Advertisements

2 thoughts on “Object Removal Within An Area- Arduino

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