Skip to content

What is GScript?

GScript is a modern, human-readable programming language for CNC machines that compiles to G-code. It provides a safer, more maintainable alternative to writing G-code directly, with built-in validation, optimization, and multi-backend support.

The Problem with G-code

Traditional G-code programming has several challenges:

  • Cryptic Syntax: Commands like G01 X10 Y20 F300 are hard to read and understand
  • No Type Safety: Easy to make mistakes with coordinates, feed rates, or tool numbers
  • Manual Optimization: You must manually optimize toolpaths and eliminate redundancies
  • Backend-Specific: Different CNC controllers use different G-code dialects
  • Limited Validation: Errors often aren't caught until runtime on the machine

The GScript Solution

GScript addresses these problems by providing:

High-Level Operations

Instead of manually calculating toolpaths, use operations like:

gscript
face {
    area: rect(0, 0, 100, 100),
    tool: endmill_6mm,
    depth: 2.0,
    stepover: 0.75,
}

Type-Safe Tool Definitions

Define tools with full specifications:

gscript
tool endmill_6mm {
    diameter: 6.0,
    flutes: 4,
    max_rpm: 18000,
    max_feedrate: 2000.0,
}

Built-in Safety

GScript validates:

  • Tool collisions with workpiece boundaries
  • Feed rate limits based on tool specifications
  • Workspace boundaries
  • Tool reach and accessibility
  • Material removal rates

Multi-Backend Compilation

Write once, compile to any backend:

bash
gscript compile program.gs --backend grbl
gscript compile program.gs --backend marlin
gscript compile program.gs --backend fanuc

Automatic Optimization

Choose your optimization level:

  • O0: No optimization (fastest compilation)
  • O1: Basic optimization (redundancy elimination)
  • O2: Advanced optimization (feedrate optimization)
  • O3: Aggressive optimization (travel path optimization)

Core Features

Operations

GScript supports common CNC operations:

  • face: Surface milling with configurable stepover
  • drill: Point drilling with peck cycles
  • pocket: 2D pocket milling with multiple strategies
  • contour: Profile cutting with lead-in/lead-out

Library System

Reusable definitions for:

  • Tool libraries (endmills, drills, face mills)
  • Material properties (aluminum, steel, wood)
  • Feed/speed tables
  • Machine configurations

Cost Estimation

Built-in cost calculator considers:

  • Machining time
  • Material usage
  • Tool wear
  • Machine hourly rates

Simulation

Validate programs before running:

  • Toolpath visualization
  • Collision detection
  • Material removal simulation
  • Cycle time estimation

Use Cases

GScript is ideal for:

  • Production Shops: Standardize CNC programming across machines
  • Prototyping: Quickly iterate on designs with readable code
  • Education: Teach CNC programming with clearer syntax
  • Multi-Machine Shops: Target different controllers from one codebase
  • Automation: Generate CNC programs programmatically

Next Steps

Philosophy

GScript is built on these principles:

  1. Safety First: Catch errors at compile time, not on the machine
  2. Readability: Code should be self-documenting
  3. Flexibility: Support different workflows and backends
  4. Performance: Generate efficient G-code
  5. Maintainability: Programs should be easy to modify and extend

Released under the Apache License 2.0