Sunday, July 18, 2010

Gaits









This post was inspired by a discussion with my dad while walking the dogs. If you look at old paintings of horse races (see above) , their legs are completely outstretched in the front and back. These kinds of paintings, all before high-speed photography, were painted at a time when people didn't really know what horses looked like when they're running.

In 1878, our very own Leland Stanford settled the debate over whether horses are ever fully airborne while running: he organized the first ever example of a high-speed photo shoot (and hence the forerunner of motion picture technology) . Here's the photo, taken on June 10, 1878, at his Palo Alto track.

Here, I'll describe walking (actually the most complicated of gaits) :

The dog alternates between two and three legs supporting the body. Thus, there are eight 4C3 (three-leg combinations) plus 4C2 (two-leg combinations) minus the two combinations where you have the two front legs at the same time and then the two back legs at the sam time. That's four each. It's an eight-beat cycle, which means that after eight steps/lifts, it starts all over, like a video reaching the end and starting again. Each odd beat, for example, the dog has two paws down, and each even one it has three.

Viewing the odd and even beats separately, you can see that on each paw stays down for n beats, where n is the number of paws down on the particular beat. Thus, in the whole cycle, each paw stays down for n=2 + n=3 = 5 beats.

Here's a diagram for the odd beats (let the dot represent a placed paw) :
0 •  |  0 •  |  • 0  |  • 0
• 0  |  0 •  |  0 •  |  • 0
Which, if you think about it, is really the only way you can cycle through those four positions if you adhere to each paw staying down for two beats. There are six possible orderings of the four positions (4! arrangements, but /4 for the cycles) . If you think of the above ordering that we know works as the order 234 (1234) , then you see that to avoid jumping from a position to its opposite, i.e.:
|  0 •  |  • 0  | 
|  0 •  |  • 0  | 
or the equivalent other (the diagonal mirror) , you have to come up with an order that never pairs 2 and 4 together, like above, nor does it do so with 1 and 3, which would automatically follow -- because it's a cycle, hence it repeats, so 1243 still pairs 1 and 3 at the head and tail. So, to avoid such a pairing, your only other possibility is 1423. Or, you could work it out as ordering the letters abB such that the 'b' and the 'B' are never together, so you just fix one at the start (one possibility of the remaining 2! is good) and same for the other, which gives you 1+1=2 total ways to avoid the jump. So, for now let's just remember: there's only one position and its mirror that work.

As for the three-paw steps, you can view the cycle as each next beat. Like so (to view the whole eight-beat cycle, the i^th three-paw beat in this cycle is the beat right after the i^th two-paw step) :
0 •  |  • •  |  • 0  |  • •
• •  |  0 •  |  • •  |  • 0

What about the other five possibilities? For example, how about it be such that the paw that lifts is the next in an anti-clockwise or clockwise circle? As in,
0 •  |  • •  |  • •  |  • 0
• •  |  0 •  |  • 0  |  • •
? Well, if you combine that with the odd beats you get the following:
  1      2   3       4        5       6       7 8
0 • |  0 •  |  0 •  |  • •  |  • 0  |  • •  |  • 0  |  • 0
• 0 |  • •  |  0 •  |  0 •  |  0 •  |  • 0  |  • 0  |  • •
, where 
1|2|3|4|5|6|7|8
the front left paw goes 0|0|0|•|•|•|•|• , which is OK,
the front right paw goes •|•|•|•|0|•|0|0 , which is not,
the back left paw goes •|•|0|0|0|•|•|• , which is OK,
the back right paw goes 0|•|•|•|•|0|0|• , which is not.

front right and back left don't fit. The other five possibilities don't work, either -- but the mirror of the one that does works with our original mirror for the two-paw beats. So, basically, there are only two sets of beats that work for walking: the original that we worked out, and its mirror.

Here's some code I wrote up (quickly, so it's not very nice) you can compile to simulate walking (you'll have to #include iostream, vector, algorithm and iterator for it to compile -- I'd include it here, but the blog posting script treats it as an html tag) :

using namespace std;

void PrintEachPaw(const vector<string> &v) {
 cout << "In the order of FL, FR, BL, BR:\n";
 copy(v.begin(), v.end(), ostream_iterator<string>(cout, "\n"));
return;
}

void PrintEachBeat(const vector<string> &v) {
cout << endl;
for (size_t i = 0; i < 8; i++) {
for (size_t j = 0; j < 4; j++) {
if (j == 2)
cout << endl;
cout << v[j][i];
}
cout << endl << endl;
}
return;
}

int main (int argc, char *const argv[]) {
vector<string> v;
string a, b, c, d;
v.push_back(a);
v.push_back(b);
v.push_back(c);
v.push_back(d);
for (size_t i = 0; i < v.size(); i++) {
v[i] = "........";
for (int j = 0; j < 3; j++)
v[i][((i*2)+j)%8] = '0';
}
string temp = v[2];
v[2] = v[1];
v[1] = temp;
PrintEachPaw(v);
PrintEachBeat(v);
return 0;
}

1 comment:

  1. This is really interesting! We had to study gaits in ME112 when we built walking robots...

    There's all kinds of interesting stuff out there besides quadrupeds! There are centipede robots:
    http://www.youtube.com/watch?v=1-rSfYUpZNk

    And there's an amazing six-legged robot that has an interesting gait that allows it to traverse almost any kind of terrain: http://www.youtube.com/watch?v=a0NFrA-Nx4Y

    It turns out, by the way, that cockroaches have a gait and leg structure that are optimized to minimize the amount of neurons firing in their tiny little brain. When cockroaches traverse obstacles, they don't think about it; they just run and their gait does all the work! Scientists have proved this by building extraordinarily simple robots (no control systems) and if they just run headlong into obstacles, the right gait allows them to easily get past them!

    ReplyDelete