Since the amount of memory (RAM) is limited in a micro controller (4k in a ATmega64) the theory of storing a list of servo positions that match the path to follow is not very appealing. Having 11 servo’s that each are 70mm long would require 11*70*2=1540 bytes of memory compared to 11*2=22 bytes in case of only storing the servo positions.

In theory below routine could work to determine the next servo positions:

- Read current servo angles
- Based on the angle and length of the servo all (X, Y) positions can be calculated with respect to the head at location (0, 0)
- From head tot tail servo do below using the spline functions:
- Start with Index=1
- while distance between current point and new point is less than 1mm do decrease index with 0.01

This will find all (dX, dY) of the servo’s when the snake moved forward 1mm along it’s path. Based on this list of new (X, Y) positions and the length of the servo all the servo angles/positions can be calculated again.

This will only work IF the old spline representing the full snake matches exactly the new spline (except of course the new part of the head and the last part of the tail. In order to simulate this the existing spline simulation program can be modified.

Thinking about it a bit more, this will work if the old calculated (X, Y) coordinates are stored and ONLY replaced with new coordinates if the servo moved exactly 1 length along it’s path which is the case when Index reaches 0 in the formula. In this way the spline will never change since the points in which it is based will never change. As a result the amount of bytes needed for storing the path of the snake is limited to storing 11 points each requiring 8 bytes (2 float variables of 4 bytes each). In order to optimize the routines an additional variable is required that holds the last used value of Index. Also the tip of the head and the tail (control points for the first and last spline) must be store next to a new target postion 1 servo length in front of the snake. In total this requires (11+3+1)*8=120 bytes.

Below image shows the translation of servo positions to servo angles and finally to (dX, dY).

In the next coming days I will extend the SplineSim program to test this theory.