How to add a delay control to a pen plotter running grbl

A simple hack to add a delay after a servo move...

grbl is a wonderful piece of software. One of the issues that lacks solution is the delay control when, instead of using the typical CNC spindle, one uses a servo to control a pen plotter. Here's a simple hack: download grbl, look for the gcode.c file and locate the following part:

// [4. Set spindle speed ]:
  if ((gc_state.spindle_speed != gc_block.values.s) || bit_istrue(gc_parser_flags,GC_PARSER_LASER_FORCE_SYNC)) {
    if (gc_state.modal.spindle != SPINDLE_DISABLE) {
      #ifdef VARIABLE_SPINDLE
        if (bit_isfalse(gc_parser_flags,GC_PARSER_LASER_ISMOTION)) {
          if (bit_istrue(gc_parser_flags,GC_PARSER_LASER_DISABLE)) {
             spindle_sync(gc_state.modal.spindle, 0.0);
          } else { spindle_sync(gc_state.modal.spindle, gc_block.values.s); }
        }
      #else
        spindle_sync(gc_state.modal.spindle, 0.0);
      #endif
    }
    gc_state.spindle_speed = gc_block.values.s; // Update spindle speed state.
  }

add the following line mc_dwell(0.2); (see below).

// [4. Set spindle speed ]:
  if ((gc_state.spindle_speed != gc_block.values.s) || bit_istrue(gc_parser_flags,GC_PARSER_LASER_FORCE_SYNC)) {
    if (gc_state.modal.spindle != SPINDLE_DISABLE) {
      #ifdef VARIABLE_SPINDLE
        if (bit_isfalse(gc_parser_flags,GC_PARSER_LASER_ISMOTION)) {
          if (bit_istrue(gc_parser_flags,GC_PARSER_LASER_DISABLE)) {
             spindle_sync(gc_state.modal.spindle, 0.0);
          } else { spindle_sync(gc_state.modal.spindle, gc_block.values.s); }
        }
      #else
        spindle_sync(gc_state.modal.spindle, 0.0);
      #endif
    }
    gc_state.spindle_speed = gc_block.values.s; // Update spindle speed state.

    mc_dwell(0.2); // add this line to set delay for servo motion (in mseconds !?)
  }

Compile the code and upload it. That's it.

Happy hacking!

P.S.

I'm using this spindle_control.c. Servo is controlled by M3 Sx where x take the values 0-255.

Palavras chave/keywords: grbl, plotter, servo, delay, arduino

Criado/Created: 13-04-2022 [16:49]

Última actualização/Last updated: 13-04-2022 [21:59]


Voltar à página inicial.


GNU/Emacs Creative Commons License

(c) Tiago Charters de Azevedo