walker 0
My first ever walking robot. It’s pretty much my first ever robot period, not counting the BEAM bots. This is just a couple servos, a girder from my old Erector set, and an AVR for a brain. Construction time was about 1.5 hours, and another hour or so dingling with figuring out how to program it to walk. Code below is for Arduino.
After I polish up the forward walking I’ll attempt reverse. If I can get that working I’ll aim for steering too. After that I may or may not try adding a PING))) or IR sensor for avoiding objects.
Update Feb 24: Added reverse, and it mostly works. Backing up is pretty slow and the feet are more likely to get hung up in the carpet when going backwards, but it still does it. I also tweaked the bends of the front legs and totally fouled things up… It’s about 90% back to its original walking ability. I guess my lesson is to fiddle with the code before bending stuff, especially when said stuff is already working.
Update Feb 25: Added a button to switch walking states. Button is on Arduino pin2 so it can be triggered via an interrupt. It simply switches between walkForward, walkBackward, and nothing (no walking). Thanks to this post for teaching me how to debounce a button with an interrupt.
// walker 0 // DR // Feb 22, 2009 - initial version, walked forward // Feb 24, 2009 - Added reverse // Feb 25, 2009 - added button! #include <Servo.h>; // default centers of servos int fCenter = 93; int rCenter = 85; volatile int walkState = 0; // don't walk until button is pressed int buttonPin = 2; // button on arduino pin2 (avr pin4) for interrupt Servo servF; // front servo Servo servR; // rear servo void setup() { pinMode(buttonPin, INPUT); digitalWrite(buttonPin, HIGH); // set internal pullup resistor attachInterrupt(0, changeState, LOW); // interrupt0 is on arduino pin2 servF.attach(9); // front servo on pin9 servF.write(fCenter); // center servR.attach(10); // rear servo on pin10 servR.write(rCenter); // center } void walkForward() { servF.write(fCenter+20); delay(100); servR.write(rCenter-15); delay(400); servF.write(fCenter-20); delay(100); servR.write(rCenter+15); delay(400); } void walkBackward() { servF.write(fCenter+20); delay(100); servR.write(rCenter+20); delay(400); servF.write(fCenter-20); delay(100); servR.write(rCenter-20); delay(400); } void changeState() { static unsigned long last_int_time = 0; unsigned long int_time = millis(); if(int_time - last_int_time > 150){ // if time since last calling is less than 150 it's likely a bounce if(walkState == 0){ walkState = 1; }else if(walkState == 1){ walkState = 2; }else{ walkState = 0; } } last_int_time = int_time; } void loop() { if(walkState == 1){ walkForward(); }else if(walkState == 2){ walkBackward(); } } |

