Shop OBEX P1 Docs P2 Docs Learn Events
IR Coding — Parallax Forums

IR Coding

SolEmoSolEmo Posts: 15
edited 2013-07-30 10:25 in General Discussion
Hoping someone can tell me why my coding for the IR does not work at all??

' {$STAMP BS2}
' {$PBASIC 2.5}


DEBUG "PROGRAM RUNNING!!!"


'----[I/O]----


ServoLeft PIN 13
ServoRight PIN 12
IrLedLS PIN 2
IrSenseLS PIN 1
IrLedLF PIN 4
IrSenseLF PIN 11
IrLedRF PIN 15
IrSenseRF PIN 14
IrLedRS PIN 3
IrSenseRS PIN 0
LeDSpeaker PIN 5


'----[Constants]----
Forward CON 0 ' Forward
Backward CON 1 ' Backward
RotateLeft CON 2 ' RotateLeft
RotateRight CON 3 ' RotateRight
PivotLeft CON 4 ' Pivot to the left
PivotRight CON 5 ' Pivot to the right
CurveLeft CON 6 ' Curve to the left
CurveRight CON 7 ' Curve to the right
' Servo pulse width rotations
FS_CCW CON 850 ' Full speed counterclockwise
FS_CW CON 650 ' Full speed clockwise
NO_ROT CON 750 ' No rotation
LS_CCW CON 770 ' Low speed counterclockwise
LS_CW CON 730 ' Low speed clockwise
' IR object detectors
IrFreq CON 32600


'----[Variables]----
temp VAR Word
maneuver VAR Nib
sensors VAR Byte
counter VAR Word
FREQOUT 4,2000,3000
irBits VAR Nib


irLF VAR Bit
irRF VAR Bit


'----[initialization]----


Start_Delay:
FOR counter= 1 TO 3
PAUSE 900
FREQOUT LedSpeaker,1000,3000


NEXT


'
[Main Routine]


FREQOUT 4,2000,3000




GOSUB Forward_Go
IF (irLF=1) THEN
GOSUB SecondParking
ELSEIF (irLF=0) THEN
GOSUB FirstParking
ENDIF
END


Stop_GO:
FOR counter=1 TO 80
PULSOUT 13,750
PULSOUT 12,750
PAUSE 20
NEXT
RETURN


Forward_Go:
FOR counter=1 TO 80
PULSOUT 13,850
PULSOUT 12,650
PAUSE 20


NEXT
RETURN


FirstParking:
FOR counter=1 TO 15
PULSOUT 13,850
PULSOUT 12,850
PAUSE 20


NEXT


PAUSE 20


FOR counter=1 TO 85
PULSOUT 13,650
PULSOUT 12,850
PAUSE 20


NEXT


PAUSE 20


FOR counter=1 TO 15
PULSOUT 13,650
PULSOUT 12,650
PAUSE 20


NEXT


PAUSE 20


FOR counter=1 TO 5
PULSOUT 13,650
PULSOUT 12,850
PAUSE 20


NEXT
GOSUB Servos_And_Sensors
RETURN


SecondParking:
FOR counter=1 TO 54
PULSOUT 13,850
PULSOUT 12,650
PAUSE 20


NEXT


FOR counter=1 TO 15
PULSOUT 13,850
PULSOUT 12,850
PAUSE 20


NEXT
PAUSE 20
FOR counter=1 TO 73
PULSOUT 13,650
PULSOUT 12,850
PAUSE 20


NEXT


FOR counter=1 TO 14
PULSOUT 13,650
PULSOUT 12,650
PAUSE 20


NEXT


FOR counter=1 TO 4
PULSOUT 13,650
PULSOUT 12,850
PAUSE 20


NEXT
GOSUB Servos_And_Sensors
RETURN


'
[ Subroutine - Servos_And_Sensors ]
Servos_And_Sensors:
GOSUB Pulse_Servos ' Call Pulse_Servos subroutine
' Call sensor subroutine(s)
sensors = 0 ' Clear previous sensor values
GOSUB Read_Object_Detectors ' Call Read_Object_Detectors
RETURN


Read_Object_Detectors:


FREQOUT IrLedRF, 1, IrFreq ' Repeat for right-front
irRF = ~IrSenseRF
FREQOUT IrLedLF, 1, IrFreq ' Repeat for left-front
irLF = ~IrSenseLF
RETURN


'
[ Subroutine - Pulse_Servos ]
Pulse_Servos:
' Pulse to left servo
LOOKUP maneuver, [ NO_ROT ], temp
PULSOUT ServoLeft, temp
' Pulse to right servo
LOOKUP maneuver, [ NO_ROT], temp
PULSOUT ServoRight, temp
' Pause between pulses (remove when using IR object detectors + QTIs).
PAUSE 20

Comments

  • SolEmoSolEmo Posts: 15
    edited 2013-07-30 02:33
    I am quite new on using parallax. Please help me!!
  • stamptrolstamptrol Posts: 1,731
    edited 2013-07-30 04:53
    In fairness to those who will step up to help you, you should provide a bit more information!

    What doesn't work? Does the code load into the Stamp?

    What have you done to isolate the problem to one section of code?

    Do you see anything on the DEBUG screen? Do the FREQOUT statements generate any tones or activity from the IRLeds?
  • ercoerco Posts: 20,259
    edited 2013-07-30 09:30
    Where did your code come from?

    What did you change?

    What is FirstParking vs SecondParking supposed to do?

    Add some comments so we know what you intend to do.
  • skylightskylight Posts: 1,915
    edited 2013-07-30 10:10
    Should this be moved to the basic stamp forum?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-07-30 10:14
    As I said in your third thread on this topic:
    Duane Degn wrote: »
    By starting a new thread (this one makes three) about the same topic, readers can't see what help has already been offered.

    For example, someone might suggest using code tags in order to make your code more readable without realizing such action has already be suggested(and is still a good idea).

    Now this thread make four. This is getting has gotten ridiculous.

    If you had replied in an earlier thread, you could have told us how the code you posted above differed from other versions of code you've posted (all without code tags).

    Are you just trying to make it hard for others to help you?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-07-30 10:25
    Please do not start multiple threads for the same subject. Follow up in the original thread until your question is solved. Duplicate threads cause confusion, lack any history and are not allowed.
Sign In or Register to comment.