Need Suggestions/Help on GP2D12 on Boe Bot.
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 out .
Thanks for the help
Don "Ho"
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 out .
Thanks for the help
Don "Ho"
Comments
·· 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
·'{$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"
·· 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
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.
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 Savage
Parallax Tech Support
csavage@parallax.com