3.6. Python Scripts¶
3.6.1. Grbl G-code Feeder¶
The grbl_stream.py script is copied from the grbl firmware for Arduino CNC motion distribution for convenience.
3.6.2. Sample Code for G-code Generation¶
This script is used for {broken link}.
g_code_osc_fn.py : demonstration of creating an oscillatory motion represented as a G-code using a simple function
This is a fully self-contained script, i.e. it does not require any special libraries.
This emits a NC program with speeds faster than the grbl defaults. Please issue the following commands using a terminal emulator to set the non-volatile registers:
$110=2000 $120=500
- Afterward, the $$ command should show these entries:
- $110=2000.000 (x max rate, mm/min) $120=500.000 (x accel, mm/sec^2)
-
scripts.g_code_osc_fn.
curve
(time, frequency=0.2, magnitude=2.0)[source]¶ Return a single-axis position value representing a position on a curved path at a given time.
Parameters: - time – time in seconds
- frequency – rate in cycles/second (Hz)
Returns: position in mm
-
scripts.g_code_osc_fn.
emit_move
(output, x_position, speed)[source]¶ Emit a single-axis move to the given location at the given speed. The precision is limited to three decimal places.
Parameters: - x_position – target position in mm
- speed – motion rate in mm/min
-
scripts.g_code_osc_fn.
emit_prelude
(output)[source]¶ Emit a header of G-code commands to reset the machine modes to a known standard state, including the following:
G21 units are mm G90 absolute distance mode G17 select XY plane for arcs G94 set units/mm feed rate mode G54 use default work coordinates