Try & Tune Some BOE Shield-Bot Code

Try & Tune Some BOE Shield-Bot Code

Try the Unmodified Code

Let’s try the ForwardLeftRightBackward.ino sketch from http://learn.parallax.com/node/219 in Robotics with the BOE Shield-Bot web book.  You might have noticed that the second to last call in the previous sketch: Arlo.writePulseMode().. That switched the Arlo’s DHB-10 from serial communication mode to pulse mode in preparation for this sketch.  When the Arlo’s DHB-10 starts up, it automatically goes into pulse mode.  So, another option for switching a sketch 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 Shield (position-2)
  • Upload ForwardLeftRightBackward.ino.
  • Turn all power off, unplug the programming cable, and take to your Arlo to the navigation area.
  • Press and hold the RST button on your BOE Shield.
  • Turn MAIN and MOTORS power on.
  • Let go of the RST button and quickly set the BOE Shield power switch to 2 (you will only have a couple of seconds to do this).
  • Verify that the Arlo goes forward, turns left, then right, then backs up to near where it started.

The sketch would make a BOE Shield-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 600 = 900 try replacing the 600ms delay with 900 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! 

// Robotics with the BOE Shield - ForwardLeftRightBackward
// Move forward, left, right, then backward for testing and tuning.

#include <Servo.h>                           // Include servo library

Servo servoLeft;                             // Declare left and right servos
Servo servoRight;

void setup()                                 // Built-in initialization block
{
  tone(4, 3000, 1000);                       // Play tone for 1 second
  delay(1000);                               // Delay to finish tone

  servoLeft.attach(13);                      // Attach left signal to pin 13
  servoRight.attach(12);                     // Attach right signal to pin 12

  // Full speed forward
  servoLeft.writeMicroseconds(1700);         // Left wheel counterclockwise
  servoRight.writeMicroseconds(1300);        // Right wheel clockwise
  delay(2000);                               // ...for 2 seconds

  // Turn left in place
  servoLeft.writeMicroseconds(1300);         // Left wheel clockwise
  servoRight.writeMicroseconds(1300);        // Right wheel clockwise
  delay(600);                                // ...for 0.6 seconds

  // Turn right in place
  servoLeft.writeMicroseconds(1700);         // Left wheel counterclockwise
  servoRight.writeMicroseconds(1700);        // Right wheel counterclockwise
  delay(600);                                // ...for 0.6 seconds

  // Full speed backward
  servoLeft.writeMicroseconds(1300);         // Left wheel clockwise
  servoRight.writeMicroseconds(1700);        // Right wheel counterclockwise
  delay(2000);                               // ...for 2 seconds

  servoLeft.detach();                        // Stop sending servo signals
  servoRight.detach();
}  

void loop()                                  // Main loop auto-repeats
{                                            // Empty, nothing needs repeating
}