1
3D Printer3D Printer
關鍵軟體控制技術關鍵軟體控制技術
之分析與探討之分析與探討
Hellion @ COSCUP
2014
2
莊竣傑 Hellion Chuang
視覺辨識
LinuxCNC
3D Printer
Open Source Projects:
https://github.com/roboard/Print3D
https://github.com/roboard/86Duino
https://code.google.com/p/rb050-little-turtle/
About me
R&D Engineer
DMP Electronics INC.
3
3D Printer3D Printer
4
RepRap
3D 立體印表
機
( replicating rapid prototyper )的縮
寫
它具有一定程度的自我複製能力,能 列印出大部分其自身的(塑料)組件夠
2005 年, RepRap 項目在英國巴斯大學由機械工程高級
講師 Adrian Bowyer 博士創建。
5
Sorce :http://zh.wikipedia.org/wiki/RepRap#mediaviewer/File:First_replication.jpg
RepRap
3D 立體印表
機
這原型機從軟體到硬體各種資料都是免費和開源的,都
在自由軟體協議 GNU 通用公共許可證 GPL 之下發布。
6
RepRap
Family Tree
7
8
RepRap
列印原理 : 熔融 積式沉 ( fused deposition
modeling , FDM )
http://www.uni.edu/~rao/rt/major_tech.htm
9
RepRap
WorkFlow
利用電腦 3D 建
模
轉換成 G Code 傳送到 3DP 控制
器
開始列印列印完成
10
RepRap
各軸 進馬達步
擠出頭
加熱板控制器
結構
11
3D Printer3D Printer 控制器控制器
接收 & 傳送資料
控制馬達的移動與進料
控制擠出頭與
加熱板的溫度
控制風扇,極限開關與其他外部感應器
What it do?
12
硬體
軟體 ??
13
Open Source 3D PrinterOpen Source 3D Printer 控制軟體控制軟體
• Sjfw (2012-1)
• Sprinter (2013-9)
• ImpPro3D (2014-2)
• Sailfish (2014-6)
• Aprinter (2014-6 )
• Teacup (2014-7)
• RepRap Firmware
(2014-7)
• Grbl (2014-7)
• Marlin (2014-7)
• Repetier-Firmware
(2014-7)
• Smoothie (2014-7)
Github 上最新 commit 的日期
14
Grbl
15
Sprinter
16
Marlin
17
V0.91 (2013 12 30)
Repetier-Firmware
18
Smoothie
19
關鍵技術
20
SD 卡
USB
UART
LAN
…
G Code
解譯
與運
動有
關
與溫度有關
其他
軌跡規劃
溫度控制
一些相關的設定
脈波命令
脈波輸出
3D Printer3D Printer 軟體架
構
Hard Realtime
Soft Realtime
50us1ms~10ms
16ms
10ms
21
解譯 軌跡規劃 溫度控制 脈波輸出
Real-Time Task Implementation
Solutions :
Multi-Processor
Multi-Threading
State Machine
22
23
G CodeG Code 解譯解譯
• 將 G Code 轉換成 3D Printer 的內部控制命令。
• EX :
– G01 X10 Y15.5 F2000
– M109 S180
(X10, Y15.5)X
Y
加熱到 180 度才執行下一行 G
Code
24
Solutions :
Just-in-time compilation
Lex & yacc?
25
G Code Interpretation on
Sprinter/Marlin:
G01 X10 Y15.5 F2000
EX :
G 的分
類
直線段
目標 X
10 mm
目標 Y
15.5 mm
速度 F
2000 mm/min
Planner_line(10, 15.5, z, 2000);
26
Source Code :
• 字串解析
• G Code, M Code, other…
– 軌跡規劃
– 溫度設定
– 系統參數的設定
– 等…
27
(X10, Y15.5)
X
Y
?
Planner_line(10, 15.5, z, 2000);
28
軌跡規劃軌跡規劃
運動學的計算
Normal X-Y
H-Bot
CoreXY
delta
29
Look Ahead
速度曲線 No Look Ahead
速度曲線
Look Ahead Buffer = 6
速度曲線 Look Ahead Buffer = 2
運動路徑
30
梯形曲線加減速控制
V V
T T
TV ∆×=∆Χ 2
32
2
1
2
1
2
1
TATVTA ∆+∆×+∆=∆Χ
∆T ∆T1 ∆T2 ∆T3
31
Source Code :

計算運動學

Look Ahead

梯形加減速
32
http://dedamail.pixnet.net/blog/post/9910986-%E9%A6%AC%E9%81%94%E7%95%B0%E6%83%B3
33
進馬達步
120o
走 3 圈又
120o
走 41 圈又
240o
離散
以左上步進馬達為例
34
運動軌跡
X
T
V
T∆T1 ∆T2 ∆T3
連續
35
離散連續
X
T
10
9
8
7
6
5
4
3
2
1
,...2,1,0)( ==∆ xxft
Precise
Discretization
脈波周期
36
v
t
1
=∆
X
T
近似誤差
Linear Approximation
Pulse Generation on Sprinter/Marlin
37
Implementation:
Pulse generation by Timer ISR
T1
T2
T3
T4
T5
T6
T7
T9
T8
T10
中斷間隔 = 脈波周期
!Hard Real-Time:
interrupt latency
+ jitter
+ pulse generation
+ I/O
= 50us
38
V
T∆T1 ∆T2 ∆T3
High & Low 由 GPIO 產
生
Implementation:
39
Source Code :

將 planner 的連續軌跡,轉化成 進馬步
達所需的離散脈波

利用 Timer ISR 來控制脈波的 度寬 ( 頻
率 )

用硬體的 GPIO 生產 High & Low
40
http://lunglungdesign.blogspot.tw/2013/05/mataerial-3d-printing.html
41
溫度控制溫度控制
加熱
AD 讀
取 度溫
AD 讀
取 度溫
加熱
42
利用熱敏電阻
讀取 度溫
目標 度溫
超過或低於
目標 度溫 ?
加大電流,
達到加熱的效果
減少電流,
達到冷卻的效果
ON
YES
度控制溫
43
利用熱敏電阻
讀取 度溫
目標 度溫
超過或低於
目標 度溫 ?
加大電流,
達到加熱的效果
減少電流,
達到冷卻的效果
ON
YES
控制周期 16ms
44
實現的方式
∫ ++=
t
dip te
dt
d
KdeKteKtu
0
)()()()( ττ
45
Source Code :

利用熱敏電阻 or 熱電偶,取得目前 度溫

用 PWM 控制電流以達到目標 度溫

PID
46
https://www.youtube.com/playlist?
list=PLFL0ylDooClTaryk1IPAvDsqsFQ85-
Rd1
47
48
目前 3D printer 的控制板
Generation 7
Melzi
PiBot for
Repetier
MotherboardArduino
Mega Pololu
Shield
Sanguinololu
ATmega-Based
Clock : 8MHz ~ 16MHz
SRAM : 32KB
Flash : 128KB~256KB
49
Why not 32-Bit platform ?
Beaglebone
Raspberry Pi
Cubieboard
Intel Galileo
86Duino
ARM11, ARM Cortex-Ax, x86…
Clock : 300MHz ~ 1GHz
DRAM : 512MB~1GB
Storage : eMMC, SD Card
50
進階機型的性能需求
51
有一天,
hellion 做了一個夢……
從 programmer 的角度來看…
52
最近 3D printer
市場很
夯, hellion 我們
也做一台來插花,
如何 ?
53
RepRap
RepRap
…
有很多
Open
Source 的
3D Printer
可以參考
54
做出來怎麼跟別
人的都長一樣,
那我們怎麼會有
競爭力 ?我要軟體速度快一
點,功能強一點,
列印品質好一點… .
反正要比市面上的
都好,你快去改善
但是成本不
能增加 !
55
現有
firmware 已
經快把
ATmega 榨
乾了,很難
改的動…
我們換一個性能
更好,限制更少
,更容易擴展的
開發平台吧 !
56
現有的 32-Bit 3D Printer
controller
R2C2
ARM Cortex-M3
Running at 100MHz
512KB flash memory
64KB SRAM memory
R2C2 firmware
57
現有的 32-Bit 3D Printer
controller
Azteeg X5
ARM Cortex-M3
Running at 120MHz
Smoothieware firmware
58
現有的 32-Bit 3D Printer
controller
Smoothieboard
ARM Cortex-M3
Running at 96 to 120 MHz
512KB flash memory
64KB SRAM memory
Smoothieware firmware
Still MCU-baesd
solutions…
59
現有的 32-Bit 3D Printer
controller
86Duino Print3D
Vortex86EX 32-Bit x86
Running at 400MHz
128MB DDR3
RS232/
RS485/CAN
LAN
USB
USB
Host
X MOTOR
Z MOTOR Y MOTOR
E MOTOR
E HEATER
E THERM
X LIMIT Y LIMIT
Z LIMIT
60
Before
After
61
可用 32-Bit platform 改善的一些 issues
Internal
Buffer size ↑
4 x 96 Bytes 20MB
→
Before After
穩定性增加
解譯 軌跡規劃 脈波輸出BufferBufferBuffer
62
程式的可讀性 
intRes = intIn1 * intIn2 >> 16
可用 32-Bit platform 改善的一些 issues
Before
After
63
更細緻平滑的運動路徑生成
可用 32-Bit platform 改善的一些 issues
Before After
64
Look Ahead Window ↑ 速度控制更平順
可用 32-Bit platform 改善的一些 issues
Before After
65
linear approximation → precise discretization
v
t
1
=∆
a
XaVaXV
t
)1(22 2
0
2
0 −+−+
=∆
可用 32-Bit platform 改善的一些 issues
Before After
66
Higher Speed Pulse Generation
20KHz 250KHz
可用 32-Bit platform 改善的一些 issues
Before After
67
移植的注意事項
Speed trick
68
移植的注意事項
OS 的選擇
69
移植的注意事項
Hard Real-Time Task
70
Thank Yourobotics@dmp.com.tw
https://github.com/roboard/Print3D

3D Printer 關鍵軟體控制技術之分析與探討 @ COSCUP 2014

Editor's Notes

  • #3 研究過Linuxcnc, 因為同是繞跑,臨時接收3D print的軟體開發。
  • #8 由RepRap衍生出來的機型