problem with encoders
Tonight I installed the bs2px. Sence I have the wheel encoders seem to be acting up.. After start up, it just spins in a circle.. All lines seem to be connected correct, but it just spins in circles. The encoders were originally hooked up a few weeks ago, and has performed quite well up till now...
· Thanx again _Duane
· Thanx again _Duane

Comments
·· Some of the timing parameters for the BS2px are different than some of the other BS2 models, perhaps you should post your code and we can see what's going on.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
(replace this text with your code) ' {$STAMP BS2px} ' {$PBASIC 2.5} Ping PIN 15 #SELECT $STAMP #CASE BS2, BS2E Trigger CON 5 ' trigger pulse = 10 uS Scale CON $200 ' raw x 2.00 = uS #CASE BS2SX, BS2PX Trigger CON 13 Scale CON $0CD ' raw x 0.80 = uS #CASE BS2PE Trigger CON 5 Scale CON $1E1 ' raw x 1.88 = uS #ENDSELECT'Constant declarations (IR) irclock_right CON 1 ' pin 1 is output (clock) irdata_right CON 2 ' pin 2 is the input (data) irclock_left CON 3 ' pin 3 is output (clock) irdata_left CON 4 ' pin4 is input (data) ' I/O pin setup for detector (IR) INPUT irdata_left 'make pin 3 input HIGH irdata_left ' make pin 4 outpt & high. INPUT irdata_right ' make pin 1 the input HIGH irclock_right ' make pin 2 output & high.'intilazation counter_cornerSIR = 0 counterir = 0 countersonar = 0main: PAUSE 2000 DO GOSUB ir_sence GOSUB sonar GOSUB corner_test LOOPrange: GOSUB get_sonar cm = rawdist ** RawToCm sonarC = cm +1 GOSUB left_turn GOSUB get_sonar cm = rawdist ** RawToCm sonarL = cm +1 GOSUB right_turn GOSUB right_turn GOSUB get_sonar cm = rawdist ** RawToCm sonarR = cm +1 IF (sonarC > sonarL AND sonarR) THEN GOSUB forward ELSEIF (sonarL > sonarC AND sonarR) THEN GOSUB back_up GOSUB left_turn ELSEIF (sonarR > sonarL AND sonarC) THEN GOSUB back_up GOSUB right_turn ELSE GOSUB back_up GOSUB back_up GOSUB left_turn GOSUB left_turnENDIF RETURNSonar: countersonar = countersonar + 1 GOSUB Get_Sonar ' get sensor value inches = rawDist ** RawToIn ' convert to inches cm = rawDist ** RawToCm ' convert to centimeters IF cm <12 THEN GOSUB back_up GOSUB right_turn GOSUB right_turn ELSE GOSUB forward ENDIF RETURNir_sence: GOSUB read06 GOSUB read05 IF(IN2 <> IN4) THEN IF (oldirR <> IN2) AND (oldirL <> IN4) THEN counterir = counterir + 1 oldirR = IN2 oldirL = IN4 IF (counterir > 2) THEN counterir = 1 GOSUB back_up GOSUB left_turn GOSUB left_turn ENDIF ELSE counterir = 1 ENDIF ENDIF IF (va = 0) THEN GOSUB back_up GOSUB left_turn ELSEIF (va = 1) THEN GOSUB forward ENDIF IF (va2 = 0) THEN GOSUB back_up GOSUB right_turn ELSEIF (va2 = 1) THEN GOSUB forward ENDIF RETURN forward: counter(left) = 0 DO WHILE (counter(left) < 1) PULSOUT motorL, 849 PULSOUT motorR, 647 GOSUB update LOOP RETURNback_up: counter(left) = 0 DO WHILE (counter(left) < 3) PULSOUT motorL, 650 PULSOUT motorR, 847 GOSUB update LOOP RETURNleft_turn: counter (left) = 0 DO WHILE (counter(left)< 4) PULSOUT motorL, 650 PULSOUT motorR, 650 GOSUB update LOOP RETURNright_turn: counter(right) = 0 DO WHILE (counter(right) < 4) PULSOUT motorR, 850 PULSOUT motorL, 850 GOSUB update LOOP RETURN▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Post Edited (Chris Savage (Parallax)) : 5/18/2005 3:29:13 AM GMT
· You're going to need to test your code in smaller sections or something.· Frankly I can't see how this code worked anyway, since it appears to be missing sections.· There are GOSUBs to several labels that don't exist.· Therefore it's impossible to help you because this code won't run any any BASIC Stamp.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
it was something like this....
main:
do
pulsout 12,850
pulsout 13,650
pause 20
loop
it just spun in circles .. wich leads me to belive that there is a difference in timming/pulsout· for the bs2px.. sadlly i donot know what value is required for forward,reverse, right,and left turns....
thanx again duane
·· Yes, I explained this at the beginning of the thread.· Try changing the values to those used for the BS2p.· You're using the BS2 timing for the PULSOUT, and those won't work.· If you have any questions, look in the help file under PULSOUT.· It explains the differences in the timing there.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com