Machine.config_EGearSlave()

[Motion86]

説明

The axis following function with electronic gear ratio can be set. After this function is enabled, the target machine will follow the movement of the coordinate axis according to the electronic gear ratio.

Syntax

machine.config_EGearSlave(target, xRatio, yRatio, zRatio);

Parameters

  • machine: is the Machine object.
  • target: For the Machine object, this target machine will follow the motion of the coordinate axis according to the electronic gear ratio.
  • xRatio: The electronic gear ratio corresponding to the X-axis.
  • yRatio: The gear ratio of Y-axis.
  • zRatio: The electronic gear ratio corresponding to the Z-axis.

Returns

bool:

  • true: Both machines exist and were created successfully.
  • false: Any machine does not exist or failed to be created.

Example

The slave_machine will follow the G-code movement of the machine according to the electronic gear ratio (1.5, 0.5, 1.0).

#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;
    }
  }
}

Libraries Reference Home

86Duino のリファレンスのテキストは Arduino レファレンス を編集したもので、 Creative Commons Attribution-ShareAlike 3.0 License下でライセンスされています。リファレンス内のコードサンプルはパブリックドメインとして公開されています。

コメントする

上部へスクロール