CNC Gcode prog error

Hello,

I am trying to use gcode for my cnc project. I am using bellow programming for fetching and executing gcode by Dan.

No, I have 1 problem in 3rd step that "parsenumber" can not be used as function.

Here is my code.

#define BAUD (9600) // How fast is the Arduino talking?
#define MAX_BUF (64) // What is the longest message Arduino can store?

char buffer[MAX_BUF]; // where we store the message until we get a ';'
int sofar; // how much is in the buffer
/**
 * First thing this machine does on startup. Runs only once.
 */
void setup() {
  Serial.begin(BAUD); // open coms
  help(); // say hello
int set_feedrate(200); // set default speed
  ready();
}

/**
 * display helpful information
 */
void help() {
  Serial.print(F("CNC Robot "));
  Serial.println(F("Commands:"));
  Serial.println(F("G00 [X(steps)] [Y(steps)] [F(feedrate)]; - linear move"));
  Serial.println(F("G01 [X(steps)] [Y(steps)] [F(feedrate)]; - linear move"));
  Serial.println(F("G04 P[seconds]; - delay"));
  Serial.println(F("G90; - absolute mode"));
  Serial.println(F("G91; - relative mode"));
  Serial.println(F("G92 [X(steps)] [Y(steps)]; - change logical position"));
  Serial.println(F("M18; - disable motors"));
  Serial.println(F("M100; - this help message"));
  Serial.println(F("M114; - report position and feedrate"));
}

/**
 * prepares the input buffer to receive a new message and 
 * tells the serial connected device it is ready for more.
 */
void ready() {
  sofar=0; // clear input buffer
  Serial.print(F("> ")); // signal ready to receive input
}
/**
 * After setup() this machine will repeat loop() forever.
 */
void loop() {
  // listen for commands
  if( Serial.available() ) { // if something is available
    char c = Serial.read(); // get it
    Serial.print(c); // optional: repeat back what I got for debugging

    // store the byte as long as there's room in the buffer.
    // if the buffer is full some data might get lost
    if(sofar < MAX_BUF) buffer[sofar++]=c;
    // if we got a return character (\n) the message is done.
    if(c=='\n') {
      Serial.print(F("\r\n")); // optional: send back a return for debugging

      // strings must end with a \0.
      buffer[sofar]=0;
      float processCommand(); // do something with the command
      ready();
    }
  }
}

/**
 * Read the input buffer and find any recognized commands. One G or M command per line.
 */
void processCommand() {
  // look for commands that start with 'G'
  int parsenumber=0;
  int cmd=parsenumber('G',-1);
  switch(cmd) {
  case 0: // move in a line
  case 1: // move in a line
    set_feedrate(parsenumber('F',fr));
    line( parsenumber('X',(mode_abs?px:0)) + (mode_abs?0:px),
    parsenumber('Y',(mode_abs?py:0)) + (mode_abs?0:py) );
    break;
  // case 2: // clockwise arc
  // case 3: // counter-clockwise arc
  case 4: pause(parsenumber('P',0)*1000); break; // wait a while
  case 90: mode_abs=1; break; // absolute mode
  case 91: mode_abs=0; break; // relative mode
  case 92: // set logical position
    position( parsenumber('X',0),
   parsenumber('Y',0) );
    break;
  default: break;
  }

  // look for commands that start with 'M'
  cmd=parsenumber('M',-1);
  switch(cmd) {
  case 18: // turns off power to steppers (releases the grip)
    m1.release();
    m2.release();
    break;
  case 100: help(); break;
  case 114: where(); break; // prints px, py, fr, and mode.
  default: break;
  }

  // if the string has no G or M commands it will get here and the Arduino will silently ignore it
}

Look at these two lines

  int parsenumber=0;
  int cmd=parsenumber('G',-1);

In the first line a variable called parsenumver is created. In the second line there is an attempt to call a function called parsenumber.

You can't use the same name for two different purposes and I don't know what you really want to do.

Also there is no definition of a function called parsenumber() or even anything similar that it might have been confused with.

...R

 int parsenumber = 0;
  int cmd = parsenumber('G', -1);

parsenumber is declared as an integer but you are trying to use it as a function.
What is the second line of code meant to do ?

Other people who posted on the page you got the code from seem to have the same problem but the author has not replied

Reading a little bit into the article, the author states

Source

Want the entire source in one file, ready to compile? Here you go. I use a version of this code in nearly all Marginally Clever robots.

Edit 2014-09-29: I’ve since added examples for Adafruit Motor Shield v1, Adafruit Motor Shield v2, RUMBA, and RAMPs.

The link in the above "quote" leads to a github repository which has a bunch of stuff, one of which is "GcodeCNCDemo2Axis"
The code there includes parsenumber(); (as well as a bunch of other things)
Be aware that you will need to download (and probably edit) config.h as well.

[EDIT]
I also note that the code you posted would not work in other respects as well.
You neglected to include the entire section that actually moves the steppers.
That's under the section "Drawing Lines".
The code in the article also has some similar issues with some support functions not declared.

I think the article was more of an instructional aid, rather than a fully functioning program, which needs to be downloaded from GitHub

int set_feedrate(200); // set default speed

What is this supposed to do? Why would you define a local variable in this bizarre format, when the variable immediately goes out of scope?

      float processCommand(); // do something with the command

This is a function prototype, defining a function that takes no arguments and returns a float. It does NOT belong in the middle of the loop() function.

void processCommand() {

WTF are you doing? Is this function supposed to return a float or nothing?

@CyberSasu, I think the overall conclusion from the various replies is that if this is a program you downloaded from somewhere it is a bunch of cr*p so just chuck in the trash and start all over.

...R

Unless you need to write a custom interface to parse and run gcode (such as your own unique inverse kinematics), consider using grbl or marlin. It solves both ends of the problem, both the code for the Arduino, and the provision for communicating with it using well designed pc interfaces.

I wish I could just use grbl or marlin for my robot arm, but its far too involved to modify it to incorporate unique inverse kinematics. It's designed for cartesian kinematics or delta kinematics.

I'm trying to write my own Arduino software that will communicate with Universal Gcode sender, but its not easy.

Which version are you trying to get running?