Pages: [1] 2   Go Down
Author Topic: Help with nested loops  (Read 1919 times)
0 Members and 1 Guest are viewing this topic.
PA, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am looking for a sketch that will condense this sketch.

Code:
void forward() {
  status_report="Forward1";
  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";
  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]);
  }     
  check_status();
  status_report="Forward3";
  for (servo_number=0;servo_number<number_of_servos;servo_number++){
    if (ping_hit==HIGH) return;
    Servos[servo_number].write(positions_to_forward3 [servo_number]); // puts servo in stand position
    position_saved[servo_number]=(positions_to_forward3 [servo_number]);
  }   
  check_status();
  status_report="Forward4";
  for (servo_number=0;servo_number<number_of_servos;servo_number++){
    if (ping_hit==HIGH) return;
    Servos[servo_number].write(positions_to_forward4 [servo_number]); // puts servo in stand position
    position_saved[servo_number]=(positions_to_forward4 [servo_number]);
  }   
  check_status();
  status_report="Forward5";
  for (servo_number=0;servo_number<number_of_servos;servo_number++){
    if (ping_hit==HIGH) return;
    Servos[servo_number].write(positions_to_forward5 [servo_number]); // puts servo in stand position
    position_saved[servo_number]=(positions_to_forward5 [servo_number]);
  }   
  check_status();
  status_report="Forward6";
  for (servo_number=0;servo_number<number_of_servos;servo_number++){
    if (ping_hit==HIGH) return;
    Servos[servo_number].write(positions_to_forward6 [servo_number]); // puts servo in stand position
    position_saved[servo_number]=(positions_to_forward6 [servo_number]);
  } 
  check_status(); 
  status_report="Forward7";
  for (servo_number=0;servo_number<number_of_servos;servo_number++){
    if (ping_hit==HIGH) return;
    Servos[servo_number].write(positions_to_forward7 [servo_number]); // puts servo in stand position
    position_saved[servo_number]=(positions_to_forward7 [servo_number]);
  }   
  check_status();
  status_report="Forward8";
  for (servo_number=0;servo_number<number_of_servos;servo_number++){
    if (ping_hit==HIGH) return;
    Servos[servo_number].write(positions_to_forward8 [servo_number]); // puts servo in stand position
    position_saved[servo_number]=(positions_to_forward8 [servo_number]);
  }   
  check_status();
  return;
}

I am not sure how to build a multidimentional array for this.
Thanks in advance,
Bob
Logged

PA, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So other info:

Code:
Servo Servos[number_of_servos] ; // max servos is 48 for mega, 12 for other boards

and
Code:
 
const int positions_to_forward1[number_of_servos]={
  135  ,90  ,135  ,90  ,45   ,90  ,45  ,90,
  180  ,90  ,180  ,90  ,0    ,90  ,0   ,90,//lega up/forward
  180  ,0   ,180  ,0   ,0    ,180 ,0   ,180};//legb stand
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 286
Posts: 25666
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

PA, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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
Code:
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.
Logged

PA, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:


Code:
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.
Logged

Italy
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
for (step_number=0;step_number>8;step_number){// eight different steps
The exit condition of the "for" loop is wrong, it may be:
Code:
step_number < 8
Quote
But this doesnot work.
What does it mean exactly?
Logged

PA, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@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
Code:
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.
Code:
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.


Code:
Servos[i][servo_number].write(forward[i][servo_number]);

This is not wrote correct.


Thanks for the help,
Bob     
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 286
Posts: 25666
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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".
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

PA, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@ 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.
Code:
  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.
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Using the 'forward' 2D array you have defined, this will iterate your servos through the positions held there:
Code:
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.
Logged

PA, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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
Code:
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
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

PA, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The sketch so far with just forward and backward.
Code:
#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();
}
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

PA, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1] 2   Go Up
Jump to: