Building an animatronic robot is one thing, but animating it in a realistic way is a completely different challenge. The Hobby server is cheap and popular with animatronics, but just letting it move at maximum speed is not particularly realistic. In the video after the break, [James Bruton] Demonstrate how Use a simple animatronic head and a few extra lines of code to achieve natural movement.
Few natural body movements occur at a constant speed, it always accelerates or decelerates. When we move our head to look at things around us, our neck muscles will sharply accelerate the head in the selected direction, and then gradually decelerate when we reach the end. For this reason, in the Arduino/C code, a new servo intermediate position is specified for each main loop until it reaches the final position. The middle value is the sum of 95% of the current position and 5% of the target position. This gives the effect of the natural movement described above. The ratio can be changed to suit the required speed.
this Delay The function is usually one of the first timing mechanisms learned by new Arduino programmers, but it is not suitable for this application, especially when you are controlling multiple servo systems at the same time. on the contrary, the least bit The function is used to track the system clock in the main loop, and it triggers the position update command at a specified time interval. Adafruit wrote an excellent tutorial on this method of multitasking, in which [James] Based on his code. Of course, for people who have been engaged in embedded programming for a while, this should be old news, but for novices, this is a good introduction.
Like most [James]Project, all code and CAD files are open source, available in GitHub. His projects often appear on Hackaday, such as his single-wheel balancing robot and mechanically multiplexed flip-point display.