How do I combine two codes together?
I want to combine "RoamingWithWhiskers.bs2" and "FastIrRoaming.bs2". I am completely new to this and when I try to copy and paste what I think needs to be combined, it gives me a label is missing ':' error.
The code for "RoamingWithWhiskers.bs2" is:
'
[noparse][[/noparse] Title ]
' Robotics with the Boe-Bot - RoamingWithWhiskers.bs2
' Boe-Bot uses whiskers to detect objects, and navigates around them.
' {$STAMP BS2} ' Stamp directive.
' {$PBASIC 2.5} ' PBASIC directive.
DEBUG "Program Running!"
'
[noparse][[/noparse] Variables ]
pulseCount VAR Byte ' FOR...NEXT loop counter.
'
[noparse][[/noparse] Initialization ]
FREQOUT 4, 2000, 3000 ' Signal program start/reset.
'
[noparse][[/noparse] Main Routine ]
DO
IF (IN5 = 0) AND (IN7 = 0) THEN ' Both whiskers detect obstacle
GOSUB Back_Up ' Back up & U-turn (left twice)
GOSUB Turn_Left
GOSUB Turn_Left
ELSEIF (IN5 = 0) THEN ' Left whisker contacts
GOSUB Back_Up ' Back up & turn right
GOSUB Turn_Right
ELSEIF (IN7 = 0) THEN ' Right whisker contacts
GOSUB Back_Up ' Back up & turn left
GOSUB Turn_Left
ELSE ' Both whiskers 1, no contacts
GOSUB Forward_Pulse ' Apply a forward pulse
ENDIF ' and check again
LOOP
'
[noparse][[/noparse] Subroutines ]
Forward_Pulse: ' Send a single forward pulse.
PULSOUT 13,850
PULSOUT 12,688
PAUSE 20
RETURN
Turn_Left: ' Left turn, about 90-degrees.
FOR pulseCount = 0 TO 20
PULSOUT 13, 650
PULSOUT 12, 688
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 20 ' Right turn, about 90-degrees.
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Back_Up: ' Back up.
FOR pulseCount = 0 TO 40
PULSOUT 13, 650
PULSOUT 12, 817
PAUSE 20
NEXT
RETURN
And this code for "FastIrRoaming.bs2" is:
' Robotics with the Boe-Bot - FastIrRoaming.bs2
' Higher performance IR object detection assisted navigation
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program Running!"
irDetectLeft VAR Bit ' Variable Declarations
irDetectRight VAR Bit
pulseLeft VAR Word
pulseRight VAR Word
FREQOUT 4, 2000, 3000 ' Signal program start/reset.
DO ' Main Routine
FREQOUT 8, 1, 38500 ' Check IR Detectors
irDetectLeft = IN9
FREQOUT 2, 1, 38500
irDetectRight = IN0
' Decide how to navigate.
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
pulseLeft = 650
pulseRight = 812
ELSEIF (irDetectLeft = 0) THEN
pulseLeft = 850
pulseRight = 812
ELSEIF (irDetectRight = 0) THEN
pulseLeft = 650
pulseRight = 688
ELSE
pulseLeft = 850
pulseRight = 688
ENDIF
PULSOUT 13,pulseLeft ' Apply the pulse.
PULSOUT 12,pulseRight
PAUSE 15
LOOP ' Repeat main routine
I have tested both of these codes seperately to make sure my Boe-Bot is responding correctly to the IR LED's and the Whiskers. Any help would be greatly appreciated!
The code for "RoamingWithWhiskers.bs2" is:
'
[noparse][[/noparse] Title ]
' Robotics with the Boe-Bot - RoamingWithWhiskers.bs2
' Boe-Bot uses whiskers to detect objects, and navigates around them.
' {$STAMP BS2} ' Stamp directive.
' {$PBASIC 2.5} ' PBASIC directive.
DEBUG "Program Running!"
'
[noparse][[/noparse] Variables ]
pulseCount VAR Byte ' FOR...NEXT loop counter.
'
[noparse][[/noparse] Initialization ]
FREQOUT 4, 2000, 3000 ' Signal program start/reset.
'
[noparse][[/noparse] Main Routine ]
DO
IF (IN5 = 0) AND (IN7 = 0) THEN ' Both whiskers detect obstacle
GOSUB Back_Up ' Back up & U-turn (left twice)
GOSUB Turn_Left
GOSUB Turn_Left
ELSEIF (IN5 = 0) THEN ' Left whisker contacts
GOSUB Back_Up ' Back up & turn right
GOSUB Turn_Right
ELSEIF (IN7 = 0) THEN ' Right whisker contacts
GOSUB Back_Up ' Back up & turn left
GOSUB Turn_Left
ELSE ' Both whiskers 1, no contacts
GOSUB Forward_Pulse ' Apply a forward pulse
ENDIF ' and check again
LOOP
'
[noparse][[/noparse] Subroutines ]
Forward_Pulse: ' Send a single forward pulse.
PULSOUT 13,850
PULSOUT 12,688
PAUSE 20
RETURN
Turn_Left: ' Left turn, about 90-degrees.
FOR pulseCount = 0 TO 20
PULSOUT 13, 650
PULSOUT 12, 688
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 20 ' Right turn, about 90-degrees.
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Back_Up: ' Back up.
FOR pulseCount = 0 TO 40
PULSOUT 13, 650
PULSOUT 12, 817
PAUSE 20
NEXT
RETURN
And this code for "FastIrRoaming.bs2" is:
' Robotics with the Boe-Bot - FastIrRoaming.bs2
' Higher performance IR object detection assisted navigation
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program Running!"
irDetectLeft VAR Bit ' Variable Declarations
irDetectRight VAR Bit
pulseLeft VAR Word
pulseRight VAR Word
FREQOUT 4, 2000, 3000 ' Signal program start/reset.
DO ' Main Routine
FREQOUT 8, 1, 38500 ' Check IR Detectors
irDetectLeft = IN9
FREQOUT 2, 1, 38500
irDetectRight = IN0
' Decide how to navigate.
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
pulseLeft = 650
pulseRight = 812
ELSEIF (irDetectLeft = 0) THEN
pulseLeft = 850
pulseRight = 812
ELSEIF (irDetectRight = 0) THEN
pulseLeft = 650
pulseRight = 688
ELSE
pulseLeft = 850
pulseRight = 688
ENDIF
PULSOUT 13,pulseLeft ' Apply the pulse.
PULSOUT 12,pulseRight
PAUSE 15
LOOP ' Repeat main routine
I have tested both of these codes seperately to make sure my Boe-Bot is responding correctly to the IR LED's and the Whiskers. Any help would be greatly appreciated!
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
'
[noparse][[/noparse] Title ]
' Robotics with the Boe-Bot - Roaming With Whiskers and Fast IR.bs2
' Boe-Bot uses whiskers to detect objects, and navigates around them.
' {$STAMP BS2} ' Stamp directive.
' {$PBASIC 2.5} ' PBASIC directive.
DEBUG "Roaming With Whiskers and Fast IR"
'
[noparse][[/noparse] Variables ]
pulseCount VAR Byte ' FOR...NEXT loop counter.
irDetectLeft VAR Bit
irDetectRight VAR Bit
pulseLeft VAR Word
pulseRight VAR Word
'
[noparse][[/noparse] Initialization ]
FREQOUT 4, 2000, 3000 ' Signal program start/reset.
'
[noparse][[/noparse] Main Routine ]
'
IR Routine
DO
· FREQOUT 8, 1, 38500 ' Check IR Detectors
· irDetectLeft = IN9
· FREQOUT 2, 1, 38500
· irDetectRight = IN0
· IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN ' Decide how to navigate.
··· pulseLeft = 650
··· pulseRight = 812
· ELSEIF (irDetectLeft = 0) THEN
··· pulseLeft = 850
··· pulseRight = 812
· ELSEIF (irDetectRight = 0) THEN
··· pulseLeft = 650
··· pulseRight = 688
· ELSE
··· pulseLeft = 850
··· pulseRight = 688
· ENDIF
'
Whisker Routine
· PULSOUT 13,pulseLeft ' Apply the pulse.
· PULSOUT 12,pulseRight
· PAUSE 15
· IF (IN5 = 0) AND (IN7 = 0) THEN ' Both whiskers detect obstacle
··· GOSUB Back_Up ' Back up & U-turn (left twice)
··· GOSUB Turn_Left
··· GOSUB Turn_Left
· ELSEIF (IN5 = 0) THEN ' Left whisker contacts
··· GOSUB Back_Up ' Back up & turn right
··· GOSUB Turn_Right
· ELSEIF (IN7 = 0) THEN ' Right whisker contacts
··· GOSUB Back_Up ' Back up & turn left
··· GOSUB Turn_Left
· ELSE ' Both whiskers 1, no contacts
··· GOSUB Forward_Pulse ' Apply a forward pulse
· ENDIF ' and check again
LOOP
'
[noparse][[/noparse] Subroutines ]
Forward_Pulse: ' Send a single forward pulse.
· PULSOUT 13,850
· PULSOUT 12,688
· PAUSE 20
· RETURN
Turn_Left: ' Left turn, about 90-degrees.
· FOR pulseCount = 0 TO 20
· PULSOUT 13, 650
· PULSOUT 12, 688
··· PAUSE 20
· NEXT
· RETURN
Turn_Right:
· FOR pulseCount = 0 TO 20 ' Right turn, about 90-degrees.
··· PULSOUT 13, 850
··· PULSOUT 12, 850
··· PAUSE 20
· NEXT
· RETURN
Back_Up: ' Back up.
· FOR pulseCount = 0 TO 40
··· PULSOUT 13, 650
··· PULSOUT 12, 817
··· PAUSE 20
· NEXT
· RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen