Lab 7: Crawler

Nicholas's picture

Description

I used some balsa wood, styrofoam packing peanuts, and tape for my crawler. The servo motor is oriented upside-down and balsa wood legs are taped to the head. I glued packing peanuts together to make the legs, and taped a glued group of peanuts to the front of the motor for stability. I also put a piece of tape at the bottom of the stabilizer to reduce traction. Finally, I wrote a program that automatically actuates the crawler. It uses the servo_serial code and alternates between the '5' and '8' settings every 750 milliseconds.

I've noticed the crawler is more successful on some surfaces than another, and it's a little bit brittle. However, given a rough enough surface, it seems to crawl forward reasonably. A video is here: http://www.youtube.com/watch?v=1uIZWeYJ11I.

Materials

  • Servo motor
  • Arduino
  • 8 Styrofoam packing peanuts
  • Balsa wood
  • Masking tape
  • Hot glue

Code

 

/*
 * Servo Control Serial
 * modified for TUI October 2011
 * Servo Serial Better
 *
 * Nicholas Kong
 * October 16, 2011
 *
 * -------------------
 *
 * Created 18 October 2006
 * copyleft 2006 Tod E. Kurt <tod@todbot.com>
 * http://todbot.com/
 *
 * adapted from "http://itp.nyu.edu/physcomp/Labs/Servo"
 */
 
int servoPin = 7;      // Control pin for servo motor
 
int pulseWidth = 0;    // Amount to pulse the servo
long lastPulse = 0;    // the time in millisecs of the last pulse
long switchPulse = 0;
int refreshTime = 20;  // the time in millisecs needed in between pulses
int switchTime = 750;
int val;               // variable used to store data from serial port
 
int minPulse = 500;   // minimum pulse width
int maxPulse = 2250;  // maximum pulse width
 
boolean on = false;
boolean six = true;
 
void setup() {
  pinMode(servoPin, OUTPUT);  // Set servo pin as an output pin
  pulseWidth = (5*(maxPulse-minPulse) / 8) + minPulse;
  Serial.begin(9600);         // connect to the serial port
}
 
void loop() {
  
  //val = six ? '1' : '9';
  val = Serial.read();      // read the serial port
  if (val == '1') {
    on = true;
  } else if(val == '0'){
    on = false;
  }
  
  if(on)
    updateServo();   // update servo position
}
 
// called every loop(). 
// uses global variables servoPi, pulsewidth, lastPulse, & refreshTime
void updateServo() {
  // pulse the servo again if rhe refresh time (20 ms) have passed:
  if (millis() - lastPulse >= refreshTime) {
    pulseWidth = ((six ? 5 : 8) * (maxPulse-minPulse) / 8) + minPulse;
 
    digitalWrite(servoPin, HIGH);   // Turn the motor on
    delayMicroseconds(pulseWidth);  // Length of the pulse sets the motor position
    digitalWrite(servoPin, LOW);    // Turn the motor off
    lastPulse = millis();           // save the time of the last pulse
  }
  
  if(millis() - switchPulse >= switchTime) {
    six = !six;
    switchPulse = millis();
  }
}
 
0
Your rating: None