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.
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.
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.
If the BOE’s power light did not come on:
Are the P13 and P12 correctly connected to Ch1 and Ch2?
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.
' 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
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).
' 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
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.
' 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
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:
' 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 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.
The program would make a Boe-Bot turn about 90 degrees, but not so with the Arlo.
In the More Precise Maneuvers with Encoders section, we’ll get those 90° turns on the first try!
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.
' 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
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:
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
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.
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.
' -----[ 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
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.
' -----[ 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
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.
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.
' 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
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.
' 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
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