Detecting Obstacles with no contact
Pistu
Posts: 10
With the GP2D120 module, the iZEBOT robot no longer has to touch the obstacle. It only has to
measure the range to see if the distance of the obstacle is closer than the specified range or not. Then the robot will move
backward and change directions immediately.
I`m working wiht a GP2D120 IR sensor.
I`ve changed the HIGH,LOW commands in the Movement Procedure to PULSOUT commands for a slowly movement of the robot...but it`s not working...why?
here is the code...
' {$STAMP BS2sx}
' {$PBASIC 2.5}
ADC VAR Word
R VAR Word
I VAR Byte
X VAR Word
PAUSE 1000
HIGH 10 ' Initial ADC
DO
GOSUB Forward
GOSUB RD_ADC
IF (ADC > 300) THEN ' Distance less than 8 CM ?
GOSUB Backward : PAUSE 1000 ' Yes, backward and spin left
GOSUB S_Left : PAUSE 400
ENDIF
LOOP ' Read again
' Analog to Digital Converter Procedure
RD_ADC: LOW 10: PAUSE 2: HIGH 10 ' Send acknowledge
SEROUT 10,240, ' Select channel
SERIN 10,240,250,Error,[noparse][[/noparse]ADC.BYTE0,ADC.BYTE1] ' Read ADC
RETURN
Error: DEBUG "Error Reading",CR
RETURN
'Movement Procedure
Forward: PULSOUT 15,900 : PULSOUT 13,900 : RETURN
Backward: PULSOUT 14,900 : PULSOUT 12,900 : RETURN
T_Left: PULSOUT 13,900 : RETURN
T_Right: PULSOUT 15,900 : RETURN
S_Left: PULSOUT 14,900 : PULSOUT 13,900 : RETURN
S_Right: PULSOUT 15,900 : PULSOUT 12,900 : RETURN
Motor_OFF: LOW 13 : LOW 12 : LOW 15 : LOW 14 : RETURN
Post Edited (Pistu) : 5/7/2009 7:50:47 PM GMT
measure the range to see if the distance of the obstacle is closer than the specified range or not. Then the robot will move
backward and change directions immediately.
I`m working wiht a GP2D120 IR sensor.
I`ve changed the HIGH,LOW commands in the Movement Procedure to PULSOUT commands for a slowly movement of the robot...but it`s not working...why?
here is the code...
' {$STAMP BS2sx}
' {$PBASIC 2.5}
ADC VAR Word
R VAR Word
I VAR Byte
X VAR Word
PAUSE 1000
HIGH 10 ' Initial ADC
DO
GOSUB Forward
GOSUB RD_ADC
IF (ADC > 300) THEN ' Distance less than 8 CM ?
GOSUB Backward : PAUSE 1000 ' Yes, backward and spin left
GOSUB S_Left : PAUSE 400
ENDIF
LOOP ' Read again
' Analog to Digital Converter Procedure
RD_ADC: LOW 10: PAUSE 2: HIGH 10 ' Send acknowledge
SEROUT 10,240, ' Select channel
SERIN 10,240,250,Error,[noparse][[/noparse]ADC.BYTE0,ADC.BYTE1] ' Read ADC
RETURN
Error: DEBUG "Error Reading",CR
RETURN
'Movement Procedure
Forward: PULSOUT 15,900 : PULSOUT 13,900 : RETURN
Backward: PULSOUT 14,900 : PULSOUT 12,900 : RETURN
T_Left: PULSOUT 13,900 : RETURN
T_Right: PULSOUT 15,900 : RETURN
S_Left: PULSOUT 14,900 : PULSOUT 13,900 : RETURN
S_Right: PULSOUT 15,900 : PULSOUT 12,900 : RETURN
Motor_OFF: LOW 13 : LOW 12 : LOW 15 : LOW 14 : RETURN
Post Edited (Pistu) : 5/7/2009 7:50:47 PM GMT
Comments
In your example (for the Forward) Pulsout 15,900 :Pulsout 13,900 : Return
That only sends out a 720microsecond pulse to each of the motors.
(BS2sx period units each 0.8microseconds * 900 periods = 720microseconds)
If the motors can operate with the pulses then you need to put the Pulsout commands inside a timing loop.
For example here is a bit of my coding for my robot;
The timer values were a bit of hit and miss until it worked but the pulses keep going since they are within the loop.
(I have cut down my full Drive_Routine to make it easier to explain since the full version can act as a (Gosub) routine as well as a (Goto) routine -- since some of the reaction routines have multiple parts to them).
'Drive routine
Drive_Routine:
FOR DriveTimer2 = 0 TO DriveTimer·············· 'Length of time for routine
PULSOUT LeftDriveW, Left_Wheel·················'Drive left wheel
PULSOUT RightDriveW, Right_Wheel···············'Drive right wheel
NEXT····················································· ·'next time
GOTO Main6··············································'back to main program
'Reaction driving values
Full_Reverse:············································ ·' Version 2
· Left_Wheel = 630
· Right_Wheel = 630
· Drivetimer = 800
Left_Turn:·······················' Version 2
· Left_Wheel = 760········ · ' Left hand turn
· Right_Wheel = 1890······ ·' with right wheel
· Drivetimer = 850··········· ·' moving only
· GOTO Drive_Routine
Right_Turn:···················· ·' Version 2
· Left_Wheel = 1890······· · ' Right hand turn
· Right_Wheel = 760······ ·· ' with left wheel
· Drivetimer = 850······· ···· ' moving only
· GOTO Drive_Routine
Sharp_Left_Turn:········· ' Version 2
· Left_Wheel = 630······· ' Left wheel backwards
· Right_Wheel = 1890····· ' right wheel forwards
· Drivetimer = 340······· '
· GOTO Drive_Routine
·