IR Coding
SolEmo
Posts: 15
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
' {$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
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?
What did you change?
What is FirstParking vs SecondParking supposed to do?
Add some comments so we know what you intend to do.
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?