DESCRIPTION
In this lab, we controlled the angle of a servo motor first with the serial monitor then with a pot. Next, we attempted to make crawlers with balsa wood and rubber bands.
For homework, I made a 3-legged crawler by attaching 2 “front legs” to a servo and dragging one “back leg” which was used for balance. The front legs consisted of balsa wood, paper clips, and rubber bands while the back leg was a toilet paper roll. The crawler’s “body” consisted of the base of the servo and a piece of balsa wood which was inserted into a slit in the toilet paper roll. I noticed in order to drive the crawler forward, I needed to decrease friction between the front legs and the table so I placed the front legs on a napkin.
I modified the code provided to oscillate the servo back-and-forth by about 30-degrees every 0.3 seconds. This small, compact motion seemed to work well in making the crawler move (slowly) in a straight line. Note that based on the code provided to us, I think my modifications should have resulted in a 70-degree rotation range, but my servo had been modified and at a certain point, it started spinning in circles, so I'm guessing the rotation range was also altered.
I originally tried using 2 servos to make my crawler, but the servos were different models/sizes and one servo didn’t have a firm area to attach “legs” to, so there was too much compliance in the system with that servo to get it to work. I also tried attaching my Arduino/breadboard to my crawler so that I could power it with a 9-volt battery and set it free to walk anywhere, but I couldn’t get the large Arduino board to balance properly on my crawler.
COMPONENTS USED
1- Arduino Uno (plus laptop and USB cable)
1- servo motor
building materials (balsa wood, paper clips, toilet paper roll, rubber bands, napkin)
22 gauge wire
1- breadboard
CODE
/*
* Servo Control Serial
* modified for crawler October 2013
* modified for TUI October 2007
* Servo Serial Better
* -------------------
*
* 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 = 600; // 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
void setup() {
pinMode(servoPin, OUTPUT); // Set servo pin as an output pin
Serial.begin(9600); // connect to the serial port
Serial.println("Servo control program ready");
}
void loop() {
if (val == 600) {
val = 1300;
pulseWidth = val;
updateServo();
}
else {
val = 600;
pulseWidth = val;
updateServo();
}
}
void updateServo() {
// pulse the servo again if rhe refresh time (20 ms) have passed:
if (millis() - lastPulse >= refreshTime) {
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
delay(300);
Serial.println(pulseWidth,DEC);
}
}
IMAGES
The attached image shows the crawler. Unfortunately, I wasn’t able to upload the video.
- Login to post comments