Basic Stamp + Pixy CMUcam
qqqzhouhk
Posts: 2
in BASIC Stamp
I am a green hand and doing a tracking robot using Pixy and basic stamp. now I can only get the Pan and Tilt value for the camera, and I wrote codes for my robot.(see below) The code doesn't work at all, can anyone help me? I would really appreciate that. Thanks!
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG CLS, "Program Running!!!"
'
[ Variables ]
wheelL VAR Word 'pin15 - L
wheelR VAR Word 'pin14 - R
pan VAR Word 'pin10
tilt VAR Word 'pin11
size VAR Word
followError VAR Word
forwardSpeed VAR Word
differential VAR Word
Center_Pos CON 750
'
[ Initialization ]
FREQOUT 4,2000,3000 'signal program start/reset
'
[ Main Routine ]
DO
PULSIN 10,1,pan
PULSIN 11,1,tilt
DEBUG "pan=",DEC pan," tilt=",DEC tilt,CR
followError = Center_Pos - pan
size = tilt
size = size - size/6
IF(size>700)AND(size<850)THEN forwardSpeed1
IF(size<700)THEN forwardSpeed2
IF(size>850)THEN forwardSpeed3
differential = (followError + (followError*forwardSpeed))/1000
wheelL=forwardSpeed + differential
wheelR=forwardSpeed - differential
PULSOUT 15,wheelL
PULSOUT 14,wheelR
LOOP
forwardSpeed1:
forwardSpeed=850 - size/8
RETURN
forwardSpeed2:
forwardSpeed=700
RETURN
forwardSpeed3:
forwardSpeed=850
RETURN
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG CLS, "Program Running!!!"
'
[ Variables ]
wheelL VAR Word 'pin15 - L
wheelR VAR Word 'pin14 - R
pan VAR Word 'pin10
tilt VAR Word 'pin11
size VAR Word
followError VAR Word
forwardSpeed VAR Word
differential VAR Word
Center_Pos CON 750
'
[ Initialization ]
FREQOUT 4,2000,3000 'signal program start/reset
'
[ Main Routine ]
DO
PULSIN 10,1,pan
PULSIN 11,1,tilt
DEBUG "pan=",DEC pan," tilt=",DEC tilt,CR
followError = Center_Pos - pan
size = tilt
size = size - size/6
IF(size>700)AND(size<850)THEN forwardSpeed1
IF(size<700)THEN forwardSpeed2
IF(size>850)THEN forwardSpeed3
differential = (followError + (followError*forwardSpeed))/1000
wheelL=forwardSpeed + differential
wheelR=forwardSpeed - differential
PULSOUT 15,wheelL
PULSOUT 14,wheelR
LOOP
forwardSpeed1:
forwardSpeed=850 - size/8
RETURN
forwardSpeed2:
forwardSpeed=700
RETURN
forwardSpeed3:
forwardSpeed=850
RETURN
Comments
The bottom line seems to be that propellor is a better match for pixy.