Help with nested loops

All those loops seem to put the servos into the stand position.
Why are there so many loops doing the same thing?

There are many forward positions. Each is a snap shot of the leg position during that step.

const int positions_to_forward2[number_of_servos]={
  135  ,45  ,135  ,45  ,45   ,90  ,45  ,90,
  180  ,180 ,180  ,180 ,0    ,90  ,0   ,90,// legb back/kn180
  180  ,90  ,180  ,90  ,0    ,180 ,0   ,180}; 
const int positions_to_forward3[number_of_servos]={
  135  ,45  ,135  ,45  ,45  ,45  ,45  ,45,
  90   ,180 ,90   ,180 ,90  ,90  ,90  ,90,// lega down/kn180
  180  ,180 ,180  ,180 ,0   ,0   ,0   ,0};  
const int positions_to_forward4[number_of_servos]={
  90  ,135  ,90  ,135  ,90   ,45 ,90  ,45,
  90  ,180  ,90  ,180  ,90   ,0  ,90  ,0,//legb up/forward/kn180
  90  ,180  ,90  ,180  ,90   ,0  ,90  ,0};//standa
const int positions_to_forward5[number_of_servos]={
  45  ,135  ,45  ,135  ,0    ,45 ,0    ,45,
  90  ,180  ,90  ,180  ,90   ,0  ,90   ,0,//lega back
  0   ,180  ,0   ,180  ,180  ,0  ,180  ,0};
const int positions_to_forward6[number_of_servos]={
  45  ,135 ,45  ,135  ,0    ,90  ,0   ,90,
  90  ,90  ,90  ,90   ,90   ,90  ,90  ,90,// legb down
  0   ,180 ,0   ,180  ,180  ,0   ,180 ,0};
const int positions_to_forward7[number_of_servos]={
  90  ,90  ,90  ,90  ,90  ,90  ,90  ,90,
  90  ,90  ,90  ,90  ,90  ,90  ,90  ,90,//lega stand
  90  ,90  ,90  ,90  ,90  ,90  ,90  ,90};//legb stand

If I did want it to stand I would

void stand(){
  status_report="Stand...";
  for (servo_number=0;servo_number<number_of_servos;servo_number++){
    Servos[servo_number].write(position_saved[servo_number]); // puts servo in last standing position
    position_saved[servo_number]=(position_saved[servo_number]);
  }  
  check_status();
  return;
}

But to walk forward i use the different positions_to_forward# to load that array onto the servos.

Each loop does the same thing but with different array values. There are 24 values in the array, all for servo positioning.

positions_to_forward1 is the very first postion. Say it lifts legs up. This writes all 24 servos to a position.
positions_to_forward2 is then next one. Say it moves the legs forward. This writes all 24 servos to a new position.
positions_to_forward3 is next. Say it puts the legs down
and positions_to_forward8 is last to move the legs backward.

I want to turn the forward() into something more like this:

forward();
status_report="Forward1";
for (step_number=0;step_number>8;step_number){// eight different steps

    for (servo_number=0;servo_number<number_of_servos;servo_number++){
    Servos[servo_number].write(step_number[servo_number]); // puts servo in stand position
    position_saved[servo_number]=(step_number[servo_number]);
    check_status();
  }  
}

But this doesnot work.

for (step_number=0;step_number>8;step_number){// eight different steps

The exit condition of the "for" loop is wrong, it may be: step_number < 8

But this doesnot work.

What does it mean exactly?

@ramo102
Thank for showing the mistake in the "for" loop.

"But this doesnot work" should have been "But this does not work". Meaning, I still cant get it to work correctly.

Another way for me to describe what the sketch does is:
If you were to take a series of pictures of a spider walking forward, say eight of them, each picture is a step in the whole loop. In order to get forward progress you "play" the loop forward. And then to walk backward, you "play" the loop backwards.
So I will have 6 loops:

forward();
backward();
counter-clockwise();
clockwise();
drift left();
drift right;

this code works but I have to write each position with the postions_to_forward1 and postions_to_forward2

void forward() {
  status_report="Forward1";  //this is step 1
  for (servo_number=0;servo_number<number_of_servos;servo_number++){
    if (ping_hit==HIGH) return;
    Servos[servo_number].write(positions_to_forward1 [servo_number]); // puts servo in stand position
    position_saved[servo_number]=(positions_to_forward1 [servo_number]);
  }    
  check_status();
  status_report="Forward2"; // this is step 2
  for (servo_number=0;servo_number<number_of_servos;servo_number++){
    Servos[servo_number].write(positions_to_forward2 [servo_number]); // puts servo in stand position
    position_saved[servo_number]=(positions_to_forward2 [servo_number]);
  }

There should be a way to
forward(); is made of 8 arrays. Each array is like a picture of the step. To make the robot walk forward, I write the arrays(pictures) to the servos, in sequence, to get the desired direction.

for (i=0;i<number_of pictures_max;i++){                                                             // this is each step for the picture
     for (servo_number=0;servo_number<number_of _servos;servo_number++) {    // this is the array loaded
          Servos[i][servo_number].write(position_for_servo[i][servo_number]);       // writes to servo    
          position_saved[i][servo_number]=(step_number[i][servo_number]);          // saves the position
}
delay(1000)                                                                                                      //delay for servos to move
}

i is the number of the picture in the sequence.
servo_number is one of the 24 servos.

Servos[i][servo_number].write(forward[i][servo_number]);
This is not wrote correct.

Thanks for the help,
Bob

for (step_number=0;step_number>8;step_number){// eight different steps

Even if you change the condition to "step_number < 8", it still won't work correctly, and will form an infinite loop, because you're not modifying "step_number".

@ AWOL
Corrected my mistake.

The current sketch I have works perfect. I am just trying to condense it even more. I am not even sure how to describe what I am after.

  int forward[8][24]={
 {135  ,45  ,135  ,45  ,45   ,90  ,45  ,90,  180  ,180 ,180  ,180 ,0    ,90  ,0   ,90,  180  ,90  ,180  ,90  ,0    ,180 ,0   ,180}, // set servos to the first position
 {35  ,95  ,135  ,45  ,45   ,90  ,45  ,90,  180  ,180 ,180  ,180 ,0    ,90  ,0   ,90,  180  ,90  ,180  ,90  ,0    ,180 ,0   ,180}, // set servos to second position
 {135  ,45  ,135  ,45  ,45   ,9  ,45  ,90,  180  ,180 ,180  ,180 ,0    ,90  ,0   ,90,  180  ,90  ,180  ,90  ,0    ,180 ,0   ,180}, // set servo to next position
 {135  ,25  ,135  ,45  ,45   ,90  ,45  ,90,  180  ,180 ,180  ,180 ,0    ,90  ,0   ,90,  180  ,90  ,180  ,90  ,0    ,180 ,0   ,180},// set servo to next position
 {15  ,45  ,135  ,45  ,45   ,90  ,45  ,90,  10  ,180 ,180  ,180 ,0    ,90  ,0   ,90,  180  ,90  ,180  ,90  ,0    ,180 ,0   ,180},// set servo to next position
 {135  ,45  ,135  ,45  ,45   ,90  ,45  ,90,  180  ,180 ,180  ,180 ,0    ,90  ,0   ,90,  180  ,90  ,180  ,90  ,0    ,180 ,0   ,180},// set servo to next position
 {135  ,45  ,135  ,45  ,45   ,90  ,45  ,90,  180  ,180 ,180  ,180 ,0    ,90  ,0   ,90,  180  ,90  ,180  ,90  ,0    ,180 ,0   ,180},// set servo to next position
 {135  ,45  ,135  ,45  ,45   ,90  ,45  ,90,  180  ,180 ,180  ,180 ,0    ,90  ,0   ,90,  180  ,90  ,180  ,90  ,0    ,180 ,0   ,180}// set servo to next position

};

I know I am close. I just dont know how to put it together.

Using the 'forward' 2D array you have defined, this will iterate your servos through the positions held there:

for (i=0;i<8;i++)
  {                                                             // this is each step for the picture
  for (servo_number=0;servo_number<number_of _servos;servo_number++)
    {    // this is the array loaded
    Servos[servo_number].write(forward[i][servo_number]);       // writes to servo    
    //position_saved[servo_number]=(forward[i][servo_number]);  // saves the position - no idea what this is for
    }
  delay(1000);                                           //delay for servos to move
  }

I could not figure out what is going on with position_saved, so I commented it out.

Also, make forward an array of bytes, none of the numbers there exceed 255 and it'll take up half the space.

Once that's working, write a function based on it that you can pass an array like forward to, with a 'number of pictures' parameter and then your other functions just have to call that, passing the appropriate array of servo settings and the number of rows and it can execute the steps for any of your movements.

void forward() {
  for (i=0;i<8;i++){
    status_report="Forward1";
    status_number=i;
    for (servo_number=0;servo_number<number_of_servos;servo_number++){
      // if (ping_hit==HIGH) return;
      Servos[servo_number].write(forwards[i] [servo_number]); // puts servo in stand position
      position_saved[servo_number]=(forwards[i] [servo_number]);
    }    
    check_status();
  };  
  return;
}

Works Great!!

@wildbill
The position_saved is the last position it was in. So when it has to pause walking, it can still run through the loops in the sketch.
But instead of a new array it just post last know array, which is position_saved

void stand(){  
  for (servo_number=0;servo_number<number_of_servos;servo_number++){
    status_report="Stand...";
     status_number=0;
    Servos[servo_number].write(position_saved[servo_number]); // puts servo in last standing position
    position_saved[servo_number]=(position_saved[servo_number]);
  }  
  check_status();
  return;
}

I changed the array from an "int" to a "byte". I hope that was all I had to do to change it. seems to work fine.
Thanks for the help.
Bob

One more thing to consider, to make the sketch smaller, is that your data is rather repetitive: looks like the last three steps of forward are the same - example data, or a way to keep your robot in the same position for three seconds? Do your different movements share identical rows of server positions? i.e. is there a row in forward that's identical to one in backward? If so, you could make a master array of servo positions, the same as forward, but with all the different unique combinations you use across all your movements.

Then the forward array could be a one dimensional array of byte, each entry telling you which row of servo positions to use from the master array. Thus, you share the servo positioning data across all your movements.

Also, last position can be made easier - you just need to store the movement you're on, e.g. forward, and which row of it you were on when interrupted.

The sketch so far with just forward and backward.

#include <Servo.h> 
#define number_of_servos 24  // the number of servos, up to 48 for Mega, 12 for other boards
#define servo_pin_start 22
const int battery_led = 13;      // select the pin for the battery low LED
const int battery_read_Pin= 10;   // input pin for the battery
String status_report="Checking...";
String status_report_sensor="Checking Sensors";
String error_report="None";
int battery_total_return;
int battery_value_ave;
int battery_low=LOW; // set battery variable to battery is charged
int battery_read;  // variable to store the value coming from the battery
int battery_sum;
int position_saved[number_of_servos];
int standing_state=LOW;
int i;
int j;
int x;// for multipule reads 
int status_number;
int servo_number=number_of_servos;
const int servo_timer_delay=350;
const int low_battery_value=750; //voltage to start low battery state
int number_of_battery_reads=1;
Servo Servos[number_of_servos] ; // max servos is 48 for mega, 12 for other boards
byte forwards[8][number_of_servos]={
  {      
    135  ,90  ,135  ,90  ,45   ,90  ,45  ,90, 180  ,90  ,180  ,90  ,0    ,90  ,0   ,90,  180  ,0   ,180  ,0   ,0    ,180 ,0   ,180      }  
  ,
  {     
    135  ,45  ,135  ,45  ,45   ,90  ,45  ,90,  180  ,180 ,180  ,180 ,0    ,90  ,0   ,90,  180  ,90  ,180  ,90  ,0    ,180 ,0   ,180      }  
  , 
  {     
    135  ,45  ,135  ,45  ,45  ,45  ,45  ,45,  90   ,180 ,90   ,180 ,90  ,90  ,90  ,90,  180  ,180 ,180  ,180 ,0   ,0   ,0   ,0      }
  ,  
  {     
    90  ,135  ,90  ,135  ,90   ,45 ,90  ,45,  90  ,180  ,90  ,180  ,90   ,0  ,90  ,0,  90  ,180  ,90  ,180  ,90   ,0  ,90  ,0       }  
  ,
  {     
    45  ,135  ,45  ,135  ,0    ,45 ,0    ,45,  90  ,180  ,90  ,180  ,90   ,0  ,90   ,0,  0   ,180  ,0   ,180  ,180  ,0  ,180  ,0       }  
  ,
  {     
    45  ,135 ,45  ,135  ,0    ,90  ,0   ,90,  90  ,90  ,90  ,90   ,90   ,90  ,90  ,90,  0   ,180 ,0   ,180  ,180  ,0   ,180 ,0              }  
  ,
  {     
    90  ,90  ,90  ,90  ,90  ,90  ,90  ,90,  90  ,90  ,90  ,90  ,90  ,90  ,90  ,90,  90  ,90  ,90  ,90  ,90  ,90  ,90  ,90              }
  ,
  { 
    45  ,45  ,45   ,45  ,135 ,45  ,135 , 45,  180 ,90  ,180  ,90  ,90  ,90  ,90  ,90,  180 ,0   ,180  ,0   ,0   ,180 ,0   ,180              }
};
byte backwards[8][number_of_servos]={
  { 
    45  ,45  ,45   ,45  ,135 ,45  ,135 , 45,  180 ,90  ,180  ,90  ,90  ,90  ,90  ,90,  180 ,0   ,180  ,0   ,0   ,180 ,0   ,180          }
  ,
  {
    90  ,90  ,90  ,90  ,90  ,90  ,90  ,90,  90  ,90  ,90  ,90  ,90  ,90  ,90  ,90,  90  ,90  ,90  ,90  ,90  ,90  ,90  ,90           }
  ,
  {
    45  ,135 ,45  ,135  ,0    ,90  ,0   ,90,  90  ,90  ,90  ,90   ,90   ,90  ,90  ,90,  0   ,180 ,0   ,180  ,180  ,0   ,180 ,0             }
  ,
  {
    45  ,135  ,45  ,135  ,0    ,45 ,0    ,45,  90  ,180  ,90  ,180  ,90   ,0  ,90   ,0,  0   ,180  ,0   ,180  ,180  ,0  ,180  ,0           }
  ,
  {
    90  ,135  ,90  ,135  ,90   ,45 ,90  ,45,  90  ,180  ,90  ,180  ,90   ,0  ,90  ,0,  90  ,180  ,90  ,180  ,90   ,0  ,90  ,0             }
  ,
  {
    135  ,45  ,135  ,45  ,45   ,90  ,45  ,90,  180  ,180 ,180  ,180 ,0    ,90  ,0   ,90,  180  ,90  ,180  ,90  ,0    ,180 ,0   ,180       }
  ,
  {
    135  ,45  ,135  ,45  ,45   ,90  ,45  ,90,  180  ,180 ,180  ,180 ,0    ,90  ,0   ,90,  180  ,90  ,180  ,90  ,0    ,180 ,0   ,180           }
  ,
  {
    135  ,90  ,135  ,90  ,45   ,90  ,45  ,90, 180  ,90  ,180  ,90  ,0    ,90  ,0   ,90,  180  ,0   ,180  ,0   ,0    ,180 ,0   ,180         }
};
void setup() {
  Serial.begin(115200);
  for(servo_number=0; servo_number < number_of_servos; servo_number++){
    Servos[servo_number].attach(servo_pin_start+servo_number);
    Servos[servo_number].write(forwards[1][servo_number]);
    position_saved[servo_number]=(forwards[1][servo_number]);
  }
  pinMode(battery_led,  OUTPUT);  // declare the ledPin as an OUTPUT:
}
void battery(){
  battery_total_return=0;
  battery_sum=0;
  for (x=0;x<number_of_battery_reads;x++){
    battery_read=analogRead(battery_read_Pin); // read the value from the sensor:
    battery_sum= battery_sum + battery_read;
  }
  battery_total_return = battery_sum / number_of_battery_reads;
  if (battery_total_return<low_battery_value){
    battery_low=HIGH;
    error_report="Battery";
    digitalWrite(battery_led, HIGH);   // turn the battery low led on  
  }
  else  {
    battery_low=LOW;
    error_report="None";
    digitalWrite(battery_led, LOW); // turn the battery low led off:   
  }
}
void hold(){  
  for (servo_number=0;servo_number<number_of_servos;servo_number++){
    status_report="Holding...";
    status_number=0;
    Servos[servo_number].write(position_saved[servo_number]); // puts servo in last standing position
    position_saved[servo_number]=(position_saved[servo_number]);
  }  
  check_status();
  return;
}
void forward() {
  for (i=0;i<8;i++){
    status_report="Forward";
    status_number=i;
    for (servo_number=0;servo_number<number_of_servos;servo_number++){
      Servos[servo_number].write(forwards[i] [servo_number]); // puts servo in stand position
      position_saved[servo_number]=(forwards[i] [servo_number]);
    }    
    check_status();
  };  
  return;
}
void backward() {  
  for (i=0;i<8;i++){
    status_report="Backward";
    status_number=i;
    for (servo_number=0;servo_number<number_of_servos;servo_number++){
      Servos[servo_number].write(backwards[i][servo_number]); // puts servo in stand position
      position_saved[servo_number]=(backwards[i][servo_number]);
    }
    check_status();
  }   
  ;
  return;  
}
void counter_clockwise() {
  for (servo_number=0;servo_number<number_of_servos;servo_number++){
    Servos[servo_number].write(forwards[i] [servo_number]); // puts servo in stand position
    position_saved[servo_number]=(forwards[i] [servo_number]);
  }   
  check_status();
  return;
}
void clockwise() {
  for (servo_number=0;servo_number<number_of_servos;servo_number++){
    Servos[servo_number].write(forwards[i][servo_number]); // puts servo in stand position
    position_saved[servo_number]=(forwards[i][servo_number]);
  }   
  check_status();
  return;
}
void check_status(){
  battery();
  debuger();
  delay(servo_timer_delay);
  if (battery_low==HIGH){
    hold();
  }
}
void debuger(){
  Serial.print(status_report);
  Serial.print(" ");
  Serial.print(status_number+1);
  Serial.write(9);
  Serial.print("Error: ");
  Serial.println(error_report);
  Serial.println("  ");
  Serial.print("Leg#");
  Serial.write(9);
  Serial.print("1");
  Serial.write(9);
  Serial.print("2");
  Serial.write(9);
  Serial.print("3");
  Serial.write(9);
  Serial.print("4");
  Serial.write(9);
  Serial.print("5");
  Serial.write(9);
  Serial.print("6");
  Serial.write(9);
  Serial.print("7");
  Serial.write(9);
  Serial.println("8");
  Serial.println(" ");
  Serial.print("Knee ");
  Serial.write(9);
  Serial.print(position_saved[0]);
  Serial.write(9);
  Serial.print(position_saved[1]);
  Serial.write(9);
  Serial.print(position_saved[2]);
  Serial.write(9);
  Serial.print(position_saved[3]);
  Serial.write(9);
  Serial.print(position_saved[4]);
  Serial.write(9);
  Serial.print(position_saved[5]);
  Serial.write(9);
  Serial.print(position_saved[6]);
  Serial.write(9);
  Serial.println(position_saved[7]);
  Serial.print("Leg ");
  Serial.write(9);
  Serial.print(position_saved[8]);
  Serial.write(9);
  Serial.print(position_saved[9]);
  Serial.write(9);
  Serial.print(position_saved[10]);
  Serial.write(9);
  Serial.print(position_saved[11]);
  Serial.write(9);
  Serial.print(position_saved[12]);
  Serial.write(9);
  Serial.print(position_saved[13]);
  Serial.write(9);
  Serial.print(position_saved[14]);
  Serial.write(9);
  Serial.println(position_saved[15]);
  Serial.print("Hip ");
  Serial.write(9);
  Serial.print(position_saved[16]);
  Serial.write(9);
  Serial.print(position_saved[17]);
  Serial.write(9);
  Serial.print(position_saved[18]);
  Serial.write(9);
  Serial.print(position_saved[19]);
  Serial.write(9);
  Serial.print(position_saved[20]);
  Serial.write(9);
  Serial.print(position_saved[21]);
  Serial.write(9);
  Serial.print(position_saved[22]);
  Serial.write(9);
  Serial.println(position_saved[23]);
  Serial.println(" ");
  Serial.print("Volt");
  Serial.write(9);
  Serial.println("Batled");
  Serial.print(battery_sum); 
  Serial.write(9);   
  Serial.println(battery_low); 
  Serial.println("----------------------------------------");  
  Serial.println("      ");
  Serial.println("      ");
  Serial.println("      ");
  Serial.println("      ");
  Serial.println("      ");
  Serial.println("----------------------------------------");  
}
void loop()
{        
  backward();
  forward();
}

Looking at your data to check my theory that you use the same 24 servo settings in both the instructions for forward & backwards, I noticed that for the most part, forward, is simply backward in reverse, so there is a space saving to be had.

However, they are so similar, that I wonder if the differing lines are correct. Based on the match everywhere else, I'd expect the third row of Forward to match the sixth row of backward, but they don't, quite.

To be honest, I do not have the servos yet. And the values in the arrays are not correct. Nor is the platform on which the servos will be attached built. The platform is going to be homebuilt. So I do not know the angles to set in the array for the functions. It will be a matter of putting it all together and measuring the values. The ones in the array are just estimates. When I get my servos and attach them to the platform, I can get real values for the array. Also, I do not know if 8 arrays will be enough to complete the loop. 8 is the very least I can have. I tried to make this a variable, but the sketch failed to compile.
I also will have 4 other instructions;counter-clockwise,clockwise,drift_left,drift_right. All of these will have the same basic array numbers.

I am interested in the "space saving to be had." For the backwards I was gonna try for (i=7;i>0;i--)
forgive me if that is totally wrong. I have not looked it up yet.
Would it be better to have 1 master array and have the different functions call on different parts of that array?
Thanks for the help,
Bob

for (i=7;i>=0;i--) would do the trick

For the master array, which looks like your forward today, but with more rows, what I was thinking was that each row of the array represents an action the robot can make as part of its walking sequence e.g. extend front legs. So each one is a basic walking operation. So the forward, backward commands etc could be thought of as a little sequence (program) of robot walking op codes:

byte forward[] = {3,5,6,9,12};

Which means set servos to the positions at row 3 of the master array, then 5, then 6....

Then you can have a function that you call like this:

DoWalkingSequence(forward,sizeof(forward)/sizeof(byte));

This function just iterates through the array it was passed, forward in this example, and sets the servos to the positions from the appropriate row of the master array

Then you can use the same 'walking opcodes' in several different sequences to achieve the movements you want, but allowing each opcode to be specified only once to keep memory usage down.

Consts, enums, #defines can make it more readable, but that's the basic idea.

So if I use the DoWalkingSequence() function, it will use less memory because it wont have to load the whole master array? It just loads the specific rows? And it also uses less memory because of the byte type variable? Also, how does the function fit into a loop? I have briefly looked over enums and #defines. I am still reading on them. When I started this project, I knew when my sketch got to a certain level, it would become too complex for me to understand by just reading to learn. That is why I choose to use this method of locomotion. I would love to use some kind of inverse kinematics to move the robot. But I am finding it difficult to learn it by the internet.

If I can use the DoWalkingSequence() in a loop it would work very well for what I am doing. Thank you for the advice and help.
Bob

Can you please show me how the DoWalkingSequence() function is wrote? I am not understanding how to use it?
I am not sure how this: DoWalkingSequence(forward,sizeof(forward)/sizeof(byte));
works.Such as the sizeof area, and what would change if i wanted to go backward. Thanks again for all the help.
Bob

Here's what I had in mind: You have a master array of servo positions, each of which is what you earlier described as a picture. I assume that when moving, you will use these pictures in more than one movement. So, you can add an extra level of indirection and have an array I've called forward, which is a list of indexes of pictures that make up forward motion and other arrays for other movements. Like this - compiles, not tested though:

#include <Servo.h>

#define number_of_servos 24

 byte Master[][number_of_servos]=
{
 {135  ,45  ,135  ,45  ,45   ,90  ,45  ,90,  180  ,180 ,180  ,180 ,0    ,90  ,0   ,90,  180  ,90  ,180  ,90  ,0    ,180 ,0   ,180}, // set servos to the first position
 {35  ,95  ,135  ,45  ,45   ,90  ,45  ,90,  180  ,180 ,180  ,180 ,0    ,90  ,0   ,90,  180  ,90  ,180  ,90  ,0    ,180 ,0   ,180}, // set servos to second position
 {135  ,45  ,135  ,45  ,45   ,9  ,45  ,90,  180  ,180 ,180  ,180 ,0    ,90  ,0   ,90,  180  ,90  ,180  ,90  ,0    ,180 ,0   ,180}, // set servo to next position
 {135  ,25  ,135  ,45  ,45   ,90  ,45  ,90,  180  ,180 ,180  ,180 ,0    ,90  ,0   ,90,  180  ,90  ,180  ,90  ,0    ,180 ,0   ,180},// set servo to next position
 {15  ,45  ,135  ,45  ,45   ,90  ,45  ,90,  10  ,180 ,180  ,180 ,0    ,90  ,0   ,90,  180  ,90  ,180  ,90  ,0    ,180 ,0   ,180},// set servo to next position
 {135  ,45  ,135  ,45  ,45   ,90  ,45  ,90,  180  ,180 ,180  ,180 ,0    ,90  ,0   ,90,  180  ,90  ,180  ,90  ,0    ,180 ,0   ,180},// set servo to next position
 {135  ,45  ,135  ,45  ,45   ,90  ,45  ,90,  180  ,180 ,180  ,180 ,0    ,90  ,0   ,90,  180  ,90  ,180  ,90  ,0    ,180 ,0   ,180},// set servo to next position
 {135  ,45  ,135  ,45  ,45   ,90  ,45  ,90,  180  ,180 ,180  ,180 ,0    ,90  ,0   ,90,  180  ,90  ,180  ,90  ,0    ,180 ,0   ,180}// set servo to next position
};

byte Forward[]={3,4,0,7};
byte OtherMovement[]={1,2,0,5};

Servo Servos[number_of_servos] ; 

void setup()
{
// Do attach and other setup
}

void loop()
{
DoWalkingSequence(Forward,sizeof(Forward)/sizeof(byte)); 
DoWalkingSequence(OtherMovement,sizeof(OtherMovement)/sizeof(byte)); 
}

void DoWalkingSequence(byte *Movements,int NumMovements)
{
for (int i=0;i<NumMovements;i++)
  {                                                             // this is each step for the picture
  for (int servo_number=0;servo_number<number_of_servos;servo_number++)
    {
    Servos[servo_number].write(Master[Forward[i]][servo_number]);       // writes to servo    
    }
  delay(1000);                                           //delay for servos to move
  }

}

If you wanna get really geeky on this, here's something to consider. What you're doing is known as key frame animation. You only need your servo positions for each key frame animation. From there, you can interpolate and tween your entire robotic movement. Taking this approach means you need only key frame your specific animations and the tweening would allow you to mix them as you desire. So for example, you could tween a walking and hand waving motion without explicitly coding that combination. Rather, you would have key frames for walking and key frames for waving.

Your master loop would then only care about a relative reference clock and the specific animations you wish to animate. So for example, a forward walk would likely look something like four to eight key frames and a backward walk would be the reverse sequence. The fact is was walking, versus any other movement, would be completely arbitrary, aside from the named association with that specific set of associated key frames.

If you look, you can find lots of coding examples of interpolation, and tweening. Of course, the complexity rises with the provided flexibility.

After a few years sitting on the shelf, I've dusted off this project. I wanted to thank wildbill and gerg for the help. Now, where are my notes. ...