I got the gait code to work on the small crab robot -- actually it only needed some adjustments for the smaller legs. I'm a bit disappointed about how slow the code runs on the M0 -- I didn't even need to add delays for the servos, the calculations take enough time for them to move into place. Oh well. That means the gait is still jerky (because I couldn't do the continuous servo updates), but it works fine.
Then I worked a little bit on the robot's "intelligence". Right now it only has only one sensor, the distance sensor in front. So its behavior is as follows:
- If the distance sensor doesn't detect anything, or the thing detected is too far away, just stand there and scan from left to right and then from right to left. Eye color blue.
- If something is detected far away, walk towards it. Eye color green.
- If something is detected close, stop. Eye color purple. Wait for one second, then check if it moved. If it did, wait again. If it didn't, look right and left, see where you have more room, and turn 60° in that direction. Eye color cyan.
- If something is very close, walk backwards. Eye color red.
And that's it. I also added exception catching, so when the legs get tangled into an impossible position (that happens sometimes), they are moved into their home positions, and then the program resumes.
This procedure gives the robot a nice behavior. It will walk towards things to examine them, and follow people, but if the things don't move, it will get bored with them and walk away, looking for other interesting things.
I'm considering adding one more state, for when it gets bored with scanning -- perhaps it could just shut down and go to sleep then.