Don't say anything. I know what you're thinking -- anyone reading this -- you were desperately hoping to spontaneously find an explanation that tells you all about animal walking cycles. ... well, I was going to do something else, but if it's so important, I'll explain it. You're welcome!
So, insects have a bunch of so-called gaits, which are the patterns in which they use their legs. Here are the common ones:
E.g., the first one is where the insect first uses its right hindleg, then its right middle leg, then its right front leg, then its left hind leg, then its left middle leg, then its left front leg. (And then repeats.) The second-last one is where it first uses the right front&hind leg and the left middle leg, then the other three. (And then repeats.) The black stripes denote protraction, which is the swing of the leg forward.
Now, how could evolution have implemented all of this? Since intelligence is all about bits moving around, surely it's with several algorithms that each implement different gaits, right? Or perhaps a more clever interpretation with some modular pieces?
Well, nope! The basic building block here is something called a pacemaker cell, which is a cell that, as the name says, oscillates between different states. (Two weeks ago I still thought this was a fringe theory; I was wrong; it's actually perfectly mainstream.) There's one such oscillator for each leg. When the oscillator reaches a certain point, the leg protracts. You've probably noticed already that the retraction time is always constant (the stripes are all equally long); the insect takes the same amount of time to swing a leg forward if it's running (e.g., second-last gait) than if it's walking slowly (e.g., first gait).
All of these pacemaker cells only obtain a single input from the central nervous system, which is the period (i.e., how long each oscillator takes for each oscillation). That's it! The entire system produces all of this stuff with only a single scalar input! All oscillators have that same frequency.
That itself wouldn't do it of course; the legs also need to be coordinated. Here are the mechanisms:
- There's a so-called "servomechanism circuit" that adjusts the strength of the movement based on sensory feedback about how much is needed, e.g., you need more if it's going uphill. This is the boring part.
- There's a mechanism which the oscillators on the same side exchange information. Basically, whenever the R3 oscillator (right hindleg) reaches a certain point, it sends a signal to R2, and R2 adjusts its speed such that it is a fixed time behind R3. And yes, I mean a fixed time -- not dependent on the period! You'll notice that in all gaits, the time between the start of R3 and R2 is the same! Ditto for R2 and R1, also an exchange of information. And L3 to L2 and L2 to L1.
- There's another mechanism by which each oscillator exchanges information with the same oscillator on the opposite side (i.e., R3 to L3 and R2 to L2 and R1 to L1). The receiving oscillator adjusts itself such that it is exactly half of the period apart, i.e., 180°. Again, you'll notice that in all gaits, R3 and L3 are exactly half of the period apart, and ditto with R2/L2 and R1/L1.
And that's it! Well, almost. That's enough to produce all of the gaits above. And I know this for sure because I've implemented it all with a python program!
You simply set the period, and off it goes. The oscillators are at the left, and each time I've also made it so a new cylce starts, it prints a black stripe on the right. I've made it so they are initially in the wrong position, but the feedback signals above make it so they adjust themselves quickly and are then perfectly stable.
The final detail is an error signal that happens a when a leg doesn't touch the ground. If this didn't exist, then if the insect had lost its middle legs and tried to run (second-last gait), it would do R3&R1 -> L3&L1 -> (loop), which obviously doesn't work because it would fall. But with the final error signal, it does R3&L1 -> R1&L3 -> (loop) instead, which is the same that a 4-legged creature like a horse does when it's running! And the same mechanism also applies when the leg is just temporarily hindered; maybe it's not lost but didn't touch the ground for some reason, then the next leg spontaneously comes for the rescue.