Help with my program
C.J. Powers
Posts: 5
Hi I'm really new at programming and the boebot. I could use some help combining two programs I have working independently already.
one is avoiding the edge of a table with IR sensors.
which looks like this:
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program Running!"
irDetectLeft VAR Bit ' Variable declarations.
irDetectRight VAR Bit
pulseLeft VAR Word
pulseRight VAR Word
loopCount VAR Byte
pulseCount VAR Byte
FREQOUT 4, 2000, 3000 ' Signal program start/reset.
DO ' Main Routine.
FREQOUT 10, 1, 38500 ' Check IR detectors.
irDetectLeft = IN11
FREQOUT 2, 1, 38500
irDetectRight = IN0
' Decide navigation.
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
pulseCount = 1 ' Both detected,
pulseLeft = 850 ' one pulse forward.
pulseRight = 650
ELSEIF (irDetectRight = 1) THEN ' Right not detected,
pulseCount = 10 ' 10 pulses left.
pulseLeft = 650
pulseRight = 650
ELSEIF (irDetectLeft = 1) THEN ' Left not detected,
pulseCount = 10 ' 10 pulses right.
pulseLeft = 850
pulseRight = 850
ELSE ' Neither detected,
pulseCount = 15 ' back up and try again.
pulseLeft = 650
pulseRight = 850
ENDIF
FOR loopCount = 1 TO pulseCount ' Send pulseCount pulses
PULSOUT 13,pulseLeft
PULSOUT 12,pulseRight
PAUSE 20
NEXT
LOOP
the other is using the CMUcam1 without the appmod, to play a sound when it sees the color it detected.
that program looks like this:
'{$STAMP BS2}
'{$PBASIC 2.5}
RcvData VAR Byte(10)
n VAR Byte
Confid VAR Byte
' Pause 1 second for CMUcam startup
PAUSE 1000
' Send "reset" to sync CMUcam and Stamp
SEROUT 15, 84, [noparse][[/noparse]"RS",CR]
SERIN 14, 84, [noparse][[/noparse]WAIT (":")]
PAUSE 1000
' Green LED on
SEROUT 15, 84, [noparse][[/noparse]"L1 1",CR]
SERIN 14, 84, [noparse][[/noparse]WAIT (":")]
PAUSE 100
' Turn on auto adjust for 5 seconds
SEROUT 15, 84, [noparse][[/noparse]"CR 18 44",CR]
SERIN 14, 84, [noparse][[/noparse]WAIT (":")]
PAUSE 100
' Pause 5 seconds for CMUcam to auto adjust to lighting conditions
PAUSE 5000
' Turn off auto adjust
SEROUT 15, 84, [noparse][[/noparse]"CR 18 44 19 32",CR]
SERIN 14, 84, [noparse][[/noparse]WAIT (":")]
PAUSE 100
' Green LED auto mode
SEROUT 15, 84, [noparse][[/noparse]"L1 2",CR]
SERIN 14, 84, [noparse][[/noparse]WAIT (":")]
PAUSE 100
' Give user time to place color target close in front of camera
PAUSE 5000
' Send command - Set poll mode - only sends one return packet -
' of data after each command - reduces data flow
SEROUT 15, 84, [noparse][[/noparse]"PM 1",CR]
SERIN 14, 84, [noparse][[/noparse]WAIT (":")]
PAUSE 100
' Send command - Set raw data mode - also suppress Ack:/Nak: to -
' further reduce serial data
SEROUT 15, 84, [noparse][[/noparse]"RM 3",CR]
PAUSE 100
' Track Window command looks at the center of CMUcam image -
' grabs the color information and sends to the Track Color function
' Send command - Track window
SEROUT 15, 84, [noparse][[/noparse]"TW",CR]
' Ignore the S packet and M packet from TW
PAUSE 2000
Main:
' Send command - Track color (with no arguments) -
' will track last color grabbed by TW command
SEROUT 15, 84, [noparse][[/noparse]"TC",CR]
SERIN 14, 84, [noparse][[/noparse]STR RcvData\10]
Confid = RcvData(9)
' 45 is aprox H center
IF RCVData(2) > 65 AND Confid > 20 THEN Left
IF RCVData(2) < 25 AND Confid > 20 THEN Left
IF RCVData(8) < 150 AND Confid > 25 THEN Left
' Trim the pulsout numbers for your servos
GOTO Main
Left:
FOR n = 1 TO 10
FREQOUT 4, 2000, 3000
GOTO main
the idea behind it is to have the camera run its camera color program show the camera the color, remove the color and place it somewhere on the table top, then drive on the table top until the color is found, then play the sound, and stop.
I'm having a lot of trouble with the program, and help would be greatly appreciated.
Thanks.
one is avoiding the edge of a table with IR sensors.
which looks like this:
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program Running!"
irDetectLeft VAR Bit ' Variable declarations.
irDetectRight VAR Bit
pulseLeft VAR Word
pulseRight VAR Word
loopCount VAR Byte
pulseCount VAR Byte
FREQOUT 4, 2000, 3000 ' Signal program start/reset.
DO ' Main Routine.
FREQOUT 10, 1, 38500 ' Check IR detectors.
irDetectLeft = IN11
FREQOUT 2, 1, 38500
irDetectRight = IN0
' Decide navigation.
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
pulseCount = 1 ' Both detected,
pulseLeft = 850 ' one pulse forward.
pulseRight = 650
ELSEIF (irDetectRight = 1) THEN ' Right not detected,
pulseCount = 10 ' 10 pulses left.
pulseLeft = 650
pulseRight = 650
ELSEIF (irDetectLeft = 1) THEN ' Left not detected,
pulseCount = 10 ' 10 pulses right.
pulseLeft = 850
pulseRight = 850
ELSE ' Neither detected,
pulseCount = 15 ' back up and try again.
pulseLeft = 650
pulseRight = 850
ENDIF
FOR loopCount = 1 TO pulseCount ' Send pulseCount pulses
PULSOUT 13,pulseLeft
PULSOUT 12,pulseRight
PAUSE 20
NEXT
LOOP
the other is using the CMUcam1 without the appmod, to play a sound when it sees the color it detected.
that program looks like this:
'{$STAMP BS2}
'{$PBASIC 2.5}
RcvData VAR Byte(10)
n VAR Byte
Confid VAR Byte
' Pause 1 second for CMUcam startup
PAUSE 1000
' Send "reset" to sync CMUcam and Stamp
SEROUT 15, 84, [noparse][[/noparse]"RS",CR]
SERIN 14, 84, [noparse][[/noparse]WAIT (":")]
PAUSE 1000
' Green LED on
SEROUT 15, 84, [noparse][[/noparse]"L1 1",CR]
SERIN 14, 84, [noparse][[/noparse]WAIT (":")]
PAUSE 100
' Turn on auto adjust for 5 seconds
SEROUT 15, 84, [noparse][[/noparse]"CR 18 44",CR]
SERIN 14, 84, [noparse][[/noparse]WAIT (":")]
PAUSE 100
' Pause 5 seconds for CMUcam to auto adjust to lighting conditions
PAUSE 5000
' Turn off auto adjust
SEROUT 15, 84, [noparse][[/noparse]"CR 18 44 19 32",CR]
SERIN 14, 84, [noparse][[/noparse]WAIT (":")]
PAUSE 100
' Green LED auto mode
SEROUT 15, 84, [noparse][[/noparse]"L1 2",CR]
SERIN 14, 84, [noparse][[/noparse]WAIT (":")]
PAUSE 100
' Give user time to place color target close in front of camera
PAUSE 5000
' Send command - Set poll mode - only sends one return packet -
' of data after each command - reduces data flow
SEROUT 15, 84, [noparse][[/noparse]"PM 1",CR]
SERIN 14, 84, [noparse][[/noparse]WAIT (":")]
PAUSE 100
' Send command - Set raw data mode - also suppress Ack:/Nak: to -
' further reduce serial data
SEROUT 15, 84, [noparse][[/noparse]"RM 3",CR]
PAUSE 100
' Track Window command looks at the center of CMUcam image -
' grabs the color information and sends to the Track Color function
' Send command - Track window
SEROUT 15, 84, [noparse][[/noparse]"TW",CR]
' Ignore the S packet and M packet from TW
PAUSE 2000
Main:
' Send command - Track color (with no arguments) -
' will track last color grabbed by TW command
SEROUT 15, 84, [noparse][[/noparse]"TC",CR]
SERIN 14, 84, [noparse][[/noparse]STR RcvData\10]
Confid = RcvData(9)
' 45 is aprox H center
IF RCVData(2) > 65 AND Confid > 20 THEN Left
IF RCVData(2) < 25 AND Confid > 20 THEN Left
IF RCVData(8) < 150 AND Confid > 25 THEN Left
' Trim the pulsout numbers for your servos
GOTO Main
Left:
FOR n = 1 TO 10
FREQOUT 4, 2000, 3000
GOTO main
the idea behind it is to have the camera run its camera color program show the camera the color, remove the color and place it somewhere on the table top, then drive on the table top until the color is found, then play the sound, and stop.
I'm having a lot of trouble with the program, and help would be greatly appreciated.
Thanks.
Comments
I know which part of the programs do what, but changing them to mesh isn't working for me. I need to right the programs basicly likes this but with the proper algorithm:
Calibrations
main
Table top program
if color is found
then beep
goto main
but I need help writing it... if anyone has the time.
As a side note, when posting code use either the attach option (for large blocks/full programs) or the code tags (for smaller snippets).
-Tony Stark, Stark Industries
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering