Shop OBEX P1 Docs P2 Docs Learn Events
problem with encoders — Parallax Forums

problem with encoders

stamp_demonstamp_demon Posts: 69
edited 2005-05-19 00:35 in BASIC Stamp
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

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-18 03:03
    Hello,

    ·· 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
  • stamp_demonstamp_demon Posts: 69
    edited 2005-05-18 03:22
    Okay here is my code. It ran pretty okay for the most part untill I installed the bs2px.. I'm sure its a timing issue, but I can't find it.... Thankyou for all your help .. _Duane
    (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
    

    RawToIn         CON     889                     ' 1 / 73.746 (with **)
    RawToCm         CON     2257                    ' 1 / 29.034 (with **)
    

    IsHigh          CON     1                       ' for PULSOUT
    IsLow           CON     0
    

    rawDist         VAR     Word                    ' raw measurement
    inches          VAR     Word
    cm              VAR     Word
    

    right CON 0
    left CON 1
    senseR PIN 10
    senseL PIN 11
    motorR PIN 14
    motorL PIN 13
    

    sense CON senseR
    motor CON motorR
    

    prev VAR Bit(2)
    new VAR Bit(2)
    side VAR Byte
    i VAR Byte
    counter VAR Word(2)
    counterir VAR Word
    oldirR VAR Bit
    oldirL VAR Bit
    countersonar VAR Bit
    counter_cornerSIR VAR Bit
    sonarC  VAR Word
    sonarL  VAR Word
    sonarR  VAR Word
    va2 VAR Bit       ' value were,(IR)
    va   VAR   Byte   ' readings are stored.
    

              '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 = 0
    

    
    
          main:
              PAUSE 2000
                DO
                 GOSUB ir_sence
               GOSUB sonar
              GOSUB corner_test
             LOOP
    

        range:
         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_turn
    

                   ENDIF
                     RETURN
    

    
    
        Sonar:
        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
              RETURN
    

        ir_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
           RETURN
    

             back_up:
                  counter(left) = 0
                      DO WHILE (counter(left) < 3)
                            PULSOUT motorL, 650
                                PULSOUT motorR, 847
                             GOSUB update
                           LOOP
                        RETURN
    

        left_turn:
          counter (left) = 0
             DO WHILE (counter(left)< 4)
               PULSOUT motorL, 650
                 PULSOUT motorR, 650
                GOSUB update
              LOOP
           RETURN
    

        right_turn:
             counter(right) = 0
               DO WHILE (counter(right) < 4)
                 PULSOUT motorR, 850
               PULSOUT motorL, 850
             GOSUB update
            LOOP
           RETURN
    
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-18 03:25
    WOW!· Try to attach code from now on...That's alot to attempt to read...It'd have been easier to open it in the Stamp Editor...shocked.gif


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com


    Post Edited (Chris Savage (Parallax)) : 5/18/2005 3:29:13 AM GMT
  • stamp_demonstamp_demon Posts: 69
    edited 2005-05-18 03:38
    Yeah, I'm really sorry about that I tryed attaching it, but endded up with a empty window.. Tryed dragging it, but it wouldnt...
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-18 17:34
    Hello,

    · 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
  • stamp_demonstamp_demon Posts: 69
    edited 2005-05-19 00:19
    I see what you mean, it looks like it didnt all post... However I belive it has to do with the puilsout commands... I tryed runing a simple prog yesterday calling each servo .. it did the same... must be a difference in timming with the bs2px....
    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
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-19 00:35
    Hello,

    ·· 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
Sign In or Register to comment.