Test BOE Arlo Encoder Connections

Test BOE Arlo Encoder Connections

The Arlo has built-in encoders that can count how far the Arlo travels in terms of 144ths of a wheel revolution.  Although it’s not needed to run Boe-Bot code, it’s best to make sure they are functioning correctly in case you want to improve the accuracy of the Arlo’s maneuvers later.  The next program will display the status of your encoder connections in the Debug Terminal.  If there is a problem, it may indicate that the encoder cables have been swapped or that there is some other wiring problem.  Here are examples of what you might see:

  • We want the wheels to be able to spin freely during this test, so set your Arlo on a box, stand, or some other stable platform that prevents its wheels from coming into contact with the table top.  
  • Run Test Encoder Connections.bs2.
  • Check the Debug Terminal’s messages.  It’ll either tell you that the Arlo is ready for the next step, or describe the error it encountered and suggest either a fix – or at least where to look for a potential problem.
' Arlo - Test Encoder Connections.bs2

' Run this program to verify that the Arlo's encoders have been connected.
' to the DHB-10 board correctly.

' {$STAMP BS2}
' {$PBASIC 2.5}

left VAR Word
right VAR Word
n VAR Byte                                    ' Stores index of serial exchange

FREQOUT 4, 2000, 3000                         ' Beep -> program starting
DEBUG "Program running...", CR, CR            ' Display program running

' Pace setting not required if Test BOE and DHB-10 Communication.bs2 has
' already been run (successfully).
n = 1                                         ' First exchange
DEBUG "PACE 1", CR                            ' Set serial pace for BS2
SEROUT 13, 32800, ["PACE 1", CR]              ' Set serial pace for BS2
SERIN  13, 32800, 50, ERR, [WAIT(CR)]         ' Get DHB-10's confirmation

n = 2                                         ' Second exchange
DEBUG "RST", CR
SEROUT 13, 32800, ["RST", CR]                 ' Send reset encoders message
SERIN  13, 32800, 50, ERR, [WAIT(CR)]         ' Wait for DHB-10's confirmation

n = 3                                         ' Third exchange
DEBUG "GO 32 32", CR
SEROUT 13, 32800, ["GO 32 32", CR]            ' Send reset encoders message
SERIN  13, 32800, 50, ERR, [WAIT(CR)]         ' Wait for DHB-10's confirmation

DEBUG "...for 4 s", CR
PAUSE 4000                                    ' ...for 4 seconds

n = 4                                         ' Fourth exchange
DEBUG "GO 0 0", CR
SEROUT 13, 32800, ["GO 0 0", CR]              ' Send reset encoders message
SERIN  13, 32800, 50, ERR, [WAIT(CR)]         ' Wait for DHB-10's confirmation

n = 5                                         ' Fifth exchange
DEBUG "DIST", CR
SEROUT 13, 32800, ["DIST", CR]                ' Request distance
SERIN  13, 32800, 50, ERR,                    ' Get left & right distances
      [SDEC left, SDEC right]
DEBUG "left = ", SDEC left,                   ' Display left & right distances
     ", right = ", SDEC right, CR

n = 6                                         ' Sixth exchange
DEBUG "PULSE", CR
SEROUT 13, 32800, ["PULSE", CR]               ' Change modes, serial to pulse
SERIN  13, 32800, 50, ERR, [WAIT(CR)]         ' Wait for confirmation  

DEBUG CR                                      ' Add a carriage return

' If all distances in range, then display success.
IF left > 175 AND left < 325 AND right > 175 AND right < 325 THEN
 DEBUG "Encoder connections are ", CR
 DEBUG "correct!  Your Arlo is ready ", CR
 DEBUG "for the next step.", CR, CR
ELSE                                          ' If not, find errors
 IF left > 175 AND left < 325 THEN           ' If left good, say so
   DEBUG "Motor 1 encoder cables ", CR
   DEBUG "are connected correctly.", CR, CR
 ELSEIF left > -325 AND left < -125 THEN     ' Negative? Cables reversed
   DEBUG "ERROR: Motor 1 encoder ", CR
   DEBUG "connections are reversed!", CR, CR
 ELSE                                        ' Else, unknown error
   DEBUG "ERROR: Motor 1 encoder ", CR
   DEBUG "values out of range. Recheck ", CR
   DEBUG "encoder connections and ", CR
   DEBUG "assemblies.", CR
 ENDIF
 IF right > 175 AND right < 325 THEN         ' Repeat for right encoders
   DEBUG "Motor 2 encoder cables ", CR
   DEBUG "are connected correctly.", CR, CR
 ELSEIF right > -325 AND right < -125 THEN
   DEBUG "ERROR: Motor 2 encoder ", CR
   DEBUG "connections are reversed!", CR, CR
 ELSE
   DEBUG "ERROR: Motor 2 encoder.", CR
   DEBUG "values out of range. Recheck ", CR
   DEBUG "encoder connections and ", CR
   DEBUG "assemblies", CR
 ENDIF
ENDIF

END

ERR:                                          ' Error routine
 DEBUG "ERROR, no reply from DHB-10.", CR    ' Error message
 DEBUG "n = ", DEC n                         ' Index of exchange that failed
 STOP                                        ' End program