Let's Make Robots! | RobotShop

Light Seeker, with obstacle avoidance

Seek light & avoid obstacles

Update, 21/01/2014

I found that the ultrasonic sensor struggles with "box" obstacles towards its front flanks, probably due to reflection. Therefore to stop it "snagging" i had to add some bump switches (which i have been meaning to do for a while). I tried to add the bumps to interupts, but it ended up being so complex, it was much easier just to add this section of code into the begning of each "forward motion" while loop

      if (digitalRead (LBumper) == LOW) {
        Serial.println("Left Bump interrupt");
        BumpedLaction();
      }
      if (digitalRead (RBumper) == LOW) {
        Serial.println("Right Bump interrupt");
        BumpedRaction();
      }
      else (Crack on!)

The bump code is really Dumb (simple), Upon bump, it backs up for half a second, then turns away from the bump for half a second (pivoting around the wheel on the bumped side) and then returns to the previous action. I have tried to build my sketch using lots of "voids", splitting each "action" into a seperate tab on the IDE. It makes it much easier to keep track of, and saves me from repeating myself over and over again.

It has taken me ages to get it to navigate a really simple course satisfactorly. To be honest, i think if i left it to its own devices it would get there in the end, but i wanted a relatively neat run for a video for you guys!

First Entry

Looking for a new objective, i decided to return to my "cyclops" light seeker, but add obstacle avoidance into it.

Using some Sugru (Awesome Christmas present) ive tidied up my Turret, and added a HC-SR04. 

The objective is to navigate a floor, but to do so while navigating a maze of blockages. At this point they will be simple boxes, but i guess by working on the code and the "rules" it runs by, i could make it navigate proper mazes. The light seeker just acts as a "target" to work towards i guess, rather than just bimbling around in pointless circles

Suugruuuu:


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

It moves good and seeks good!

Congratulations.

Does it take one or several light measures from one site to different angles?

Francisco

Hi Francisco. Thanks! It actually populates an array of around 180 values twice! Once clockwise, once counterclockwise. It is just a regular photoresistor, in a tubular shield. It then looks for the angle at which the light values start to drop down again in each direction.

By having both clockwise and counter clockwise data, it can average anf work out where the brightest light is very accuratly. Ill post that section of the code the next time i am on my pc.

This is the bot with just the light sensing part on board: https://www.robotshop.com/letsmakerobots/node/35071

Its a totally overkill solution, but it works with a single photoresistor, and seems to be very very precise! (and i like it)

 

 

/* Servo Sweep contains two voids. One for Horizontal, one for vertical.
Each populate the angle at which the light is strongest. 
Generally used in conjunction with each other */

void HoriSweep (){ // Horizontal Sweep********

  HoriPos = constrain (HoriPos, 30, 150); // constrain servos, Just in case.
  VertPos = constrain (VertPos, 50, 130);

  for(HoriPos = 30; HoriPos < 150; HoriPos += 1) 
  {    
    Array[HoriPos-30] = analogRead(PR);
    Hori.write(HoriPos);
    if ((Array[HoriPos-30] < Array[HoriPos-31]) && (HoriPos>30)) {
      CWHoriDir = HoriPos;
    }
    delay (10) ;       
  }
  for(HoriPos = 150; HoriPos >= 30; HoriPos -= 1)
  {    
    Array[HoriPos-30] = analogRead(PR);
    Hori.write(HoriPos);
    if ((Array[HoriPos-30] < Array[HoriPos-29]) && (HoriPos<150)) {
      CCWHoriDir = HoriPos;
    }
    delay (10) ;       
  }
  HoriPos = ((CWHoriDir+CCWHoriDir)/2); // Average the two value to get the centre
  Hori.write(HoriPos); // Go to the position, and print the results to serial
  Serial.print("CWSweep: ");
  Serial.print(CWHoriDir);
  Serial.print(", CCWSweep: ");
  Serial.print(CCWHoriDir);
  Serial.print(", HoriPos: ");
  Serial.println(HoriPos);    
  delay (100);
  
}

I have to say Wow!

It's a very nice and elegant sensing solution for mean light measurement!

I sill have to study it in detail but from the video and a brief reading on your code I see it's a very interesting solution. Even more, it can be applied to other type of sensors: sound, IR, and so on...

Good job and keep going!