Thing-a-day, Day 22: Walking bot

I went to bed early on Friday, but this is what I had planned to have finished. I was wondering what it would look like to make a macroscale slip-stick motion robot, so here is my attempt. The bot does move forward, but not at a very useful rate, and it appears to be fairly uncontrollable. My conclusion is that to pull this off correctly, you really need a bit more sophisticated leg motion. Source code is after the break.
Update: Thanks to some suggestions by Rubberfishy on Youtube, I was able to improve walking bot’s movements. An updated video is here. Also, a nicer picture of the bot is here.

Anatomy of a leg Standing on its own four legs Testing the walking bot

#include <Servo.h>
#include <SimpleMessageSystem.h>
 
/******************************************************************************************************
 *  Walkbot: a four-legged walking bot
 *
 * by Matt Mets
 * Created 23 Feb. 2008
 *  
 * Trigger some servos in a pattern to make the robot 'walk'
 * Requires the Servo and SimpleMessageSystem libraries
 *
 * This code is released into the public domain.  Attribution is appreciated.
 *
******************************************************************************************************/
 
/***** Variable Definitions ***************************************************************************/
int statusPin =    13;                       // Status LED
Servo servoBL, servoBR, servoFL, servoFR;    // One servo per leg
 
typedef struct feetPositions_t
{
  int FrontLeft;
  int FrontRight;
  int BackLeft;
  int BackRight;
} feetPositions_t;
 
// The table of movements to go through.  Each row is a frame.  The columns correspond to servo
// positions of each feet, in the order FL, FR, BL, BR
feetPositions_t walk_forward[] = {{90, 90, 90, 90},
                                 {60, 90, 90, 90},
                                 {60, 120, 90, 90},
                                 {60, 120, 90, 120},
                                 {60, 120, 60, 120},
                                 {90, 90, 90, 90},
                                 {90, 120, 90, 90},
                                 {60, 120, 90, 90},
                                 {60, 120, 60, 90},
                                 {60, 120, 60, 120}};    
 
// An alternate movement pattern
#if 0
feetPositions_t walk_forward[] = {{90, 90, 90, 90},
                                 {60, 90, 90, 90},
                                 {60, 90, 90, 120},
                                 {60, 120, 90, 120},
                                 {60, 120, 60, 120},
                                 {90, 90, 90, 90},
                                 {90, 120, 90, 90},
                                 {90, 120, 60, 90},
                                 {60, 120, 60, 90},
                                 {60, 120, 60, 120}};
#endif
 
/***** Functions ************************************************************************************/
void setup()
{
  servoBL.attach(2);
  servoBR.attach(3);
  servoFL.attach(4);
  servoFR.attach(5);
 
  pinMode(statusPin, OUTPUT);
 
  Serial.begin(9600);
}
 
// Allow control of the bot via serial commands
// The command expected is m xxx yyy zzz aaa
// where:
//   xxx - Front Left leg position, degrees (0-180)
//   yyy - Front Right leg position, degrees (0-180)
//   zzz - Back Left leg position, degrees (0-180)
//   aaa - Back Right leg position, degrees (0-180)
void do_serial_control()
{ 
  if(messageBuild())
  {
    char firstChar = messageGetChar();
    if(firstChar == 'm')
    {
      servoFL.write(messageGetInt());
      servoFR.write(messageGetInt());
      servoBL.write(messageGetInt());
      servoBR.write(messageGetInt());
    }
  }  
  Servo::refresh();
}
 
// Walk through each position in the sequence
void play_sequence(struct feetPositions_t* sequence, int length)
{ 
  int startTime;
 
  for(int step = 0; step < length; step++)
  {
    // Set the servos to the proper positions for this step
      servoFL.write(sequence[step].FrontLeft);
      servoFR.write(sequence[step].FrontRight);
      servoBL.write(sequence[step].BackLeft);
      servoBR.write(sequence[step].BackRight);
    // delay for some time
    startTime = millis();
    while(millis() - startTime < 500)
    {
      Servo::refresh();
    }
  }
 
}
 
void loop()
{
//  do_serial_control();
 
  play_sequence(walk_forward, 10);
}
This entry was posted in tech, thingaday. Bookmark the permalink.

2 Responses to Thing-a-day, Day 22: Walking bot

  1. joe57005 says:

    this robot could be vastly improved with just some simple modifications to the walking gait. solarbotics.net has some good articles on simple 4-legged robot building.

  2. mahto says:

    Thanks for the link, there is a lot of fun stuff there. I’m not sure this one qualifies as BEAM, but what about a BEAM emulator platform? It might be fun to run some GA or similar optimization routines to see if the robot can teach itself a more efficient way to walk…

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>