Shop OBEX P1 Docs P2 Docs Learn Events
Sumobot: Navigate using Infrared whilst detecting light soure (HELP) — Parallax Forums

Sumobot: Navigate using Infrared whilst detecting light soure (HELP)

jarelyojarelyo Posts: 2
edited 2014-04-25 15:56 in BASIC Stamp
I would like to ask for you help on coding my sumobot for Infrared navigation (avoid obstacles) whilst searching for light source. I am using Infrared sensor to avoid objects and light dependent resistor for detecting light source. I have created a code for each of the task but i am having trouble putting them together to become one code.

AVOID OBSTACLE:

'
[ I/O Definitions ]

IrLedLF PIN 4 ' Left IR LED connected to P4
IrSenseLF PIN 11 ' Left IR detector to P11

IrLedRF PIN 15 ' Right IR LED connected to P15
IrSenseRF PIN 14 ' Right IR detector to P14

'
[ Variables ]

irLF VAR Bit ' State of Left Front IR
irRF VAR Bit ' State of Right Front IR
frequency VAR Word ' Stores Frequencies

'
[ Initialization ]

DEBUG CLS, "FRONT IR DETECTORS", CR, ' Display heading
"Frequency Left Right", CR,
"
----
", CR

'
[ Main Routine ]

DO
FOR frequency = 0 TO 42000 STEP 75

FREQOUT IrLedLF, 1, frequency ' Left IRLED shines IR light
irLF = ~IrSenseLF ' Save IR receiver output

FREQOUT IrLedRF, 1, frequency ' Repeat for right IRLED/receiver
irRF = ~IrSenseRF


IF irLF = 0 AND irRF = 0 THEN

pulseLeft = 825
pulseRight = 650

PULSOUT 13,pulseLeft ' Apply the pulse.
PULSOUT 12,pulseRight


ELSEIF irLF = 1 THEN
pulseLeft = 850
PULSOUT 13,pulseLeft ' Apply the pulse.


ELSEIF irRF = 1 THEN
pulseRight = 650
PULSOUT 12,pulseRight

ENDIF

PAUSE 10 ' Delay for slower PCs

NEXT
LOOP



Light search:(this code is not mine, i got this from boebot book)

'
[ Variables ]

' Declare variables for storing measured RC times of the
' left & right photoresistors.

timeLeft VAR Word
timeRight VAR Word
average VAR Word
difference VAR Word

'
[ Initialization ]

FREQOUT 4, 2000, 3000

'
[ Main Routine ]

DO

GOSUB Test_Photoresistors
GOSUB Average_And_Difference
GOSUB Navigate

LOOP

'
[ Subroutine - Test_Photoresistors ]

Test_Photoresistors:

HIGH 6 ' Left RC time Measurement.
PAUSE 3
RCTIME 6,1,timeLeft

HIGH 3 ' Right RC time measurement.
PAUSE 3
RCTIME 3,1,timeRight

RETURN

'
[ Subroutine - Average_And_Difference ]

Average_And_Difference:

average = timeRight + timeLeft / 2
difference = average / 6

RETURN

'
[ Subroutine - Navigate ]

Navigate:

' Shadow significantly stronger on left detector, turn right.
IF (timeLeft > timeRight + difference) THEN
PULSOUT 13, 850
PULSOUT 12, 850
' Shadow significantly stronger on right detector, turn left.
ELSEIF (timeRight > timeLeft + difference) THEN
PULSOUT 13, 650
PULSOUT 12, 650
' Shadows in same neighborhood of intensity on both detectors.
ELSE
PULSOUT 13, 850
PULSOUT 12, 650
ENDIF

PAUSE 10

RETURN

Comments

  • jarelyojarelyo Posts: 2
    edited 2014-04-25 06:59
    I actually solved the problem myself. If you need the codes, message me.
  • FranklinFranklin Posts: 4,747
    edited 2014-04-25 15:56
    It will help others if you posted your solution here.
    attachment.php?attachmentid=78421&d=1297987572
Sign In or Register to comment.