Lab submission 7 - Crawler

Submitted by stlim on Sat, 03/16/2013 - 19:12

Description

This work has been done in a group of Taek and Chan to use two servo motors.

 

Using two servo motors, a crawler is implemented. An eraser cut in half was used for the two legs. A processing code receives inputs from a gamepad and signals the arduino crawler.

 

The legs imitate human knees so each is fixed when it pushes the crawler forward but flexible when it restores. The two legs operate alternatively.

 

The crawler is named "I-Arm Man" and the joint system is named "Kneeraser".

 

Components Used

- 2 servo motors
- 1 arduino uno board
- 1 eraser
- 1 arduino uno board
- 1 gamepad

 

Video Demo

http://youtu.be/Xt9j42pcHO0

 

Code: Arduino

 

int servoPin1 = 7;      // Control pin for servo motor
int servoPin2 = 6;      // Control pin for servo motor
 
int pulseWidth1 = 0;    // Amount to pulse the servo
int pulseWidth2 = 0;    // Amount to pulse the servo
 
long lastPulse = 0;    // the time in millisecs of the last pulse
int refreshTime = 20;  // the time in millisecs needed in between pulses
int val;               // variable used to store data from serial port
 
int minPulse = 500;   // minimum pulse width
int maxPulse = 3000;  // maximum pulse width
 
void setup() {
  pinMode(servoPin1, OUTPUT);  // Set servo pin as an output pin
  pinMode(servoPin2, OUTPUT);  // Set servo pin as an output pin
  pulseWidth1 = minPulse;      // Set the motor position to the minimum
  pulseWidth2 = maxPulse;      // Set the motor position to the minimum
  Serial.begin(9600);         // connect to the serial port
  Serial.println("Servo control program ready");
}
 
void loop() {
  val = Serial.read();      // read the serial port
  
  if (val >= '1' && val <= '9' ) {
    val = val - '0';        // convert val from character variable to number variable
    val = val - 1;          // make val go from 0-8
    pulseWidth1 = (val * (maxPulse-minPulse) / 8) + minPulse;  // convert val to microseconds
    pulseWidth2 = (val * (maxPulse-minPulse) / 8) + minPulse;  // convert val to microseconds
    Serial.print("Moving servo to position ");
    Serial.println(pulseWidth1,DEC);
  }
  updateServo();   // update servo position
}
 
// called every loop(). 
// uses global variables servoPi, pulseWidth1, lastPulse, & refreshTime
void updateServo() {
  // pulse the servo again if rhe refresh time (20 ms) have passed:
  if (millis() - lastPulse >= refreshTime) {
    digitalWrite(servoPin1, HIGH);   // Turn the motor on
    delayMicroseconds(pulseWidth1);  // Length of the pulse sets the motor position
    digitalWrite(servoPin1, LOW);    // Turn the motor off
    digitalWrite(servoPin2, HIGH);   // Turn the motor on
    delayMicroseconds(pulseWidth2);  // Length of the pulse sets the motor position
    digitalWrite(servoPin2, LOW);    // Turn the motor off
    lastPulse = millis();           // save the time of the last pulse
  }
}
 

 

Code: Processing

 

import processing.serial.*;
import procontroll.*;
import net.java.games.input.*;
import ddf.minim.*;
AudioPlayer player;
Minim minim;
 
static String portname = "/dev/tty.usbmodem411";
static Serial port;
static ControllIO ctr;
static final String gamepadName = "Logitech RumblePad 2 USB";
static final int STICKS_REQUIRED = 2;
static final int MULTIPLIER = 200;
static ControllDevice device = null;
static int numOfSticks = 0;
static ControllStick[] sticks;
static float[] xValues;
static int[] outputs;
 
static int centerY;
static int radius = 80;
 
void setup() {
 minim=new Minim(this);
 player=minim.loadFile("superman.mp3");//locate file
 player.play();//when opened play this
 
 size(displayWidth, displayHeight);
  frameRate(30);
  smooth();
  noStroke();
  textSize(40);
  colorMode(RGB, 255);
  background(128);
  centerY = displayHeight/2;
  ellipseMode(RADIUS);  // Set ellipseMode to RADIUS
  fill(30);  // Set fill to white
  
  //  open serial port
  port = new Serial(this, portname, 9600);
  
  //  setup gamepad
  ctr = ControllIO.getInstance(this);
  
  for(int i=0;i<ctr.getNumberOfDevices();i++) {
    ControllDevice cd = ctr.getDevice(i);
    if(cd.getName().compareTo(gamepadName)==0) {
      device = cd;
    }
  }
  
  if(device==null) {
    println("* " + gamepadName + " not found.");
    exit();
  }
  else {
    println("* " + gamepadName + " found.");
  }
  
  numOfSticks = device.getNumberOfSticks();
  
  if(numOfSticks<STICKS_REQUIRED) {
    println("* " + gamepadName + " doesn't have enough number of sticks (" + numOfSticks + " equipped /" + STICKS_REQUIRED + " needed)");
    exit();
  }
  else {
    println("* " + numOfSticks + " sticks found.");
    sticks = new ControllStick[numOfSticks];
    xValues = new float[numOfSticks];
    outputs = new int[numOfSticks];
  }
  
  for(int i=0;i<numOfSticks;i++) {
    sticks[i] = device.getStick(i);
    println(" " + i + " : " + sticks[i].getName());
  }
}
 
void draw() {
  background(128);
  drawCircle();
   if (mousePressed==true){// click to stop music
  player.close();
  minim.stop();
  super.stop();
   }
}
 
void drawCircle() {
  int centerX = displayWidth/2 - 2*radius;
  
  for(int i=0;i<numOfSticks;i++) {
    xValues[i] = sticks[i].getX();
    outputs[i] = (int) (10 * xValues[i]) + 10;
    fill(30 + abs(xValues[i]) * MULTIPLIER);
    ellipse(centerX, centerY + xValues[i]*MULTIPLIER, radius, radius);
    text(xValues[i], centerX-radius, 100);
    centerX+=4*radius;
  }
  
  if(outputs[0]==0) port.write('2');
  else if(outputs[0]==20) port.write('9');
  else {}
}
 
photo_0.JPG
0
Your rating: None
Drupal theme by Kiwi Themes.