gcode-interpreter

A gcode interpreter I use to control lasers.
git clone git://git.christianermann.dev/gcode-interpreter
Log | Files | Refs | README | LICENSE

machine.h (1543B)


      1 #ifndef MACHINE_H
      2 #define MACHINE_H
      3 
      4 #include "command.h"
      5 #include "timing.h"
      6 
      7 typedef enum {
      8     UNITS_MM,
      9     UNITS_INCHES,
     10 } Units;
     11 
     12 static const char* UNITS_STRINGS[] = {
     13     "mm",
     14     "in",
     15 };
     16 
     17 typedef enum {
     18     POSITIONING_MODE_ABSOLUTE,
     19     POSITIONING_MODE_RELATIVE,
     20 } PositioningMode;
     21 
     22 static const char* POSITIONING_MODE_STRINGS[] = {
     23     "absolute",
     24     "relative",
     25 };
     26 
     27 typedef enum {
     28     EXECUTE_STATUS__UNRECOGNIZED_COMMAND,
     29     EXECUTE_STATUS__UNRECOGNIZED_GCODE,
     30     EXECUTE_STATUS__UNRECOGNIZED_MCODE,
     31     EXECUTE_STATUS__IDLE,
     32     EXECUTE_STATUS__IN_PROGRESS,
     33     EXECUTE_STATUS__FINISHED,
     34 } ExecutionStatus;
     35 
     36 static const char* MACHINE_ERROR_STRINGS[] = {
     37     "command unrecognized.",
     38     "gcode unrecognized.",
     39     "mcode unrecognized.",
     40 };
     41 
     42 typedef struct {
     43     float x;
     44     float y;
     45     float z;
     46 } ControlData;
     47 
     48 typedef struct {
     49     ExecutionStatus status;
     50     bool has_data;
     51     ControlData data;
     52 } ExecutionResult;
     53 
     54 typedef enum {
     55     MOVE_NONE,
     56     MOVE_LINEAR,
     57 } MoveType;
     58 
     59 typedef struct {
     60     float start;
     61     float distance;
     62 } AxisStatus;
     63 
     64 typedef struct {
     65     MoveType type;
     66     Time start;
     67     Time end;
     68     Time duration;
     69     AxisStatus x;
     70     AxisStatus y;
     71     AxisStatus z;
     72 } Move;
     73 
     74 typedef struct {
     75     float x;
     76     float y;
     77     float z;
     78     float feed_rate;
     79     Units units;
     80     PositioningMode positioning_mode;
     81     Move current_move;
     82 } Machine;
     83 
     84 void machine_init(Machine* machine);
     85 ExecutionResult machine_execute_command(
     86     Machine* machine,
     87     const Command* command,
     88     const Time* now
     89 );
     90 
     91 #endif