Skip to content

tomohiron907/G-coordinator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

G-coordinator



日本語バージョンは,このページの下に載せています.

What is G-coordinator?

To use a 3D printer, basically, you need to prepare a 3D model and then slice it using slicing software to create G-code, which is then loaded into the printer. The G-coordinator developed this time is an open-source software in Python specifically designed for directly creating G-code. You can find it at the following URL: https://github.com/tomohiron907/G-coordinator.

Additionally, there is a Python library called "gcoordinator" that extracts the internal G-code generation engine of G-coordinator. (URL: https://github.com/tomohiron907/gcoordinator)

Using this Python library, you can generate G-code directly from Python scripts without installing the GUI. The G-code generation engine inside the G-coordinator app also uses this Python library.

gif_img1 By directly creating G-code, it becomes possible to easily produce shapes and structures that were previously difficult to achieve using traditional methods of creating 3D models. For example, it allows for the realization of intricate knitting patterns like the one shown below.



By writing Python scripts in the left editor and executing them, you can display the nozzle path of the 3D printer and preview the fabrication process. Additionally, you can adjust various printing settings on the right side of the screen and output the G-code.

Requirements

G-coordinator currently supports macOS and Windows. Additionally, you can launch it by directly executing the Python file. In that case, you can install the required libraries in bulk using the following command:

pip install -r requirements.txt

Please make sure you have Python and pip installed on your system before running the command.
When launching G-coordinator as an executable file like .app or .exe, you do not need to install the libraries separately. However, if you plan to examine the outputted G-code, it would be convenient to have software like Prusa Slicer or Repetier available. These software tools can help you visualize and analyze the G-code generated by G-coordinator.

G-coordinator installation procedure

Please download the software from here according to your operating system.

If you have a Python environment set up, please create a clone of this GitHub repository and set the current directory to "src." Then, execute the "main.py" file. The necessary INI configuration file for execution is also included in the "src" directory.

Furthermore, I have uploaded a video on YouTube that summarizes the installation process. You can watch it at the following link: https://www.youtube.com/watch?v=LqZGno-BWG0.

How G-code works

It is useful to have at least a basic understanding of the structure of G-code before engaging in fabrication. The photo below depicts an example of G-code opened in Repetier: img5

G1 F800 X114.97987 Y105.63424 Z2.00000 E0.00589

This is a command that is repeated multiple times in the G-code. It instructs the machine to move from its current position to the specified position of X114.97987, Y105.63424, and Z2.00000, while extruding filament at a rate of 0.00589mm per step, with a feedrate of 800mm per minute. This command is commonly used for controlled movements and filament extrusion during 3D printing or CNC machining processes.

In other words, when it comes down to it, there are five main elements that should be controlled using G-code: the three coordinates (x, y, z), speed, and extrusion amount. Additionally, the speed and extrusion can be automatically determined by the G-coordinator (though it is also possible to specify them individually). Therefore, the only thing you need to consider is the coordinate of the nozzle's movement, i.e., where the nozzle should move to.

Test modeling (cylinder)

Alright, let's start creating the model using G-coordinator. First, as the simplest model, we will create the walls of a cylinder. Inside the downloaded folder from GitHub, you will find a folder called "Example." Click on the "Open File" button at the top left and open the 'default_cylinder.py' file located inside the 'Example' folder.

The code will be displayed in the editor on the left, and when you press the reload button, it will look like the picture below.

img6

In G-coordinator, the modeling process takes place within the function called object_modeling(). As mentioned earlier, what we ultimately want is a list of coordinates. Therefore, we are creating a list that includes the coordinates of the points that the tool should pass through.

import math
import numpy as np
import gcoordinator as gc

LAYER = 100

full_object=[]
for height in range(LAYER):
    arg = np.linspace(0, 2*np.pi, 100)
    x = 10 * np.cos(arg)
    y = 10 * np.sin(arg)
    z = np.full_like(arg, (height+1) * 0.2)
    wall = gc.Path(x, y, z)
    full_object.append(wall)

gc.gui_export(full_object)

In G-coordinator, the modeling process involves using objects of the Path class. This refers to the path along which the nozzle continuously extrudes resin. In the case of the cylindrical example mentioned earlier, the nozzle follows a circular path within a certain layer while continuously extruding resin. Therefore, the path of a single circle is represented by an object called "path."

img7

Let's break down what the function is doing. First, it iterates through each layer using a for loop. Since the current layer count is 100, it will iterate from layer 0 to layer 99.

Next, to draw a circle, the function sets up an angle (argument) using a numpy array ranging from 0 to 2π. With an array size of 100, it will precisely form a regular 99-sided polygon. Assuming a fixed radius of 10, the x-coordinate can be calculated as radius * cos(argument), and the y-coordinate as radius * sin(argument). As for the z-coordinate in the vertical direction, it initializes an array with the same size as argument and assigns values based on the height variable. Adding 0.2 ensures that even if the height starts from 0, the first layer will be printed at a height of 0.2.


layer = gc.Path(x,y,z)

Furthermore, in the code, the endpoint of the path in the nth layer and the starting point of the path in the n+1st layer are automatically connected, allowing for smooth travel between layers.

For each layer, the function appends the path to the full_object list and sets full_object as the return value.

Printing settings

Once modeling is complete, prepare the G-code.

At the current stage, the available printing settings are limited to the essential parameters. As the names suggest, nozzle_diameter refers to the diameter of the nozzle, and layer_height corresponds to the height of each layer.

If you click on the "Machine Settings" button at the top, a window will appear where you can adjust the hardware settings of the 3D printer.

In this section, you have the option to select the kinematics for your 3D printer. Generally, for most printers, you would choose the "Cartesian" option, which supports the three axes (x, y, z).

However, there are additional options available to support specific types of 3D printers:

  1. "Nozzle Tilt": This option is for printers that have a robotic arm or a hexapod-like structure and require G-code specifically designed for these types of printers.

  2. "Bed Tilt": This option is for printers with a bed that can tilt, similar to a machining center.

  3. "Bed Rotate": This option is for printers with a rotating bed.

These options cater to printers with specialized kinematics beyond the standard Cartesian configuration.

One important thing to note is the "Origin" setting. In most standard 3D printers, the origin is set at the front-left corner of the bed. However, in G-coordinator, the origin is set at the center of the bed to simplify the mathematical expressions used in modeling.
For example, if your printer bed is 210mm x 210mm in size, the origin is set at the center, which is 105mm in both the X and Y directions.
In G-coordinator, coordinates entered as (10, -20) would be converted and recorded as (115, 85) in the actual G-code, considering the shifted origin.

Another setting available is the "Speed" option. The default value represents the print speed when no specific speed is set. However, if you specify the speed in detail within the editor, that value will take precedence.

The same applies to the "Extrusion Multiplier" option. If you define a specific value within the editor, it will override the default setting.

In the "Travel Option" section, you can configure options for retraction and Z-hop during travel movements.

The "Extrusion Multiplier" setting allows you to determine a coefficient to scale the extrusion amount (E value).

Export G-code

When ready, press the Gcode Export button.

In this window, only the first 1000 lines of the generated G-code are displayed. However, when you click the "Save" button, the entire G-code will be saved.

When saving the G-code, make sure to enter the name with the extension. The format should be "{name}.gcode" for proper file saving.


Lastly

Using G-coordinator requires a combination of coding, mathematics, and an interest in 3D printing. Given that this combination may not be common among individuals, it can be challenging for people to start creating designs from scratch. As a result, the user base for G-coordinator may be limited.

To foster community engagement and encourage more users, it would be beneficial for individuals to actively tweet about their experiences using G-coordinator and share their creations or modifications under the hashtag #Gcoordinator (without a hyphen). This can help in promoting community interaction and participation.

Works






G-coordinatorとは?

3Dプリンタを使用するためには,基本的には3Dモデルを用意し,それをスライスソフトにかけてG-codeを作成してプリンタに読み込ませる必要があります.今回開発したG-coordinatorはpythonで直接G-codeを作成するためのオープンソースフトウェアです.(URL:https://github.com/tomohiron907/G-coordinator)

また,内部のG-code生成エンジンを切り出したgcoordinatorというライブラリもあります.(URL:https://github.com/tomohiron907/gcoordinator)

このpythonライブラリをしようすると,GUIをインストールすることなく,pythonスクリプトからG-codeを生成することができます.このG-coordinatorのアプリも,内部のG-code生成エンジンはgcoordinatorを使用しています.

gif_img1


直接G-codeを作成することにより,従来の3Dモデルを作成する方法では実現が困難であった形状や造形を,容易に作り出すことができます.例えば,下のような編み形状を実現できます.


RhinocerosのGrasshopperではビジュアルプログラミングにて同様のことは可能ですが,G-coordinatorではそれをpythonで実現します.
左側のエディタにpythonスクリプトを描き,それを実行することにより,3Dプリンタのノズルパスが表示され造形のプレビューが確認できます.また,画面の左側で各種印刷設定を調整し,G-codeを出力することができます.

必要事項

G-coordinatorは現在,macOSとWindowsに対応しています. また,pythonファイルを直接実行することでも起動できます. その場合には,以下のコマンドでライブラリを一括インストールできます.

pip install -r requirements.txt

.appや.exeなどの実行ファイルとしてG-coordinatorを起動した場合にはライブラリのインストールは必要ありません. 出力されたG-codeを確認するために,Prusa slicerやReptierなどのソフトがあれば便利です.

G-coordinatorのインストール

ここから,お使いのOSにあったものをダウンロードしてください.

python環境が整っている場合には,このgithubリポジトリのクローンを作成し,カレントディレクトリをsrcにして,main.pyを実行してください.実行に必要なini設定ファイルもsrcの中に入っているからです.

また,インストール手順をまとめた動画もyoutube にアップしています. https://www.youtube.com/watch?v=LqZGno-BWG0

G-codeの仕組み

造形の前に,G-codeの構造を簡単にでも把握しておくことは,今後,造形を行う上でも有用です.下の写真は,repetierでG-codeを開いたものです

img5


基本的には, G1 F800 X114.97987 Y105.63424 Z2.00000 E0.00589 こういった行が大量に繰り返されています. これは,現在の位置からX114.97987 Y105.63424 Z2.00000の位置まで,分速800mmで移動しながら,フィラメントを0.00589mm押し出すという命令です.

つまり,突き詰めれば,G-codeで制御すべき要素は,座標(x, y, z)の三要素とスピード,押し出し量の計5つです.さらに,スピードと,押し出しはG-coordinator から自動で決定できる(もちろん細かく個別に指定することも可能)なので,考えるべきは,どの位置にノズルが動くかという座標のみで良いです.

テスト造形(円柱)

では,いよいよ,G-coordinatorで造形をしていきましょう.まずは,最も簡単なモデルとして,円柱の壁を作ります. githubからダウンロードしたフォルダの中に,Exampleというフォルダがあります.左上のopen fileを押してexampleの中の’default_cylinder.py'を開いてください.

左のエディタにコードが表示され,reloadボタンを押すと,以下の写真のようになります.

img6


G-coordinator では,object_modeling()という関数の中でモデリングを行います.先ほど述べた通り,最終的に欲しいものは,座標のリストです.なので,通るべき点の座標を含んだlistを作成しています.


import math
import numpy as np
import gcoordinator as gc

LAYER = 100

full_object=[]
for height in range(LAYER):
    arg = np.linspace(0, 2*np.pi, 100)
    x = 10 * np.cos(arg)
    y = 10 * np.sin(arg)
    z = np.full_like(arg, (height+1) * 0.2)
    wall = gc.Path(x, y, z)
    full_object.append(wall)

gc.gui_export(full_object)

G-coordinatorの中では,Pathクラスのオブジェクトをモデリングに使用します。 これは,ノズルが樹脂を絶え間なく出し続ける経路のことを指しています。つまり,上の円柱の例では,ノズルは,ある層において,樹脂を出し続けながら,円を描くので一つの円の経路がpathというオブジェクトです.


img7


関数内で何をしているかについてです. まず,for文で各レイヤーについて繰り返しをしています.現在のレイヤー数は100なので,0層目から99層目まで繰り返されるイメージです.
次に,円を描くために,角度(argument)をnumpy arrayで0から2πの範囲で設定しています.要素数は100としているため,正確には,正99角形が造形されます. 半径は10で固定すると, x座標は,

半径×cos(arg) y座標は, 半径×sin(arg) より計算できます. 高さ方向のz座標に関しては,argと同じ要素数のarrayをheightに応じて値を初期化しています.0.2を足しているのは,heightが0から始まっても,第一層目は高さ0.2の場所に印刷して欲しいからです.

layer = gc.Path(x,y,z)


なお,n段目のPathの終点とn+1段目のPathの始点とは,自動でトラベルするようになっています. そして,各レイヤーごとに,full_objectのlist にPathを追加し,full_objectを返り値として設定しています.

印刷設定

造形が完了すれば,G-codeの準備をします.

現段階では,そこまで,複雑な印刷設定ができないです.最低限の設定項目のみです. 読んで字のごとくですが,nozzle_daimeterはノズル径,layer_heightはレイヤーの高さです.

一番上のmachine settingsのボタンを押すと,3Dプリンタのハードウェア設定のウィンドウが出てきます.


ここでは,kinematicsを選択することが可能です.一般的には3軸x, y, zのCartesianの項目を選択してください.ここでは,他に,

  • ロボットアーム型やHexaといった3Dプリンタ用のGcodeをサポートするために,Nozzle Tilt
  • マシニングセンタのようなベッドが傾く3Dプリンタ用にBed Tilt
  • ベッドが回転する3Dプリンタに用にBed Rotate

がサポートされています。


少し注意の必要なのは,Origin の項目です.一般の3Dプリンタでは,原点をベッドの左手前に設定していますが,G-coordinatorでは,造形の数式を簡単に書くために,原点をベッドの中央に設定しています. 自分の今使用している3Dプリンタのベッドが210mm×210mmなので,その中心の105mm を原点と設定しています.
G-coordinator上で(10,-20)の座標が,G-code上では(115, 85)に変換されて記録されるイメージです.
他には,スピードの項目も設けています.ここでのプリントスピードは,何も設定しなかった場合のデフォルト値であり,エディタで細かくスピードを指定した場合には,そちらが優先されます.これは,一番下の項目のExtrusion_multiplierでも同様です.
travel_optionでは,リトラクションの有無とzホップの設定が可能です.
extrusion_multiplier では,押し出し量(E値)に掛ける係数を決定できます.

G-codeの出力

準備が整ったら,Export Gcodeボタンを押してください

このウィンドウでは,G-code作成したG-codeの最初の1000行だけが表示されています。もちろん,保存ボタンを押して保存されるのはG-code全体です.また,Gーcodeを保存するときに,名前は,{名前}.gcodeと、拡張子まで入力する必要があります。


最後に

G-coodinatorを使うにあたり,造形のためのコードや数学と3Dプリンタの両方に興味のある人が少ないこともあり,なかなか自分で1から造形をおこなうのは難しく,ユーザも限られてしまいます.そこで,G-coordinatorで造形をおこなったり,改造して印刷をおこなったりしたものを積極的に #Gcoordinator(ハイフンなしに注意)でツイートしてもらえると,よりコミュニティの活性化につながると思っています.

作品