LEARN.PARALLAX.COM
Published on LEARN.PARALLAX.COM (https://learn.parallax.com)
Home > Arlo with a BASIC Stamp Boe-Bot Brain

Arlo with a BASIC Stamp Boe-Bot Brain

Ready for a bigger Boe-Bot?  Try mounting your Board of Education (with BASIC Stamp 2) on the Arlo!  After a couple connections and a few simple tests, any Boe-Bot code will run.  The time it takes for the Arlo to go distances and execute turns is different than a regular Boe-Bot, so you will have to adjust a few numbers in your programs, but after that the Arlo will run your classic Boe-Bot code like a pro.

  • If you have not done so already, complete the Arlo Robot Assembly Guide tutorial, up to but not inlcuding the optional Top Deck Assembly.
  • Download the BASIC Stamp Editor (Windows only) or Parallax IDE for Chrome programming environment.
  • Grab your Board of Education with a BASIC Stamp 2 and its programming cable, then get started!
  • NOTE: If you want a full copy of all PBASIC code presented in this tutorial, visit the download page to get a zip archive.

Connect Your BOE to the DHB-10

Connect Your BOE to the DHB-10

The BOE connections to the Arlo’s DHB-10 motor control board use the same servo ports as the ones you used to connect to your Boe-Bot’s servos.  

  • Complete the Arlo Robot Assembly Guide first (IMPORTANT).
  • Turn off the Arlo’s MAIN and MOTOR power switches.
  • Set the BOE’s 3-position power switch to 0.
  • IMPORTANT! Make sure the jumper between servo headers P14 and P13 is set to Vdd, NOT Vin. (See image, below.)
  • Use a 4-inch 3-wire cable to connect the P13 servo to the DHB-10’s CH1 port.
  • Use another 4-inch 3-wire cable to connect the P12 servo to the DHB-10’s CH2 port.
  • Double-check that the 3-wire cables are oriented properly, with the black wires connecting to the pins labeled BLACK.
  • Connect the Arlo’s +6.5 V Aux barrel plug to the BOE’s barrel jack.

Test and Correct BoE Electrical Connections

Test and Correct Electrical Connections

Is the barrel plug connected correctly?  

If you have not already done so, make sure your batteries are freshly charged.  Follow the instructions provided on the charger case.

  • Follow the BOE power barrel plug leads to the Arlo power distribution board.
  • Verify that the lead with the white stripes is connected to the +6.5V socket of the AUX terminal.
  • Verify that the other lead (without the white stripes) is connected to the GND socket of the AUX terminal.
  • Turn on the Arlo’s Main power rocker switch.
  • Set the BOE’s 3-position power switch to 1.
  • Check if the BOE’s power light came on.
    • Yes –  the BOE’s power is connected correctly.
    • No – turn all power switches off immediately.
  • Turn ARLO and BOE power back off.

If the BOE’s power light did not come on:

  • Check your the barrel plug’s AUX connection, AUX connection fuse.  If both are good, check your soldering.

 

Are the P13 and P12 correctly connected to Ch1 and Ch2?  

  • Verify that one 3-wire cable connects the BOE’s P13 port to the DHB-10’s Ch1 port.
  • Verify that the other 3-wire cable connects the BOE’s P12 port to the DHB-10’s Ch2 port.
  • Check the cables in BOE’s P13 and P12, both black wires should align with the Black label to the right of the servo ports.
  • Check the cables in the DHB-10’s Ch1 and CH2 ports.  Both black wires should align with the B label next to the Ch2 port.

Clear the BS2 Program

Clear the BS2’s program

Let’s make sure to clear the program in the BASIC Stamp 2 before turning motor power on.  That way, some Boe-Bot program that used to be in there won’t send your Arlo into unexpected maneuvers.

  • Make sure the Arlo’s Motors power is off.
  • Connect your board’s programming cable to your computer.
  • Turn on the Arlo’s Main power.
  • Set the BOE’s power switch to 1.
  • Open the No Surprise Maneuvers.bs2 program into your BASIC Stamp programming software.
  • Run the program using your BASIC Stamp programming software’s Run button.
' Arlo - No Surprise Maneuvers.bs2
' Run this before ever turning on power to the Arlo's motors to prevent any
' unexpected motions.
' {$STAMP BS2}
' {$PBASIC 2.5}

FREQOUT 4, 2000, 3000                         ' Beep -> program starting
DEBUG "Your Arlo will stay still."            ' Success message
END                                           ' End program

Test BS2 to DHB-10 Communication

Test BASIC Stamp to DHB-10 Communication

This next program asks the DHB-10 for its hardware and firmware versions, and displays the results in your Debug Terminal.  Here is what you’ll see if your BS2 communicates successfully with the DHB-10 (left) alongside one of the messages you might see if communication fails (right).

  • Make sure your programming cable is connected, the Arlo’s Main power is on, and the BOE’s power switch is set to 1.
  • Turn on the Arlo’s Motors power.
  • Verify that the DHB-10’s indicator lights blink on/off orange once every second.  If not, go back to the Arlo Assembly Tutorial and start checking wiring connections.
  • Open and run Test BOE and DHB-10 Communication.bs2.
    • If the Debug Terminal displays an error message, recheck the cables connecting the BOE servo ports to the DHB-10’s Ch1 and Ch2 ports. Also, make sure you set the Arlo’s Motors rocker switch to on.
    • If the Debug Terminal displays the hardware and firmware versions, make a note of the firmware version, and then proceed to the Test Motor Connections section.
' Arlo - Test BOE and DHB-10 Communication.bs2
' Run this program to verify that your BOE and DHB-10 are communicating.
' Should display:
'      Hardware
'      HWVER = 1
'      Firmware
'      VER = 10

' If it instead displays:
'     "ERROR, no reply from DHB..."
' It means there is a wiring problem.

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

val 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

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 "STORE PACE", CR, CR                    ' Display storing serial pace
SEROUT 13, 32800, ["STORE PACE", CR]          ' Remember serial pace settings
SERIN  13, 32800, 50, ERR, [WAIT(CR)]         ' Get DHB-10's confirmation

n = 3                                         ' Third exchange
DEBUG "Hardware", CR                          ' Display hardware heading
SEROUT 13, 32800, ["HWVER", CR]               ' Request hardware version
SERIN  13, 32800, 50, ERR, [DEC val]          ' Get DHB-10's reply
DEBUG "HWVER = ", DEC val, CR, CR             ' Display version

n = 4                                         ' Fourth exchange
DEBUG "Firmware", CR                          ' Display firmware heading
SEROUT 13, 32800, ["VER", CR]                 ' Request firmware version
SERIN  13, 32800, 50, ERR, [DEC val]          ' Get DHB-10's reply
DEBUG "VER = ", DEC val, CR                   ' Display version

END                                           ' End program

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

Test BOE Arlo Motor Connections

Test Motor Connections

This next program sets the Arlo’s motors to 20/127 of full power in the forward direction.  If your Arlo goes forward while running this program, it indicates that your motors are connected correctly and the battery is charged.

IMPORTANT: Your Arlo will not be ready for the next step until it goes forward for this test.

  • Check the picture at the start of this document and make sure you know the Arlo’s forward, backward, left and right.
  • Turn off the Arlo’s Motors power switch.
  • Run Arlo – Test Motor Connections.bs2.
  • The Debug Terminal will display a communication failure because your DHB-10 isn’t responding.  Don’t worry about it, the DHB-10 didn’t reply because Motors power is off.
  • Turn all power switches off.
  • Take your Arlo to an open space with at least 2 m of open space for forward travel.
  • Turn all powers on: Arlo MAIN & MOTORS and BOE power to 2.
  • Verify that the Arlo goes slowly forward for 3 s, then stops.
    • If it does not go forward, check the Arlo Fails Motor Connections Test section in the Troubleshooting Guide at the end of this document.
    • If it does go forward, your Arlo is ready for the next step (Test Encoder Connections).
' Arlo - Test Motor Connections.bs2
' Run this program to verify that your Arlo goes forward.

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

s VAR Byte(19)                                ' Stores DHB-10 replies
n VAR Byte                                    ' Stores index of serial exchange

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

n = 1                                         ' First exchange
DEBUG "GO 20 20", CR                          ' Display message to DHB-10
SEROUT 13, 32800, ["GO 20 20", CR]            ' Motors forward 20/127 of full power
SERIN  13, 32800, 50, ERR, [WAIT(CR)]         ' Wait for DHB-10 confirmation

PAUSE 3000                                    ' Let motors run 3 seconds

n = 2                                         ' Second exchange
DEBUG "GO 0 0", CR                            ' Display message to DHB-10
SEROUT 13, 32800, ["GO 0 0", CR]              ' Set both motors to 0 power
SERIN  13, 32800, 50, ERR, [WAIT(CR)]         ' Wait for DHB-10 confirmation

END                                           ' End program

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

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

Try & Tune Some Boe-Bot Code

Try & Tune Some Boe-Bot Code

Try the Unmodified Code

Let’s try the ForwardLeftRightBackward.bs2 program from pages 107-108 in Robotics with the Boe-Bot v3.0.  You might have noticed that the last serial command to the Arlo in the previous program was SEROUT 13, 32800, [“PULSE”, CR].  That switched the Arlo’s DHB-10 from serial communication mode to pulse mode in preparation for this program.  When the Arlo’s DHB-10 starts up, it automatically goes into pulse mode.  So, another option for switching a program out of serial communication mode is to simply restart the DHB-10.  You can do that by either pressing and releasing its reset button or turning Motors power off and back on.   

  • Set power like this: MAIN (on), MOTORS (off), BOE (position-2)
  • Run ForwardLeftRightBackward.bs2.
  • Turn all power off, unplug the programming cable, and take to your Arlo navigation area.
  • Turn MAIN and MOTORS power on.
  • Set the BOE power switch to 2.
  • Verify that the Arlo goes forward, turns left, then right, then backs up to near where it started.

The program would make a Boe-Bot turn about 90 degrees, but not so with the Arlo. 

  • Make notes on how far it actually turned.
  • Let’s say the Arlo turned 60° instead of 90°.  Since (90/60) x 24 = 36 try replacing 24 with 36 and retry.  A couple iterations to get closer to 90° will probably be needed.  

In the More Precise Maneuvers with Encoders section, we’ll get those 90° turns on the first try!  

Increase BOE Arlo’s Top Speed in Pulse Mode

Increase BOE Arlo’s Top Speed in Pulse Mode

The DHB-10 defaults to a speed control scale from 1000 to 2000 us.  That’s PULSOUT duration values from 500 (full speed clockwise) to 750 (stop) to 1000 (full speed counterclockwise).  The DHB-10 has a scale command for adjusting that range.  For example SCALE 200 would make it fit PULSOUT durations from 650 to 850.  The result: Arlo goes a lot faster!  This also means it’ll travel and turn more for a given number of pulses, so some recalibration may be in order.

  • Put the Arlo up on blocks so it cannot run away while connected to the computer.
  • MAIN and MOTORS power on, BOE power to 2.
  • Run Change Pulse Scale.bs2.
  • MOTORS power off.
  • Run ForwardLeftRightBackward.bs2.
  • MAIN & BOE powers off.
  • Take Arlo to your navigation area.
  • Make sure you’ve got enough room for the Arlo to go more than twice the distance of last time.
  • Turn Main, Motors, and BOE powers on.
  • Optionally, note the turn angle and recalibrate.
  • Optionally, to go back to the slower speeds, uncomment the commented SEROUT and SERIN commands and re-run the ChangePulseScale.bs2.
' Arlo - Change Pulse Scale.bs2
' Change pulse scale from 1000...2000 us to 1300 to 1700 us so that
' Robotics with the Boe-Bot examples can run the Arlo at top speed.

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

DEBUG "Program Running!", CR

FREQOUT 4, 2000, 3000                        ' Signal program start/reset.

DEBUG "SCALE 200", CR                        ' Display SCALE message
SEROUT 13, 32800, ["SCALE 200", CR]          ' Full speed in 650-850
SERIN  13, 32800, 50, ERR, [WAIT(CR)]        ' Wait for DHB-10's confirmation

' Uncomment to return to default
' DEBUG "SCALE 1000", CR                     ' Display SCALE message
' SEROUT 13, 32800, ["SCALE 1000", CR]       ' Full speed in 500-1000
' SERIN  13, 32800, 50, ERR, [WAIT(CR)]      ' Get DHB-10's reply

DEBUG "STORE SCALE", CR                      ' Display STORE SCALE message
SEROUT 13, 32800, ["STORE SCALE", CR]        ' Remember scale
SERIN  13, 32800, 50, ERR, [WAIT(CR)]        ' Get DHB-10's reply

SEROUT 13, 32800, ["PULSE", CR]              ' Exit from serial to pulse mode
SERIN  13, 32800, 50, ERR, [WAIT(CR)]        ' Get DHB-10's reply

DEBUG "Done!"

END

ERR:                                          ' Error routine
  DEBUG "ERROR, no reply from DHB-10.", CR    ' Error message
  STOP                                        ' End program

Control BOE Arlo with the Debug Terminal

Control BOE Arlo with the Debug Terminal

You can also communicate with the Arlo through the Debug Terminal, and perform the same serial communication tasks the BASIC Stamp has been programmed to do.  For example, here is the sequence of commands and replies from Test Encoder Connections.bs2:

     

  • Make sure your Debug Terminal’s Echo Off box is unchecked.
  • Put the Arlo up on blocks so that its wheels can spin freely without touching your work surface.
  • Set Main, Motors, and BOE power to on.
  • Run Arlo Terminal Communication.bs2.
  • Click the text input pane in your debug terminal.  It’s just above the pane that displays Debug messages from the BASIC Stamp.
  • Type PACE 1, and then press the Enter Key.
  • Type RST, and then press the Enter Key.
  • Type the following commands, each followed by the Enter key: GO 32 32, Go 0 0, DIST.

The reply values to your DIST command will depend on how long you let the wheels run.

' Arlo - Arlo Terminal Communication

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

info VAR Byte(24)                            ' String buffer
n    VAR Byte                                ' Index

FREQOUT 4, 2000, 3000                        ' Start sound
DEBUG "Arlo Terminal", CR                    ' Terminal title

DO                                           ' Main loop
  DEBUG "> "                                 ' Send to terminal
  DEBUGIN STR info20CR                     ' Get typed values
  SEROUT 13, 32800, [STR info, CR]           ' Send to DHB-10
  SERIN 13, 32800, [STR info24CR]          ' Get DHB-10 reply
  DEBUG STR info                             '
  IF info(0) <> 0 THEN DEBUG CR              ' Add CR to reply
LOOP                                         ' Repeat main loop

More Precise BOE Arlo Maneuvers with Encoders

More Precise BOE Arlo Maneuvers with Encoders

As mentioned earlier, the Arlo has encoders that track distance in 144th increments of a full wheel rotation.  These increments are commonly called “counts”, and the Arlo’s encoders send 144 counts per revolution.  The Arlo’s encoders are quadrature, meaning that the two encoder sensors are offset by ¼ of a count.  By monitoring the pattern of low-high-low transitions for both sensors, the DHB-10 can also determine which direction the wheel is turning.  For a given wheel, 144 counts would mean a full forward rotation, and -144 counts would mean a full backward rotation.

The Arlo’s DHB-10 motor controller has a built-in control system that uses the encoder outputs to control motor speed and distance as well as monitor motor position.  To take advantage of this more accurate control system, your program will have to send and receive serial messages instead of servo control pulses.  

NOTE: To find out more about the DHB-10 commands in this document’s example programs, look them up in the DHB-10 Motor Controller Firmware Guide.

 

Serial Distance Control  

This example program uses distance mode commands  TRVL  and TURN to send the Arlo forward 2 wheel revolutions, left ¼  turn, right ½ turn, left ¼ turn, and back 2 wheel revolutions.  The DHB-10 gets the Arlo’s wheels to the right encoder count; all the program has to do is wait long enough for it complete each command.   

  • Set power like this: MAIN (on), MOTORS (off), BOE (position-2)
  • Run Serial Distance Maneuvers.bs2.
  • Don’t worry about the communication error message because Motors power is off.
  • Turn all power off, unplug programming cable, and take to your Arlo navigation area.
  • Turn MAIN and MOTORS power on.
  • Set the BOE power switch to 2.
  • Verify that the Arlo goes forward, turns left, then right, then left, then backs up to near where it started.
' -----[ Title ]-----------------------------------------------------------
' Arlo - Serial Distance Maneuvers.bs2
' Examples that use serial communication to make the arlo travel in certain
' straight-line and turn-in-place distances.

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

' -----[ I/O Definitions ]-------------------------------------------------

Tx PIN 13
Rx PIN 13

' -----[ Variables ]-------------------------------------------------------

countsL        VAR     Word                  ' L & R distances
countsR        VAR     Word
counts         VAR     countsL               ' Distance & top speed
topSpeed       VAR     countsR
n              VAR     Byte                  ' Stores index of serial exchange

' -----[ Initialization ]-------------------------------------------------

FREQOUT 4, 2000, 3000                        ' Beep -> program starting
DEBUG "Program running...", CR, CR           ' Display program running
GOSUB Set_Ser_Pace                           ' Set serial pace
GOSUB Clear_Encoders                         ' Clear previous distances

' -----[ Main Routine ]----------------------------------------------------

counts = 288 : topSpeed = 200                ' Forward 288 @ 200 counts/sec
GOSUB Travel                                 ' Call Travel subroutine
PAUSE 3000                                   ' 3 s to complete maneuver
GOSUB Get_Distance                           ' Get distances

counts = -93 : topSpeed = 200                ' Left 93 @ 200 counts/sec
GOSUB Turn                                   ' Call Turn subroutine
PAUSE 3000                                   ' 3 s to complete maneuver
GOSUB Get_Distance                           ' Get distances

counts = 186 : topSpeed = 100                ' Right 186 @ 100 counts/sec
GOSUB Turn                                   ' Call Turn subroutine
PAUSE 4000                                   ' 4 s to complete maneuver
GOSUB Get_Distance                           ' Get distances

counts = -93 : topSpeed = 32                 ' Left 93 @ 32 counts/sec
GOSUB Turn                                   ' Call Turn subroutine
PAUSE 5000                                   ' 4 s to complete maneuver
GOSUB Get_Distance                           ' Get distances

counts = -288 : topSpeed = 200               ' Backward 288 @ 200 counts/sec
GOSUB Travel                                 ' Call Travel subroutine
PAUSE 3000                                   ' 3 s to complete maneuver
GOSUB Get_Distance                           ' Get distances

END

' -----[ Subroutine - Set_Ser_Pace ]---------------------------------------

' Pace setting not required if Test BOE and DHB-10 Communication.bs2 has
' already been run (successfully).  Adds 1 ms delay before serial reply
' and with each space so BS2 can set up SDEC inputs at 19200.
Set_Ser_Pace:
  n = n + 1                                   ' Increment message index
  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
RETURN

' -----[ Subroutine - Clear_Encoders ]-------------------------------------

Clear_Encoders:
  n = n + 1                                  ' Increment message index
  DEBUG "RST", CR                            ' Display message to DHB-10
  SEROUT Tx, 32800, ["RST", CR]              ' Send reset encoders message
  SERIN  Rx, 32800, 50, ERR, [WAIT(CR)]      ' Get DHB-10's reply
RETURN

' -----[ Subroutine - Travel ]---------------------------------------------

Travel:
  n = n + 1                                  ' Increment message index
  DEBUG "TRVL ", SDEC counts, " ",           ' Display message to DHB-10
                 SDEC topSpeed, CR
  SEROUT Tx, 32800, ["TRVL ", SDEC counts,   ' Travel command with arguments
                     " ", SDEC topSpeed, CR]
  SERIN  Rx, 32800, 50, ERR, [WAIT(CR)]      ' Get DHB-10's reply
RETURN

' -----[ Subroutine - Turn ]-----------------------------------------------

Turn:
  n = n + 1                                  ' Increment message index
  DEBUG "TURN ", SDEC counts,                ' Display message to DHB-10
            " ", SDEC topSpeed, CR
  SEROUT Tx, 32800, ["TURN", " ",            ' Turn command with arguments
                     SDEC counts,
                " ", SDEC topSpeed, CR]
  SERIN  Rx, 32800, 50, ERR, [WAIT(CR)]      ' Get DHB-10's reply
RETURN

' -----[ Subroutine - Get_Distance ]---------------------------------------

Get_Distance:
  countsL = 0                                ' Clear counts variables
  countsR = 0
  n = n + 1                                  ' Increment message index
  DEBUG "DIST ", CR                          ' Display message to DHB-10
  SEROUT Tx, 32800, ["DIST", CR]             ' Distance command
  SERIN  Rx, 32800, 100, ERR, [SDEC countsL, ' Get DHB-10's reply
                               SDEC countsR]
  DEBUG "countsL = ", SDEC countsL, " countsR = ", SDEC countsR, CR
RETURN

' -----[ Routine - ERR ]---------------------------------------------------

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

 

Serial Speed Control

If your robot is using sensors to navigate, maybe you just want your program to make the Arlo go forward until it finds an obstacle.  Instead of specifying a particular distance and setting aside a certain amount of time, your program can set each wheel speed and go until the sensors have detected a condition your program is looking for.    

This next example program just goes forward at a certain speed for 2 seconds, then backward at that same speed for 2 seconds.  Note that the left and right values are positive for forward and negative for backward.  Keep in mind that the values don’t have to match.  For example, you could change the left and right values to 150 and 50 to make it draw an arc, or even -150 and -50 to reverse the direction of the arc.

  • Set power like this: MAIN (on), MOTORS (off), BOE (position-2)
  • Run Serial Speed Maneuvers.bs2.
  • Disregard the communication error message.
  • Turn all power off, unplug programming cable, and take to your Arlo navigation area.
  • Turn MAIN and MOTORS power on.
  • Set the BOE power switch to 2.
  • Verify that the Arlo goes forward, and then backwards.
  • Try changing the left = 144  : right = 144      to     left = 144  : right = 44.
  • Change the         left = -144 : right = -144    to     left = -144 : right = -44.
' -----[ Title ]-----------------------------------------------------------
' Arlo - Serial Speed Maneuvers.bs2
' Examples that use serial communication to make the arlo travel in certain
' straight-line and turn-in-place distances.

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

' -----[ I/O Definitions ]-------------------------------------------------

Tx PIN 13
Rx PIN 13

' -----[ Variables ]-------------------------------------------------------

left           VAR     Word                  ' L & R speeds & distances
right          VAR     Word
n              VAR     Byte                  ' Stores index of serial exchange

' -----[ Initialization ]-------------------------------------------------

FREQOUT 4, 2000, 3000                        ' Beep -> program starting
DEBUG "Program running...", CR, CR           ' Display program running
GOSUB Set_Ser_Pace                           ' Set serial pace
GOSUB Clear_Encoders                         ' Clear previous distances

' -----[ Main Routine ]----------------------------------------------------

left = 144 : right = 144                     ' Left & right 144 counts/sec
GOSUB Go_Speed                               ' Call Go_Speed subroutine
PAUSE 3000                                   ' Go for 3 seconds

left = 0 : right = 0                         ' Left & right 0 counts/sec
GOSUB Go_Speed                               ' Call Go_Speed subroutine
PAUSE 1500                                   ' Time to stop
GOSUB Get_Distance                           ' Get distances

left = -144 : right = -144                   ' Left & right -144 counts/sec
GOSUB Go_Speed                               ' Call Go_Speed subroutine
PAUSE 3000                                   ' Go for 3 seconds

left = 0 : right = 0                         ' Left & right 0 counts/sec
GOSUB Go_Speed                               ' Call Go_Speed subroutine
PAUSE 1500                                   ' Time to stop
GOSUB Get_Distance                           ' Get distances

END

' -----[ Subroutine - Set_Ser_Pace ]---------------------------------------

' Pace setting not required if Test BOE and DHB-10 Communication.bs2 has
' already been run (successfully).  Adds 1 ms delay before serial reply
' and with each space so BS2 can set up SDEC inputs at 19200.
Set_Ser_Pace:
  n = n + 1                                   ' Increment message index
  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
RETURN

' -----[ Subroutine - Clear_Encoders ]-------------------------------------

Clear_Encoders:
  n = n + 1                                  ' Increment message index
  DEBUG "RST", CR                            ' Display message to DHB-10
  SEROUT Tx, 32800, ["RST", CR]              ' Send reset encoders message
  SERIN  Rx, 32800, 50, ERR, [WAIT(CR)]      ' Get DHB-10's reply
RETURN

' -----[ Subroutine - Go_Speed ]-------------------------------------------

Go_Speed:
  n = n + 1                                  ' Increment message index
  DEBUG "GOSPD ", SDEC left,                 ' Display message to DHB-10
             " ", SDEC right, CR
  SEROUT Tx, 32800, ["GOSPD", " ",           ' GOSPD command with arguments
                     SDEC left,
                " ", SDEC right, CR]
  SERIN  Rx, 32800, 50, ERR, [WAIT(CR)]      ' Get DHB-10's reply
RETURN

' -----[ Subroutine - Get_Distance ]---------------------------------------

Get_Distance:
  n = n + 1                                  ' Increment message index
  left = 0                                   ' Clear counts variables
  right = 0
  DEBUG "DIST ", CR                          ' Display message to DHB-10
  SEROUT Tx, 32800, ["DIST", CR]             ' Distance command
  SERIN  Rx, 32800, 100, ERR, [SDEC left,    ' Get DHB-10's reply
                               SDEC right]
  DEBUG "left = ", SDEC left,                ' Display distances
        " right = ", SDEC right, CR
RETURN

' -----[ Routine - ERR ]---------------------------------------------------

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

Connect and Test the Arlo + BOE Ping))) Sensors

Connect and Test the Arlo + BOE Ping))) Distance Sensors

This connection diagram (below) shows where to connect each 3-wire Ping))) sensor cable.  If you’re looking at the color version, note that each black wire is connected to either Vss on the breadboard, or the Vss terminal in the servo header (labeled Black to the right of the header block).  Each of those black wires should also be connected to a Ping))) sensor’s GND pin.  The power jumper between BOE servo ports 13 and 14 should also be set to Vdd.  

WARNING! Wiring errors can damage the Ping))) sensors and/or your BASIC Stamp.  Do not turn power back on until you have double-checked all the connections in this section’s checklist below.  

  • Turn all power off before building the circuit.
  • Double check to make sure the power jumper between the 14 and 13 servo ports is set to Vdd (5 V).
  • Make sure that each 3-wire cable’s black wire is connected to a Ping))) sensor’s GND connection (and red to 5 V and white to SIG).  
  • On the BOE’s breadboard, make sure that each 3-wire cable’s black wire is connected to Vss, each red wire is connected to Vdd, and each white wire is connected to its corresponding I/O pin, P10 to the right Ping))) sensor, and P11 to the left.
  • In the BOE’s servo header, make sure that the front Ping))) sensor is connected to P14 and rear to P15.  Then, double check to make sure that all black wires in the servo ports align with the Black label to the right of the servo.    

The Debug Terminal display after connecting the Ping))) sensors and running the example program will resemble this.  If all the Ping))) sensors are connected correctly, the display should show the centimeter distances of obstacles placed in front of each one (within its 3 cm to 3 m range, and typically +/- 1 cm).  Note that right now, the right Ping))) sensor does not see an obstacle, either because it’s beyond the 3 m limit, or the obstacle might be at an angle that’s reflecting the ultrasonic energy away from (instead of back to) the sensor.  If you put your hand about 10 cm in front of the right sensor, that value should change to about 10.  Make sure that each sensor correctly reports distances when you do that.

  • Run Test Ping Array.bs2.
  • Use the debug terminal and an obstacle (like your hand) 10 cm from each sensor to verify that each Ping))) sensor correctly reports centimeter distances of obstacles you place in front of them.   
  • For any Ping))) that doesn’t respond correctly, check the wiring connections.
' Arlo - Test Ping Array

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

n              VAR     Nib                   ' Counting index
pinPing        VAR     Nib                   ' Ping pin variable
tEcho          VAR     Word                  ' Echo time variable
cm             VAR     tEcho                 ' Recycle echo time as cm

DO                                           ' Main loop
  IF n = 0 THEN DEBUG HOME,                  ' If n is 0 then display heading
                "Ping))) Distances", CR,
                "-----------------", CR
  LOOKUP n, [14, 11, 10, 15], pinPing        ' Pick ping pin
  PULSOUT pinPing, 5                         ' Send chirp
  PULSIN pinPing, 1, tEcho                   ' Measure echo time
  cm = tEcho / 29                            ' Echo time to cm distance
  SELECT n                                   ' Pick which ping to display
    CASE 0: DEBUG "Front: "
    CASE 1: DEBUG "Left:  "
    CASE 2: DEBUG "Right: "
    CASE 3: DEBUG "Back:  "
  ENDSELECT
  DEBUG DEC3 cm, " cm", CR                   ' Display distance
  n = n + 1                                  ' Increment index
  IF n >= 4 THEN n = 0                       ' Reset index after last ping
  PAUSE 50                                   ' Wait 50 ms befor repeat
LOOP                                         ' Repeat main loop

Arlo + BOE Control System Adjustments

Arlo + BOE Control System Adjustments

Integration and deadzone comprise a group of values that may need to be tuned to accommodate certain payload weights, and gearbox play.  The three integration constants (KI, KIT, and KIP) affect how rapidly the Arlo can make final adjustments in its destination.  The deadzone (DZ) value specifies allowable error.  This example program is actually setting the default values, but you can change them, and then test the responses under the conditions you need the Arlo to perform.  

If your battery is charged, and the payload is small, the default settings should be fine.  If payloads increase and decrease during runtime, you may wish to programmatically adjust those constants, either to give it some extra push to get to each final goal, or to apply less push toward the final goal to prevent oscillations (repeated over corrections).  For more information, see the DHB-10 command set for information on KI, KIT, KIP, and DZ.  

Code for making the changes semi-permanent by writing them to the DHB-10’s EEPROM have been commented out.  As long as you keep the lines with STORE commented, the changes only affect performance until the DHB-10 is restarted.  You can restart the DHB-10 by pressing and releasing its Reset button or turning the Motors power off, and then back on.

  • No need to run this program unless you want to observe different possible Arlo behaviours as it approaches its final distance destination.
' Arlo - Tune Integral Constants

' Set control system constants that give the extra push to get to the
' final position and control the allowable positional error.

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

n VAR Byte                                   ' Serial message index

FREQOUT 4, 2000, 3000                        ' Signal program start/reset
DEBUG "Program Running!", CR

' Integral constant, value multiplied by accumulated positional error
' to give wheels that extra push to get to the goal.
n = n + 1                                    ' Increment serial COM index
DEBUG "KI 65", CR                            ' Display integral constant
SEROUT 13, 32800, ["KI 65", CR]              ' Set integral constant
SERIN  13, 32800, 50, ERR, [WAIT(CR)]        ' Wait for DHB-10 confirmation

' Time decay causes older integral measurements to weigh less than newer
' ones.  100 is no decay.  85 takes 85% of the previous measurement, 60%
' of the one before that, etc.
n = n + 1                                    ' Increment serial COM index
DEBUG "KIT 65", CR                           ' Display integral time decay
SEROUT 13, 32800, ["KIT 65", CR]             ' Set integral time decay
SERIN  13, 32800, 50, ERR, [WAIT(CR)]        ' Wait for DHB-10 confirmation

' Smaller values increase the allowed integral contribution to motor power
' at lower speeds.
n = n + 1                                    ' Increment serial COM index
DEBUG "KIP 512", CR                          ' Display integral power ratio
SEROUT 13, 32800, ["KIP 512", CR]            ' Set integral power ratio
SERIN  13, 32800, 50, ERR, [WAIT(CR)]        ' Wait for DHB-10 confirmation

' Max deadzone (positional error) = +/- 1.  Typically set greater than or equal
' to the slack in the wheels.  If you can wiggle the wheel and see a deviation
' of +/- 1, then make deadzone 1.  Deadzone errors do not propagate, so the
' next position goal will start from the previous target value, not the
' previous measured value.
n = n + 1                                    ' Increment serial COM index
DEBUG "DZ 1", CR                             ' Display deadzone
SEROUT 13, 32800, ["DZ 1", CR]               ' Set deadzone
SERIN  13, 32800, 50, ERR, [WAIT(CR)]        ' Wait for DHB-10 confirmation

' Un-comment these lines to make the new settings the ones that get loaded
' when the DHB-10 is reset or turned off and back on.
'n = n + 1                                    ' Increment serial COM index
'DEBUG "STORE KI", CR                         ' Display storing new KI
'SEROUT 13, 32800, ["STORE KI", CR]           ' Remember new KI
'SERIN  13, 32800, 50, ERR, [WAIT(CR)]        ' Wait for DHB-10 confirmation

'n = n + 1                                    ' Increment serial COM index
'DEBUG "STORE KIT", CR                        ' Display storing new KIT
'SEROUT 13, 32800, ["STORE KIT", CR]          ' Remember new KIT
'SERIN  13, 32800, 50, ERR, [WAIT(CR)]        ' Wait for DHB-10 confirmation

'n = n + 1                                    ' Increment serial COM index
'DEBUG "STORE KIP", CR                        ' Display storing new KIP
'SEROUT 13, 32800, ["STORE KIP", CR]          ' Remember new KIP
'SERIN  13, 32800, 50, ERR, [WAIT(CR)]        ' Wait for DHB-10 confirmation

'n = n + 1                                    ' Increment serial COM index
'DEBUG "STORE DZ", CR                         ' Display storing new DZ
'SEROUT 13, 32800, ["STORE DZ", CR]           ' Remember new DZ
'SERIN  13, 32800, 50, ERR, [WAIT(CR)]        ' Wait for DHB-10 confirmation

DEBUG "Done!"                                 ' Display program done

END                                           ' End program

ERR:                                          ' Error routine
  DEBUG "ERROR, no reply from DHB-10.", CR    ' Error message
  DEBUG "n = ", DEC n                         ' Display which message failed
  END                                         ' End program

Troubleshooting Your Arlo + BOE

Troubleshooting

Important: Keep Your DHB-10 Firmware Up-to-Date!
The DHB-10 firmware is expected to undergo occasional revision as continual improvements are made by Parallax and by the community. It is important to make sure your firmware is up to date.

To make sure you always have the latest firmware version, bookmark the following pages and check back regularly for updates: Updating Your Firmware, DHB-10 Firmware Download Page

 

Arlo Failed the Motor Connections Test

  • If the Arlo instead rotates left (clockwise), it means the Motor 2 inputs are reversed. To fix this, turn all power off and swap the DHB-10’s Motor 2 +/- terminal block connections.
  • If it rotates right (counterclockwise) swap the DHB-10’s Motor 1 +/- terminal block connections.
  • If it backs up, (travels toward the power switches), both Motor 1 and Motor 2 +/- terminal block connections will need to be swapped.  Make sure to test between each adjustment.

 

Ready To Mount the Optional Top Deck?

  • Return to the Assembly Guide.

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024


Source URL:https://learn.parallax.com/courses/arlo-with-a-basic-stamp-boe-bot-brain/
Links