Shop OBEX P1 Docs P2 Docs Learn Events
Light finding robot dillema — Parallax Forums

Light finding robot dillema

ltmhallltmhall Posts: 102
edited 2007-03-01 21:05 in BASIC Stamp
· Hi I'm designing a robot that will search for light and when it finds it, it'll roam towards it·(similar to the Boe bot robotics example). However,·when the robot doesn’t see the light I want it to rotate 360 degrees and take measurements to find it. But this isn't possible because the microcontroller won't be able to·take measurements because it's rotating the wheels. If I were to use a servo controller to control my motors, would I be able to take measurements with the microcontroller because the servo controller would make the wheels rotate?

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2007-03-01 14:45
    Since the Servo control signal is a simple pulse (1 mSec to 2 mSec, depending on direction and speed) repeated every 20 mSec to 50 mSec, your processor has LOTS of time in which to look for the light.

    However, if it needs more time, then yes, using the Parallax Servo Controller board would let you off-load the servo refresh duties. However, your robot STILL needs to hold still while making its measurement -- how else is your robot going to have any idea where it was 'pointing' when it made its measurement?

    "Hold still" here is a relative term -- it can come to a stop, make a measurement in 100 mSec, then move again.
  • ltmhallltmhall Posts: 102
    edited 2007-03-01 17:14
    So maybe it would be better to stop and make quarter turns to complete a circle and when it stops make the measurements?
  • edited 2007-03-01 18:03
    The Robotics with the Boe-Bot·v2.2 (pdf)·light following example uses a pair of circuits, each with a light dependent resistor (LDR) and a capacitor (see page 208).· The BASIC Stamp measures infers the LDR's value by charging the circuit and then measuring its discharge time with the RCTIME command.· This is done between every servo pulse, and the result is a light tracking Boe-Bot.·

    In the light following example, the capacitors are selected so that the Boe-Bot can "see" under dim or bright lighting conditions.· Under bright lighting conditions, a larger capacitor is needed because the LDR's values are pretty small, so the decay times are also small.· If it is placed in dim lighting conditions, the LDR's value gets larger, which means the decay time takes longer.· The problem is that the decay measurements take long enough to delay the servo control pulses, to the point where the Boe-Bot gets sluggish because the servo signals just aren't updating rapidly enough.· Pulses every 20 ms is optimal; delays greater than about 45 ms really slow the Boe-Bot down.

    Here is an example of a circuit you can use to make the Boe-Bot adjust to different lighting conditions.· In bright light, set P4 to input, and set P5 low.· Then, take RCTIME measurements.· In dim light, set P5 to input and P4 low.· The capacitor that gets charged and discharged is 10 times smaller, and so it compensates for the longer decay times that result from larger LDR values.


    attachment.php?attachmentid=45671

    Depending on the conditions your robot is operating under, you may want to scale down both capacitors by 1/10, or increase the range by adding a third capacitor that's 0.001 uF.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 3/1/2007 6:38:46 PM GMT
    489 x 161 - 28K
  • ltmhallltmhall Posts: 102
    edited 2007-03-01 18:28
    Sorry to be Redundant, but this circuit above will allow my robot to move towards light much quicker than
    the other circuit. If i'm planning on using this new circuit in a bright light area, I set p4 as an input and p5 low.
    What about p6. Are p6 and p4 both inputs ?
  • edited 2007-03-01 18:36
    The RC Decay measurement is performed on P6. The program on page 210·of Robotics with the Boe-Bot v2.2 would be modified so that it either sets (P5 low, P4 input) or (P5 input, P4 low) before taking the RC decay measurement. (This modification should be made between the DO and HIGH commands.)· If the current capacitor results in RC decay measurements above 10 ms (5000) or below, say 2 ms (1000), the program·could switch to the smaller or larger capacitor to divide (or multiply) the measurement range by 10.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 3/1/2007 6:42:40 PM GMT
  • edited 2007-03-01 19:03
    Here is some example code to test the modified circuit.· Make sure the LDR is connected to Vss for ground.· The ground for the capacitors is controlled by the I/O pins.· As the shade over the LDR increases and the measurement reaches 1000, the display will indicate low light, switch set the large capacitor to input and use the small capacitor, and the measurement range will drop by 1/10.

    ' Robotics with the Boe-Bot - TestP6Photoresistor.bs2
     
    ' MODIFIED for
    ' [url=http://forums.parallax.com/showthread.php?p=635345]http://forums.parallax.com/showthread.php?p=635345[/url]
    ' see schematic at the web address.
     
    ' Test Boe-Bot photoresistor circuit connected to P6 and display
    ' the decay time.  Incorporates one of two different capacitors
    ' into the RC decay circuit based the decay times (light conditions).
     
    ' {$STAMP BS2}                               ' Stamp directive.
    ' {$PBASIC 2.5}                              ' PBASIC directive.
     
    timeLeft       VAR     Word
     
    timeLeft = 0
    LOW 4
    INPUT 5
     
    DO
      ' Adjust for lighting conditions.
      IF timeLeft < 100 THEN
        INPUT 4
        LOW 5
        DEBUG CR, "High Light", CLREOL
      ELSEIF timeLeft > 1000  THEN
        INPUT 5
        LOW 4
        DEBUG CR, "Low light", CLREOL
      ENDIF
     
      ' Take RC decay measurement. 
      HIGH 6
      PAUSE 2
      RCTIME 6,1,timeLeft
      DEBUG HOME, "timeLeft = ", DEC5 timeLeft
      PAUSE 500
     
    LOOP
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 3/1/2007 7:08:42 PM GMT
  • ltmhallltmhall Posts: 102
    edited 2007-03-01 19:20
    So my P6 would be used for the normal RC measurement and depending on what that value is the program could
    switch one of the capacitors.

    I started imagining how to 4write this. I'm still a little confused. If one of the pins becomes low, the other becomes an
    input (to switch to one of the capacitors). So would I then want to use the input pin and record its's value and divide( or
    multiply it) depending on how I want to adjust the range.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    timeLeft VAR Word
    time_4 VAR Word
    time_5 VAR Word

    DO
    HIGH 6
    PAUSE 2
    RCTIME 6,1,timeLeft ' Photo resistor takes measurement from pin 6
    If timeLeft > 5000 Then ' this being the value from photoresistor in bright light
    Low 5 ' Pin 5 low
    Gosub Get_4
    ElseIf
    If timeLeft < 1000 ' this being the value from photoresistor in bright light
    Low 4 ' Pin 4 low
    PAUSE 20
    LOOP

    Get_4
    HIGH 4 ' pin 4 is being used as an input and takine another photoresistor reading with 0.01 cap
    PAUSE 2
    RCTIME 4,1,reading_4
    ' Then multiply or divide value
    Return

    Get_5
    HIGH 5 ' pin 5 is being used as an input and takine another photoresistor reading with 0.1 cap
    PAUSE 2
    RCTIME 4,1,reading_ 5
    ' Then multiply or divide value
    Return

    * I see you beat me to it !
  • edited 2007-03-01 19:28
    itmhall said...
    ...So would I then want to use the input pin and record its's value and divide( or
    multiply it) depending on how I want to adjust the range.
    Yeah, you'll probably want to use a variable to track what mode the circuit is being operated in.· Then, your code will use that value to scale the measurement up (or down).· Remember that your ceiling for word variables is 65535.··I'm pretty sure that·scaling to one measurement range will simplify the Boe-Bot's decision making.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2007-03-01 21:05
    Itmhall

    "So my P6 would be used for the normal RC measurement and depending on what that value is the program could
    switch one of the capacitors."

    If you gave "pseudo binary weights" to the capacitor values....

    i.e.

    .01uF
    .022uF
    .047uF
    .1uF

    ...you could switch multiple capacitors for even more detailed resolution and/or scaling techniques.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
Sign In or Register to comment.