Handle data from array

Hello all,
I am not sure if my approach to this problem in the correct. My project will involve two servo motors which are going to get their positions from an array. Currently my program doesn't include any servo motors attached. I am still trying to work out how to remove the leading zero's from the array. I need to keep in mind that if the array only contains 0's that the servo's are to be at the orgin (next to home)

/*

- direction = 11
+ direction = 22

Example of data format:
A) X+000000Y-000000  Orgin
B) X+003000Y-011500  Tool path 
*/

void setup()
{

  int R = 0;
  int C = 0;
  int const X = 88;          // Servo X
  int const Y = 89;          // Servo Y
  int valueX = 0;            // Path X
  int valueY = 0;            // Path Y
  int directionX = 0;        // + or -
  int directionY = 0;        // + or -

  /*
  P = not needed
  A = might need
            P  P           A         P              A
    {X, 22, 0, 0, 3, 0, 0, 0, Y, 11, 0, 1, 1, 5, 0, 0}
   */

  int Co_Ords[1] [16]    // Current XY values and clockwise/anti-clockwise direction
  {
    {X, 22, 0, 0, 3, 0, 0, 0, Y, 11, 0, 1, 1, 5, 0, 0}
  };

  Serial.begin(9600);

  for (R = 0; R < 1; R++)
  {
    for (C = 0; C < 16; C++)
    {
      Serial.print(Co_Ords [R] [C]);
    }
  }
}

void loop() {

}

What on earth do you mean, "remove the leading zero's from the array"? There is no explanation anywhere in your post or your code about how this program works (enough for anyone else but you to read, anyway).

  int const X = 88;          // Servo X
  int const Y = 89;          // Servo Y

In the array I can't place a value of X or Y. I replaced X,Y with decimal values X = 88 and Y = 89. I replaced (-) with a value of 11 and (+) with a value 22.

  /*
  P = not needed
  A = might need
            P  P           A         P              A
    {X, 22, 0, 0, 3, 0, 0, 0, Y, 11, 0, 1, 1, 5, 0, 0}
   */

The leading zero's have a (P) above them.

What precisely makes them "leading"? Also what determines the position of the numbers in the array? What do you want to do with the spaces that would be left by removing zeros? Shift all the values left? Fill with another character?

Why do you have the strange encodings for "+" and "-"?

Think about how strange this problem must look to someone who has no familiarity with what you are trying to do! Then explain better.

Good point aarg, I didn't think about what happens to the array afterwards.

Why do you have the strange encodings for "+" and "-"?

{X+003000Y-011500}
// Will not work as is

The way the code is (X+) is not a value, nor is (Y-).

X+003000Y-011500

A numeric value prefixed with a zero is interpreted as octal.
I don't know what a Y suffix is meant to signify.

The way the code is (X+) is not a value, nor is (Y-).

That seems to be completely missing the point. Your initial statement was:

My project will involve two servo motors which are going to get their positions from an array

That IMPLIES that the array contains TEXT.

char array[] = "X+003000Y-011500";

In this case, the question of how to get rid of leading 0s is both relevant and irrelevant.

Once you determine that the X value's string is "+003000", then atoi() will convert the string to a int value, 3000. Once you determine that the Y value's string is "-011500", atoi() will convert the string to an int value, -11500.

If you have the data in some other format (besides text), you need to explain just what form at it is in, and quit trying to force it to be in some other format.

  int const X = 88;          // Servo X
  int const Y = 89;          // Servo Y

I made X, Y a value (88, 89). I also made + , - a value (22, 11).
X, Y and -, + will always be in the array. The direction of each axis is decided by the next value 22 or, 11 in the array. The value will make the servo move anti-clockwise or, clockwise.

Gates:

  int const X = 88;          // Servo X

int const Y = 89;          // Servo Y




I made X, Y a value (88, 89). I also made + , - a value (22, 11).
X, Y and -, + will always be in the array. The direction of each axis is decided by the next value 22 or, 11 in the array. The value will make the servo move anti-clockwise or, clockwise.

maybe describe what you are actually trying to do rather than your approach to the solution.

Thank you,

Pauls post #7

Gates:
Thank you,

Pauls post #7

So, Paul explained what it is that you are trying to do?

I don't think so , no.

Ok here is the file. I will delete some of it to run the program.

Feedrate override allowed:
M48

Signals start of data during file transfer. Originally used to stop tape rewind, not necessarily start of program. For some controls (FANUC) the first LF (EOB) is start of program. ISO uses %, EIA uses ER (0x0B).
%

T01
X+003000Y-011500
X+004000Y-011500
X+005000Y-011500
X+006000Y-011500
X+007000Y-011500
X+008000Y-011500
X+009000Y-011500
X+010000Y-011500
X+011000Y-011500
X+012000Y-011500
X+013000Y-011500
X+014000Y-011500
X+015000Y-011500
X+016000Y-011500
X+017000Y-011500
X+018000Y-011500
X+019000Y-011500
X+020000Y-011500
X+021000Y-011500
X+022000Y-011500
X+022000Y-005500
X+021000Y-005500
X+020000Y-005500
X+019000Y-005500
X+018000Y-005500
X+017000Y-005500
X+016000Y-005500
X+015000Y-005500
X+014000Y-005500
X+013000Y-005500
X+012000Y-005500
X+011000Y-005500
X+010000Y-005500
X+009000Y-005500
X+008000Y-005500
X+007000Y-005500
X+006000Y-005500
X+005000Y-005500
X+004000Y-005500
X+003000Y-005500
X+012500Y-015000
X+013500Y-015000
X+004000Y-014500
X+005000Y-014500
X+006000Y-014500
X+007000Y-014500
X+008000Y-014500
X+009000Y-014500
X+003000Y-002000
X+004000Y-002000
X+005000Y-002000
X+006000Y-002000
X+007000Y-002000
X+008000Y-002000
X+009000Y-002000
X+010000Y-002000
X+017000Y-014000
X+018000Y-014000
X+019000Y-014000
X+020000Y-014000
X+017000Y-002000
X+018000Y-002000
X+019000Y-002000
X+020000Y-002000
X+021500Y-014000
X+022500Y-014000
X+021500Y-002000
X+022500Y-002000
X+012500Y-002000
X+013500Y-002000
X+014500Y-002000
X+015500Y-002000
T02
X+015000Y-020500
X+016000Y-020500
X+011000Y-020500
X+012000Y-020500
X+012500Y-023500
X+014500Y-023500
M30

Ok here is the file.

So, the data is all text, and you need to read, parse, and use the numeric tokens.

G Code is perfect for Nick Gammon's State Machine example.

Suggest you try to learn that and apply to your stream.

Review his "More elaborate example"