Machine.config_EGearSlave()

[Motion86]

描述

可設定電子齒輪比的軸跟隨功能,啟用此功能後目標機器將會依照電子齒輪比跟隨坐標軸運動。

語法

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"
 
// Generate machine objects, up to three machines from machine 0 to 2, each machine has three axes. 
// In this example, machine 0 and machine 1 are used.
Machine machine(0);
Machine slave_machine(1);
 
// Stepper motor enable pin.
int EnablePin = 4;
 
// This gcode file is stored in the SD card.
char *filename = "auto.gcode";
File gfile;
char buf[256];
int ptr;
bool working;
 
void setup() {
  while (!Serial);
  pinMode(EnablePin, OUTPUT);
 
  // If necessary, the direction of motion of the motion axis can be reversed.
  // In this example, the direction of x-axis and y-axis should be reversed.
  machine.config_ReverseDirection(AXIS_X);
  machine.config_ReverseDirection(AXIS_Y);
 
  // PPU (pulse per unit) is a virtual length unit, depending on different requirements.
  // In this example, the unit length of x-axis is set to 80 pulses, which corresponds to 1 mm in real application.
  machine.config_PPU(AXIS_X, 80.0);
  machine.config_PPU(AXIS_Y, 80.0);
  machine.config_PPU(AXIS_Z, 1600.0);
 
  // Set the software limit for the machine motion.
  machine.config_PosLimit(AXIS_X, 0, 300);
  machine.config_PosLimit(AXIS_Y, 0, 200);
  machine.config_PosLimit(AXIS_Z, 0, 300);
 
  // Set the pin used to set the limit switch for the home point.
  machine.config_HomePins(2, 7, 8);
 
  // In this example, slave_machine needs to reverse the direction of y-axis.
  slave_machine.config_ReverseDirection(AXIS_Y);
 
  // Set the PPU (pulse per unit) of the slave_machine.
  slave_machine.config_PPU(AXIS_X, 80.0);
  slave_machine.config_PPU(AXIS_Y, 80.0);
  slave_machine.config_PPU(AXIS_Z, 3200.0);
 
  // Set the software limit of slave_machine movement.
  slave_machine.config_PosLimit(AXIS_X, 0, 200);
  slave_machine.config_PosLimit(AXIS_Y, 0, 200);
  slave_machine.config_PosLimit(AXIS_Z, 0, 300);
 
  // Set slave_machine to set the pin used for limit switch of home point.
  slave_machine.config_HomePins(21, 22, 23);
 
  // Set the slave_machine to the machine's EGearSlave, which means that the slave_machine will calculate and follow the machine's motion.
  machine.config_EGearSlave(slave_machine, 1.5, 0.5, 1.0);
 
  // Before controlling, the machine must be started.
  machine.machineOn();
 
  // Enable the software limit.
  machine.enableSoftLimit();
 
  // Set the feed rate back to the home point.
  machine.setHomeSpeed(1000, 1000, 200);
  slave_machine.setHomeSpeed(1000, 1000, 100);
 
  // Open the gcode file in SD card
  if (SD.exists(filename)) {
    gfile = SD.open(filename);
    working = true;
  } else {
    Serial.print("File does not exist: ");
    Serial.println(filename);
    while (1);
  }
 
  // Start the stepper motor.
  digitalWrite(EnablePin, LOW);
 
  // Return to the home point defined by the limit switch.
  machine.home();
home(); }
 
void loop() {
  // Read and parse the gcode file.
  // slave_machine is a scaled gcode path, width x 1.5, height x 0.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;
    }
  }
}

函式庫參考主頁面

86Duino 參考的文本是根據 知識共享署名-相同方式分享 3.0 許可證,部分文本是從 Arduino 參考 修改的。 參考中的代碼示例已發佈到公共領域。

返回頂端