Skip to main content
added 128 characters in body
Source Link
Alexander
  • 5.2k
  • 1
  • 24
  • 28

G-code was created to be extremely easy to parse by devices with extremely limited computing resources. It's almost more of a data file format than a programming language. There is no "compilation" step. It's interpreted as it is read, line by line, with a small buffer to avoid mechanical issues from timing latency. There's also no "standard library." Firmware typically has to be recompiled for each different combination of microcontroller and motor hardware used, and it takes quite a bit of work to even support what might seem like those minor variations.

In the case of the Marlin firmware, inside the Marlin_main.cpp you have a get_command() function that keeps a queue filled with the commands, and you have a process_next_command()process_next_command() that contains a massive switch statement to pull the next command from the queue and call the appropriate function.

As far as what those individual functions do, that depends a lot on what kind of hardware you have connected, but if you know you have a certain clock rate, a certain type of stepper motors, connected to certain axes, with a certain resolution, connected to certain pins, you can work out the right pins to toggle at the right time to say, move the head in a straight line from a to b along the x axis with a certain speed. From there it's really just a big grind to implement all the different required commands with the correct timing.

G-code was created to be extremely easy to parse by devices with extremely limited computing resources. It's almost more of a data file format than a programming language. There is no "compilation" step. It's interpreted as it is read, line by line, with a small buffer to avoid mechanical issues from timing latency. There's also no "standard library." Firmware typically has to be recompiled for each different combination of microcontroller and motor hardware used, and it takes quite a bit of work to even support what might seem like those minor variations.

In the case of the Marlin firmware, inside the Marlin_main.cpp you have a get_command() function that keeps a queue filled with the commands, and you have a process_next_command() that contains a massive switch statement to pull the next command from the queue and call the appropriate function.

As far as what those individual functions do, that depends a lot on what kind of hardware you have connected, but if you know you have a certain clock rate, a certain type of stepper motors, connected to certain axes, with a certain resolution, connected to certain pins, you can work out the right pins to toggle at the right time to say, move the head in a straight line from a to b along the x axis with a certain speed. From there it's really just a big grind to implement all the different required commands with the correct timing.

G-code was created to be extremely easy to parse by devices with extremely limited computing resources. It's almost more of a data file format than a programming language. There is no "compilation" step. It's interpreted as it is read, line by line, with a small buffer to avoid mechanical issues from timing latency. There's also no "standard library." Firmware typically has to be recompiled for each different combination of microcontroller and motor hardware used, and it takes quite a bit of work to even support what might seem like those minor variations.

In the case of the Marlin firmware, inside the Marlin_main.cpp you have a get_command() function that keeps a queue filled with the commands, and you have a process_next_command() that contains a massive switch statement to pull the next command from the queue and call the appropriate function.

As far as what those individual functions do, that depends a lot on what kind of hardware you have connected, but if you know you have a certain clock rate, a certain type of stepper motors, connected to certain axes, with a certain resolution, connected to certain pins, you can work out the right pins to toggle at the right time to say, move the head in a straight line from a to b along the x axis with a certain speed. From there it's really just a big grind to implement all the different required commands with the correct timing.

Source Link
Karl Bielefeldt
  • 148.9k
  • 38
  • 285
  • 485

G-code was created to be extremely easy to parse by devices with extremely limited computing resources. It's almost more of a data file format than a programming language. There is no "compilation" step. It's interpreted as it is read, line by line, with a small buffer to avoid mechanical issues from timing latency. There's also no "standard library." Firmware typically has to be recompiled for each different combination of microcontroller and motor hardware used, and it takes quite a bit of work to even support what might seem like those minor variations.

In the case of the Marlin firmware, inside the Marlin_main.cpp you have a get_command() function that keeps a queue filled with the commands, and you have a process_next_command() that contains a massive switch statement to pull the next command from the queue and call the appropriate function.

As far as what those individual functions do, that depends a lot on what kind of hardware you have connected, but if you know you have a certain clock rate, a certain type of stepper motors, connected to certain axes, with a certain resolution, connected to certain pins, you can work out the right pins to toggle at the right time to say, move the head in a straight line from a to b along the x axis with a certain speed. From there it's really just a big grind to implement all the different required commands with the correct timing.