Shop OBEX P1 Docs P2 Docs Learn Events
Sharp GP2D02 and servos — Parallax Forums

Sharp GP2D02 and servos

haunteddansionhaunteddansion Posts: 68
edited 2007-01-25 21:22 in BASIC Stamp
I was looking at the posted code (at the bottem) and I was wondering how I would go out interfacing the distance mesured with the motion of a servo? Thanks for the help!







' {$STAMP BS2}
'
' variable declarations
val05· VAR· Byte· ' value where reading is stored
i· VAR· Byte· ' count variable for loop

'
' constant declarations
cl· CON· 14· ' pin 14 is output (clock)
dt· CON· 15· ' pin 15 is the input (data)

'
' I/O pin setup for detector
INPUT dt··· ' make pin 15 the input
HIGH cl····· ' make pin 14 output and high
DEBUG "Start", CR· ' indicate beginning
FOR i = 1 TO 40
· GOSUB read05··· ' take reading
· DEBUG DEC val05, CR· ' display result
· PAUSE 100··· ' stall so display readable
NEXT
DEBUG "Finish", CR· ' indicate end
END····· ' stop Stamp when done

'
' subroutine read05
'
' This subroutine takes a reading from the connected
' GP2D05 detector and stores the value in "val05".
' Any two pins can be used.· Set "dt" to the data line
' of the GP2D05 (pin 3 on JST connector, yellow wire).
' Set cl to the clock line of the GP2D05 (pin 1 on the
' JST connector, green wire).· Also, the IN15 needs
' to be set to the correct variable for the data pin
' (data line).
read05:
· LOW cl··· ' turn on detector for reading
· PAUSE 56··· ' wait 56ms for detector to read
· val05 = IN15··· ' obtain reading from detector
· HIGH cl··· ' turn off detector
· PAUSE 2··· ' wait for reset
RETURN

Comments

  • Tom WalkerTom Walker Posts: 509
    edited 2007-01-18 21:00
    I am not sure that I understand what it is that you are asking..

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...
  • haunteddansionhaunteddansion Posts: 68
    edited 2007-01-18 21:33
    I would like the make the servo move back or forth in regaurd to the distance of my hand to the IR sensor
  • FranklinFranklin Posts: 4,747
    edited 2007-01-19 00:16
    You want the servo to follow your hand? you will need more than one ir sensor and have the servo turn toward the closest reading.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • haunteddansionhaunteddansion Posts: 68
    edited 2007-01-19 01:39
    Can the Ir take a reading say of 20 and make the servo go to 20 degrees and then if the IR sensor gets a reading of 200 can the servo go to another location? A proportional interface between the distance the IR reads and the rotation of the servo.
  • FranklinFranklin Posts: 4,747
    edited 2007-01-19 01:46
    You could write the code to do that but the IR won't do that on it's own.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • haunteddansionhaunteddansion Posts: 68
    edited 2007-01-19 01:52
    Thats true, what would the code look like, I am new to this and trying to learn about these things like interfacing and stuff
  • Special_KSpecial_K Posts: 162
    edited 2007-01-19 03:36
    well try this
    take the val05 ... that is the value you will get from the sharp sensor.. then take some servo code
    like this
    remember to set x as a variable


    I think the servo value can be a variable..??
    remember the GP2D02 does not give you a cm or inch value.

    INPUT dt ' make pin 15 the input
    HIGH cl ' make pin 14 output and high
    DEBUG "Start", CR ' indicate beginning
    FOR i = 1 TO 40
    GOSUB read05 ' take reading
    DEBUG DEC val05, CR ' display result
    PAUSE 100 ' stall so display readable
    NEXT
    FOR i= 1 TO 24
    PULSOUT 13, val05 'servo plugged into pin 13
    PAUSE 20
    NEXT
    PAUSE 200
    DEBUG "Finish", CR ' indicate end
    END ' stop Stamp when done
  • haunteddansionhaunteddansion Posts: 68
    edited 2007-01-21 03:23
    Where do I place this code for the servo to react to the sensor?
  • FranklinFranklin Posts: 4,747
    edited 2007-01-21 19:09
    I'm still not clear on what you want to happen. As you move your hand closer or farther away from the sensor you want a servo to move left or right?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • haunteddansionhaunteddansion Posts: 68
    edited 2007-01-21 19:34
    I would like the servo to move right as you move your hand closer and left as you move your hand farther away. Thanks soo much for the help this is tough
  • FranklinFranklin Posts: 4,747
    edited 2007-01-21 20:00
    OK, get a reading from the sensor, use that reading to determine a value to send to the servo (pulse between 1 and 2 ms with a pause of 20 ms between pulses) and send it. loop back to start (get another reading) Right and left and closer and further will become apparant as you test your results.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • haunteddansionhaunteddansion Posts: 68
    edited 2007-01-21 20:48
    would I modify the code that is pasted at the top of this thread or make a new one, what would the basics of it look like?
  • haunteddansionhaunteddansion Posts: 68
    edited 2007-01-22 05:07
    Also the reading on the debug screen is always 255?
  • haunteddansionhaunteddansion Posts: 68
    edited 2007-01-25 06:10
    What is the constent 255 reading from is because I am using a wrong type of diode, also how can I tie the debug values into servo movements? Thanks soo much I am really in need of help.
  • WarrlokWarrlok Posts: 77
    edited 2007-01-25 15:49
    hey all
    ·if you have a boe bot with the regular ir u should be able to modify the" following boebot" code, but first things first you gonna have to get your ir sensor working ,,try this



    ·· then u could look at modifiying this code


    hope this helps

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Problems are the "roads" of life,
    solutions are only "onramps" to the next problem



    ············································· "Brad Smith"
  • haunteddansionhaunteddansion Posts: 68
    edited 2007-01-25 21:22
    thanks soo much Warrlok, we are getting somewhere now. I was wondering with that first code why I would be getting a reading of a constent number of 510, then when I do get the numbers fluctauting to distance how would I interface the servo with the bs2's pins? Thanks again!
Sign In or Register to comment.