3dSynth

Tutorials / Custom G-code

Open in the interactive tutorials reader

---
title: Tutorial 45 Multi-axis & 5-axis G-code Concepts
description: Moving beyond XYZ.
---

Tutorial 45 Multi-axis & 5-axis G-code Concepts

1. Lesson Header

2. Concept Introduction

Degrees of Freedom.
Standard printers have 3 DOF (X, Y, Z).
5-Axis Machines add rotation:
- A Axis: Rotation around X.
- B Axis: Rotation around Y.
- C Axis: Rotation around Z.

This allows the nozzle to approach the part from any angle, eliminating the need for support material.

3. Machine State Explanation

Rotary Coordinates.
Move X to 100, while rotating A to 90 degrees.
G1 X100 A90 F3000.
The feedrate F is tricky. Is it mm/min or deg/min?
Usually, the controller handles the kinematics to keep the tip speed constant.

4. Command Breakdown

5. Minimal Working Example

The Tube Print (4-Axis).
Instead of moving Y, we rotate the object (A).
Y becomes A.
Circumference = PI * Diameter.
A_steps = 360 * (Y_mm / Circumference).

6. Visual Representation

Interactive preview is available in the interactive reader.

7. Build Exercise

Task: Write a Python script to wrap a text string ("HELLO") around a cylinder.
1. Generate G-code for flat text (X, Y).
2. Map Y to A (Degrees).
A = (Y / Circumference) * 360.
3. Output G1 X... A....

Assumption: You have a rotary axis connected to the E-motor driver or a dedicated A-axis driver.

8. Deep Insight Section

Singularities.
In 5-axis machining, there are points where the machine can't move smoothly (Gimbal Lock).
The planner must avoid these or move through them very quickly.
RTCP (Rotation Tool Center Point):
High-end controllers (LinuxCNC) adjust X/Y/Z automatically as you rotate A/B to keep the nozzle tip in the same place.
Without RTCP, you must calculate the exact X/Y/Z offset for every degree of rotation.

9. Common Failure Modes

  1. Collision: Rotating the bed might hit the gantry.
  2. Cable Winding: Infinite rotation (A10000) twists cables until they snap. Use slip rings or unwind logic.

10. Real-World Application

Turbine Blades.
Printing complex overhangs without support by tilting the part.
Or "Conformal Printing" on a curved surface (like printing circuits on a helmet).

11. Final Clean Version

The Wrapper Script:

import math

filename = "rotary_text.gcode"
diameter = 50
circumference = math.pi * diameter

# Flat G-code (Simplified list of points)
flat_path = [(0,0), (10,0), (10,10), (0,10), (0,0)] # A box

with open(filename, "w") as f:
    f.write("G28\nG1 Z10\n")
    
    for p in flat_path:
        x, y = p
        # Map Y to A
        a = (y / circumference) * 360
        
        f.write(f"G1 X{x:.3f} A{a:.3f} F1000\n")

    f.write("G28 X0\n")

12. Stretch Challenge

Challenge: Implement 5-Axis Slicing (Conceptual).
Take a normal slice (Planar).
Tilt the nozzle 45 degrees to avoid the previous layer (Non-planar).
Calculate the B angle required.
B = 45.
X_new = X + Tool_Length * sin(B).
Z_new = Z - Tool_Length * (1 - cos(B)).
Output G1 X{X_new} Z{Z_new} B45.