Code source en BasicStamp BS2sx de la CMUCAM

Forum sur la programmation Basic Stamp
Répondre
andromeda
Messages : 706
Enregistré le : 30 mars 2004 0:07
Contact :

Code source en BasicStamp BS2sx de la CMUCAM

Message par andromeda » 05 mars 2007 11:28

Code : Tout sélectionner

'{$STAMP BS2sx}
' CMUcam Boe-Bot Demo Program 3
' Copyright 2002, Seattle Robotics
' Basic Stamp 2
' CMUcam jumpered for Baud 9600
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 10, 240, ["RS",CR]
serin 9, 240, [Wait (":")]
pause 5000


' Green LED on
serout 10, 240, ["L1 1",CR]
serin 9, 240, [Wait (":")]
pause 100

' Pause 5 seconds for CMUcam to auto adjust to lighting conditions
'pause 5000

serout 10, 240, ["CR 18 32 19 32",CR]
serin 9, 240, [Wait (":")]
pause 5000

' Green LED auto mode
serout 10, 240, ["L1 2",CR]
serin 9, 240, [Wait (":")]
pause 100

' Give user time to place color target close in front of camera
pause 2000

' Send command - Set poll mode - only sends one return packet -
' of data after each command - reduces data flow
serout 10, 240, ["PM 1",CR]
serin 9, 240, [Wait (":")]
pause 100


' Mode 2
'serout 10, 240, ["MM 2",CR]
'serin 9, 240, [Wait (":")]
'pause 100


' Send command - Set raw data mode - also suppress Ack:/Nak: to -
' further reduce serial data
serout 10, 240, ["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 10, 240, ["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 10, 240, ["TC",CR]
serin 9, 240, [STR RcvData10]
Confid = RcvData(9)

' 45 is aprox H center
If RCVData(2) > 55 And Confid > 20 Then Left
If RCVData(2) < 25 And Confid > 20 Then Right
If RCVData(8) < 130 And Confid > 20 Then Fwd
' Trim the pulsout numbers for your servos
Goto Main

Left:
for n = 1 to 20
pulsout 5,3125 ' 625
pulsout 6,3125 ' 625

next
Goto main
Right:
for n = 1 to 20
pulsout 5,625 ' 3125
pulsout 6,625 ' 3125

next
Goto main
Fwd:
for n = 1 to 20
pulsout 5,3125 ' 3125
pulsout 6,625 ' 625
pause 15
next
Goto main
Moderator - Forum

Répondre