config_EGearSlave()
描述
可設定電子齒輪比的軸跟隨功能,啟用此功能後目標機器將會依照電子齒輪比跟隨坐標軸運動。
語法
machine.config_EGearSlave(target, xRatio, yRatio, zRatio);
參數
machine:為 Machine物件。
target:為 Machine物件,此目標機器將會依照電子齒輪比跟隨坐標軸運動。
xRatio:對應 X 軸之電子齒輪比。
yRatio:對應 Y 軸之電子齒輪比。
zRatio:對應 Z 軸之電子齒輪比。
回傳
bool:
true: 兩台機器皆存在且創建成功。
false: 任意機器不存在或創建失敗。
範例
slave_machine 將會依照電子齒輪比 (1.5, 0.5, 1.0) 跟隨 machine 進行 G-code 運動。
#include "Motion86.h"
#include "SD.h"
// 產生機器物件,最多可使用 machine 0~2 三台機器,每台機器三軸。
// 此例中使用 machine 0 與 machine 1。
Machine machine(0);
Machine slave_machine(1);
// 步進馬達 enable pin。
int EnablePin = 4;
// 此 gcode 檔案存放於 SD 卡中。
char *filename = "auto.gcode";
File gfile;
char buf[256];
int ptr;
bool working;
void setup() {
while (!Serial);
pinMode(EnablePin, OUTPUT);
// 若有需要,可以反轉運動軸的運動方向。
// 在此範例中,需要反轉 x 軸和 y 軸的方向。
machine.config_ReverseDirection(AXIS_X);
machine.config_ReverseDirection(AXIS_Y);
// PPU (pulse per unit) 是一虛擬長度單位,依照不同需求而定。
// 此例 x 軸的單位長度設定為 80 pulses,對應到實際應用為 1 mm。
machine.config_PPU(AXIS_X, 80.0);
machine.config_PPU(AXIS_Y, 80.0);
machine.config_PPU(AXIS_Z, 1600.0);
// 設定機器運動的軟體極限。
machine.config_PosLimit(AXIS_X, 0, 300);
machine.config_PosLimit(AXIS_Y, 0, 200);
machine.config_PosLimit(AXIS_Z, 0, 300);
// 設定用來設定 home 點的極限開關所使用的 pin 腳。
machine.config_HomePins(2, 7, 8);
// 此例中 slave_machine 需要反轉 y 軸的方向。
slave_machine.config_ReverseDirection(AXIS_Y);
// 設定 slave_machine 的 PPU (pulse per unit)。
slave_machine.config_PPU(AXIS_X, 80.0);
slave_machine.config_PPU(AXIS_Y, 80.0);
slave_machine.config_PPU(AXIS_Z, 3200.0);
// 設定 slave_machine 運動的軟體極限。
slave_machine.config_PosLimit(AXIS_X, 0, 200);
slave_machine.config_PosLimit(AXIS_Y, 0, 200);
slave_machine.config_PosLimit(AXIS_Z, 0, 300);
// 設定 slave_machine 用來設定 home 點的極限開關所使用的 pin 腳。
slave_machine.config_HomePins(21, 22, 23);
// 設定 slave_machine 到 machine 的 EGearSlave,這代表 slave_machine 會計算並跟隨 machine 的運動。
machine.config_EGearSlave(slave_machine, 1.5, 0.5, 1.0);
// 控制之前,必須啟動機器。
machine.machineOn();
// 啟動軟體極限。
machine.enableSoftLimit();
// 設定回到 home 點的進給速率。
machine.setHomeSpeed(1000, 1000, 200);
slave_machine.setHomeSpeed(1000, 1000, 100);
// 開啟 SD 卡中的 gcode 檔案
if (SD.exists(filename)) {
gfile = SD.open(filename);
working = true;
} else {
Serial.print("File not exists: ");
Serial.println(filename);
while (1);
}
// 啟動步進馬達。
digitalWrite(EnablePin, LOW);
// 回到由極限開關所定義的 home 點。
machine.home();
}
void loop() {
// 讀取並解析 gcode 檔案。
// slave_machine 為縮放 gcode 路徑,寬x1.5、高x0.5。
if (working && !machine.isCmdBufferFull()) {
ptr = 0;
while (gfile.available()) {
buf[ptr] = gfile.read();
if (buf[ptr] == '\n') {
buf[ptr + 1] = '\0';
machine.gcode(buf);
break;
} else {
ptr ++;
}
}
if (!gfile.available())
{
Serial.println("GCODE FINISH");
gfile.close();
working = false;
}
}
}
The text of the 86Duino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.
