twitter
Search

Entries in boe shield (4)

Sunday
Mar252012

Arduino, BOE Shield, PING, and a servo

The video above is in two parts: first with a crawler kit and then with wheels. Switching back to wheels required a code modification to change the time it takes to turn. 
All the parts in the video were released for the original STAMP/Propeller chips, but the code below will get you off and running on the Arduino shield. Only digital pins 10, 11, 12, and 13 are used, so any shield that does not require those pins is available for use. 
// BOE Shield code from "Robotics with the BOE Bot"
// Roaming With Whiskers source, modified to use a PING)))
// sensor on the PING))) servo bracket.
// Using code from the Ping))) example sketch.
#include <Servo.h>                           // Include servo library
Servo servoLeft;                             // Declare left, right and Ping))) servos
Servo servoRight;
Servo PingServo;
int minSafeDist = 11 ;                        // Minimum distance in inches
int pingPin = 10;                             // PING input on 10 so the last servo port is used.
int centerDist, leftDist, rightDist;          // Define distance variables
long duration, inches, cm;                    // Define variables for Ping)))
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
  PingServo.attach(11);
}  
void loop(){
  LookAhead();
  if(inches >= minSafeDist) /* If the inches in front of an object is greater than or equal to the minimum safe distance (11 inches), react*/
  {
    forward (121); //Go Forward
    delay(110); // Wait 0.11 seconds
  }
  else // If not:
  {
    servoLeft.writeMicroseconds(1500);
    servoRight.writeMicroseconds(1500);
    LookAround(); // Check your surroundings for best route
    if(rightDist > leftDist) // If the right distance is greater than the left distance , turn right
    {
      turnRight (250); // Turn Right      
    }
    else if (leftDist > rightDist) // If the left distance is greater than the right distance , turn left
    {
      turnLeft (250); // Turn Left
    }
    else
    {
      backward (250); // Go Backward
    }
    delay (250);
  }
}
void forward(int time)                       // Forward function
{
  servoLeft.writeMicroseconds(1700);         // Left wheel counterclockwise
  servoRight.writeMicroseconds(1300);        // Right wheel clockwise
  delay(time);                               // Maneuver for time ms
}
void turnLeft(int time)                      // Left turn function
{
  servoLeft.writeMicroseconds(1300);         // Left wheel clockwise
  servoRight.writeMicroseconds(1300);        // Right wheel clockwise
  delay(time);                               // Maneuver for time ms
}
void turnRight(int time)                     // Right turn function
{
  servoLeft.writeMicroseconds(1700);         // Left wheel counterclockwise
  servoRight.writeMicroseconds(1700);        // Right wheel counterclockwise
  delay(time);                               // Maneuver for time ms
}
void backward(int time)                      // Backward function
{
  servoLeft.writeMicroseconds(1300);         // Left wheel clockwise
  servoRight.writeMicroseconds(1700);        // Right wheel counterclockwise
  delay(time);                               // Maneuver for time ms
}
unsigned long ping() {
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW); //Send a low pulse
  delayMicroseconds(2); // wait for two microseconds
  digitalWrite(pingPin, HIGH); // Send a high pulse
  delayMicroseconds(5); // wait for 5 micro seconds
  digitalWrite(pingPin, LOW); // send a low pulse
  pinMode(pingPin,INPUT); // switch the Pingpin to input
  duration = pulseIn(pingPin, HIGH); //listen for echo
  /*Convert micro seconds to Inches
   -------------------------------------*/
  cm = microsecondsToCentimeters(duration);
  inches = microsecondsToInches(duration);
}
long microsecondsToInches(long microseconds) // converts time to a distance
{
  return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds) // converts time to a distance
{
  return microseconds / 29 / 2;
}
void LookAhead() {
  PingServo.write(90);// angle to look forward
  delay(175); // wait 0.175 seconds
  ping();
}
void LookAround(){
  PingServo.write(20); // 20° angle
  delay(320); // wait 0.32 seconds
  ping();
  rightDist = inches; //get the right distance
  PingServo.write(160); // look to the other side
  delay(620); // wait 0.62 seconds
  ping(); 
  leftDist = inches; // get the left distance
  PingServo.write(90); // 90° angle
  delay(275); // wait 0.275 seconds
}

 

Sunday
Mar252012

BOE Shield Crawler Kit notes/video

The crawler kit was a big pain to build, but it looks cool! It is essential to use the correct screws and nuts exactly as described in the instructions. Long screws and lock nuts are at the "knees," tapping screws in the pivots, and a nice comfortable drilled hole for the servo horn. 

CODE! The robot is functionally identical to the standard "navigation with whiskers" bot but the whiskers are higher from the ground and bounce up and down. In general - it is far less reliable. Any code included for turns should have durations about four to six times longer to allow for the added turning time of the crawler.

Some tips:

 

  • If you break your servo horn while cutting/drilling the extra space for the bolt, don't worry too much: The other three spokes will do just fine. If you completely break your servo horn, the horns that came with the original BOE Shield kit work fine.
  • Don't let the diagram on the middle legs confuse you - they're both assembled the same way.
  • Double check your washers before tightening the bolts on the middle legs. The one closest to the servo horn is a 1/8" spacer and looks twice as thick as the other nylon washers.
  • Needle-nose pliers are very useful in tightening those lock nuts - but don't over-tighten them!A good measure its to tighten them just enough to allow the friction of a leg to keep it from spinning downward with gravity, then slightly loosen it from there.
  • My crawler kit was four washers short. I easily found matching nylon washers at Lowes (Hillman #6 nylon flat washers)
Friday
Mar232012

BOE Shield Whisker Kit

This video is a direct follow-up on my last post. It just shows the next step of growth on the BOE Bot.

Some notes on assembly:

http://learn.parallax.com/ShieldSetup

It's VERY difficult to use the nylon spacer near the mounting header by the AREF pin. I skipped using the spacer and just used the screw and nut - tightening it until it felt snug.

Between ShieldSetup and building your robot, it actually IS important to do the servo centering. Both of the servos I got were not centered.

http://learn.parallax.com/node/194
The 1" aluminum standoffs and screws aren't attached to the shield when it is shipped. The instructions are there for people who followed the introduction course and mounted the shield before the 
In the same bag, there are two lengths of screws and all fit the standoffs. USE THE SHORT SCREWS FOR THE STANDOFFS. The long screws are needed to mount the servos.

Tires: Annoying!

Spare parts: All bolts are used. Two spare "tire" rubber bands are included. Once you assemble the base kit, you'll have two long screws, two short risers, and two nylon washers left over as well. Those are used for the whisker kit.

Example sketch notes:
Many of the example sketches run all the code in void setup() so they only run once and stop. This means the servo test code will only run once. If your power switch is in the wrong position and you start the test, hit the reset button and see if it runs.

Wednesday
Mar212012

Parallax BOE Shield for Arduino: First Look

I'm a big fan of Parallax and adafruit industries, so was glad to learn that they are now stocking the Parallax BOE Shield for Arduino. I already owned this kit but have yet to have time to play with it. The video above is an unboxing of the BOE Shield, PING))) sensor mounting bracket, and crawler kit. 
The original Parallax BOE-Bot uses Propeller controller and is very good for learning robotics in that environment. The lessons, documentation, and examples are quite detailed. With a focus on education, Parallax wisely decided to expand this platform into Arduino territory. The only "required" pins for the shield are two of 10, 11, 12, and 13. You can choose which two in your Arduino code. The rest can be used with your normal stackable Arduino shields.
To get a general idea of the BOE Shield and completed robot in action, take a look at adafruit's new product announcement.
Here's a photo of the crawler kit sitting on an original BOE bot (borrowed from Parallax's site) that I intend to use with the BOE Shield.
I'll be posting all my source code and a bunch of pictures or videos, but it will all pale in comparison to the online book from Parallax.
Stay tuned for more!