Shop OBEX P1 Docs P2 Docs Learn Events
Need Suggestions/Help on GP2D12 on Boe Bot. — Parallax Forums

Need Suggestions/Help on GP2D12 on Boe Bot.

don_sdon_s Posts: 35
edited 2006-01-13 15:13 in Robotics
I have a boe-bot that I wanted to use the GP2D12 sensors for the front and sides to check distances while it roams the house.· I also have the wheel encoders for the servos.· It is looking like I need to put multiple (Two) Stamps on the Boe-Bot to handle what I want to do.

Is the this the correct way to do it. Have one stamp handle the motor control· and the other stamp handle all the sensors?

Should I scrap the servos of different motors?· I am relative new to this and running out of hair to pull outrolleyes.gif .

Thanks for the help
Don "Ho"

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-01-12 05:37
    Don,

    ·· Why can't you scan your sensors and drive the servos?· It doesn't seem like it would take that long.· You have 20 - 50 mS between servo refresh.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • don_sdon_s Posts: 35
    edited 2006-01-12 12:07
    Thats what I thought I was trying to do but apperently my code is not processing correctly.· At this time all I have connected to the Stamp is the two front sensors using a LTC1298 and switching between CH0 and CH1.· Here is my code (Please dont laugh too much!lol.gif

    ·'{$stamp BS2}
    ' {$pbasic 2.5}

    'This will use a single LTC1298 and dual Sharp GP2D12.
    'This is my second attempt to run this program to allow the Boe-Bot to transvers its
    'universe using the gp2d12 for front eyes.

    '=====================================================
    '········ ADC Interface Pins
    '=====================================================
    CS····· CON· 0···· 'Chip select; 0=Active
    CLK···· CON· 1···· 'Clock to ADC; out on rising, in on falling edge
    DIO_n·· CON· 2···· 'Data I/O pin Number
    config· VAR· Nib·· 'Configuration bits for ADC
    AD····· VAR· Word· 'Variale to hold 12-bit AD result

    '=====================================================
    '········ ADC Setup Bits
    '=====================================================
    startB· VAR· config.bit0·· 'Start bit for comm with ADC
    sglDif· VAR· config.bit1·· 'Single-ended or differential mode.
    oddSign VAR· config.bit2·· 'Channel selection.
    msbf··· VAR· config.bit3·· 'Output 0s after data xfer complete.

    '=====================================================
    '········ Program Variables
    '=====================================================
    Dist····· VAR···· Byte····· 'Convert to Distance.
    leftDist· VAR···· Byte····· 'Left Distance.
    rightDist VAR···· Byte····· 'Right Distance.
    Side····· VAR···· Word····· ' Variable used to display the correct side.
    moving··· VAR···· Byte····· 'Is Bot Moving or Not.
    Frontok·· VAR···· Word····· 'Determine if it is ok to move.
    counter·· VAR···· Byte····· 'Motor Time counter.
    pulsecount· VAR·· Word····· 'Pulse Count for motor
    rightwidth· VAR·· Word
    leftwidth VAR···· Word
    MinDist·· VAR···· Byte
    MaxDist·· VAR···· Byte
    RTopspeed· VAR· Word
    Ltopspeed· VAR· Word

    '=====================================================
    '········ Data Definations
    '=====================================================

    '--- Initialization ---
    LOW 14····················· 'Right Motor.
    LOW 15····················· 'Left Motor.
    MinDist = 10
    MaxDist = 80
    Rtopspeed = 1000
    LTopspeed = 500

    '=====================================================
    '········ Main Program
    '=====================================================
    Main:
    · GOSUB CheckFront
    · IF Moving = 0 THEN
    ····· IF· (leftDist < 2) and (RightDist < 2) THEN
    ········· GOSUB Turn_It
    ······· ELSE
    ········· GOSUB Ramp_UP
    ····· ENDIF
    ··· ELSE
    ····· IF·· LeftDist < 2 and RightDist < 2 THEN
    ·········· GOSUB Ramp_Down
    ····· ENDIF
    ····· IF·· LeftDist < 5 THEN
    ·········· GOSUB Left_Turn
    ····· ENDIF
    ····· IF·· RightDist < 5 THEN
    ·········· GOSUB Right_Turn
    ····· ENDIF
    ····· GOSUB Go_Forward
    · ENDIF

    GOTO Main

    '=====================================================
    '········ Go Forward
    '=====================================================
    Go_Forward:
    · FOR Counter = 1 TO 10
    ··· PULSOUT 14, LTopSpeed
    ··· PULSOUT 15, RTopSpeed
    ··· PAUSE 20
    · NEXT
    RETURN

    '=====================================================
    '········ Right Turn
    '=====================================================
    Right_Turn:
    · FOR pulseCount = 0 TO 20
    ··· PULSOUT 15, 900
    ··· PAUSE 20
    · NEXT
    RETURN

    '=====================================================
    '········ Left Turn
    '=====================================================
    Left_Turn:
    · FOR pulseCount = 0 TO 20
    ··· PULSOUT 14, 500
    ··· PAUSE 20
    · NEXT
    RETURN

    '=====================================================
    '········ Turn It
    '=====================================================
    Turn_It:
    · FOR pulseCount = 0 TO 20
    ··· PULSOUT 14, 650
    ··· PULSOUT 15, 650
    ··· PAUSE 20
    · NEXT
    RETURN

    '=====================================================
    '········ Ramp Up
    '=====================================================
    Ramp_up:
    ··· FOR pulsecount = 0 TO 250 STEP 5
    ····· PULSOUT 14, 750 - pulsecount
    ····· PULSOUT 15, 750 + pulsecount
    ····· PAUSE 20
    ··· NEXT
    ··· Moving = 1
    RETURN

    '=====================================================
    '········ Ramp Down
    '=====================================================
    Ramp_Down:
    ··· FOR pulsecount = 250 TO 0 STEP 5
    ····· PULSOUT 14, 750 - pulsecount
    ····· PULSOUT 15, 750 + pulsecount
    ····· PAUSE 20
    ··· NEXT
    ··· Moving = 0
    RETURN

    '=====================================================
    '········ Check Front
    '=====================================================
    CheckFront:
    · HIGH CS···················· ' Deactivate ADC to begin
    · HIGH DIO_n················· ' Set data pin for first start bit.
    · FOR oddSign = 0 TO 1····· 'Toggle between input channels.
    ······ GOSUB Convert········ 'Get data from ADC.
    ······ GOSUB ConvertToDistance
    ······ PAUSE 500
    ······ SELECT oddSign······· 'Move Distance to the correct Eye.
    ········ CASE = 0
    ············· leftDist = Dist
    ········ CASE = 1
    ············· Rightdist = Dist
    ······ ENDSELECT
    · NEXT
    RETURN

    '=====================================================
    '········ Convert To Distance
    '=====================================================
    ConvertToDistance:
    · SELECT AD
    ··· CASE > 1900
    ····· Dist = 1················ ' Actual Distance = 10
    ··· CASE > 1575
    ····· Dist = 2················ ' Actual Distance = 15
    ··· CASE > 1150
    ····· Dist = 3················ ' Actual Distance = 20
    ··· CASE > = 860
    ····· Dist = 4················ ' Actual Distance = 25
    ··· CASE > 700
    ····· Dist = 5················ ' Actual Distance = 30
    ··· CASE ELSE
    ····· Dist = 6··············· ' Actual Distance = 89 or Greater
    · ENDSELECT
    ·RETURN

    '=====================================================
    '········ ADC Subroutine
    '=====================================================
    convert:
    · config = config|%1011····· 'Set all bits except oddSign.
    · LOW CS···················· 'Activate ADC
    · SHIFTOUT DIO_n, clk, LSBFIRST,[noparse][[/noparse]config\4]······ 'Send config bits.
    · SHIFTIN dio_n,clk,MSBPOST,[noparse][[/noparse]ad\12]············· 'Get data bits.
    · HIGH cs··················· 'Deactivate the ADC.
    RETURN

    I have recently remove the conversion to Actual Distance and using the raw data.·

    Thanks for all the comments and/or suggestions.

    Don "Ho"
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-01-12 15:22
    Don,

    ·· What exactly is your code doing?· I don't see anything in your code regarding the Wheel Encoders.· Also, you should attach your code rather than pasting it into the message as it affects the formatting and makes it difficult to follow, especially since I typically load code into my Stamp Editor.·

    ·· Anyway, when you run the code above, what is happening?· Please provide some details as to what you're trying to do, and what results you are getting.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • don_sdon_s Posts: 35
    edited 2006-01-12 17:46
    Sorry. WIll do on the attachment next time. The Wheel encoders are not in place at this time. Trying to get this code in place and working correctly before I add them. Right now, there is a huge pause between the motor movement (no fluild motor movement.) When I remove the "CheckFront" code the "Go_Forward" works smoothly. Once I put the "CheckFrount" routine back in, the wheels only move 1/8" then pause, then move 1/8 then pause, continulously. Sorry if these are dumb questions, but I am a little slow somethimes and this is getting frustrating. All I want is a boe-bot to roam the house...
    smilewinkgrin.gif
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-01-12 22:39
    Why in the world do you put a 1/2 second delay in your "CheckFront" routine? It doesn't seem to serve any purpose at all -- other than delay your robot's movements. That may fix the problem you're seeing.

    The Servo's really want to be 'refreshed' every 20 to 50 mSec. Everything you're doing should work fine the way you're doing it -- except for that 1/2 second delay in there. That's going to cause the servo's to pulse every time.

    Also, the logic in your main loop looks odd. If LeftDist was < 5, AND RightDist was also < 5, then you'd first turn left, then turn right, then go straight?

    Each time through the loop, wouldn't you want to ONLY turn left, or ONLY turn right, or ONLY go straight? The way you've written it, you ALWAYS go straight, after you may or may not have turned left, then may or may not turn right.

    You probably want a few more 'ELSE' clauses in there.
  • don_sdon_s Posts: 35
    edited 2006-01-13 15:02
    smhair.gif I cannot tell you why I have that there. It might have been left over from a debug Statement. Thanks. I got so fixated on the Forward motor control, I didnt even look at the other peices of code!!..

    I removed that and low and behold, it starting to work the way I want it.

    Yes, the Direction loop does need work and I am on that now.

    Again Thanks alot.

    Don "Ho"
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-01-13 15:13
    allanlane5 said...(trimmed)
    Why in the world do you put a 1/2 second delay in your "CheckFront" routine? It doesn't seem to serve any purpose at all -- other than delay your robot's movements. That may fix the problem you're seeing.
    Nice catch Allan!· I am too spoiled on needing the code in an attachment to load it into the editor.· Once the formatting is lost it makes it so much harder to follow.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
Sign In or Register to comment.