config_EGearSlave()

Describe

The axis following function of the electronic gear ratio can be set. After enabling this function, the target machine will move according to the electronic gear ratio and the coordinate axis.

 

Grammar

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

 

Parameter

machine: It is an object of Machine. .

target: It is an object Machine, and this target machine will move along the coordinate axis according to the electronic gear ratio. .

xRatio: The electronic gear ratio corresponding to the X-axis. .

yRatio: The electronic gear ratio corresponding to the Y axis. .

zRatio: The electronic gear ratio corresponding to the Z axis. .

 

Return

bool:

true: Both machines exist and were created successfully.

false: Any machine does not exist or failed to create.

 

Example

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

#include "Motion86.h"

#include "SD.h"

 

// Generate machine objects. You can use up to three machines, machine 0~2, each with three axes.

// This example uses machine 0 and machine 1。

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 axis can be reversed.

  // In this example, you need to reverse the direction of the x-axis and the y-axis.

  machine.config_ReverseDirection(AXIS_X);

  machine.config_ReverseDirection(AXIS_Y);

 

  // PPU (pulse per unit) is a virtual unit of length, depending on different needs.

  // In this example, the unit length of the x-axis is set to 80 pulses, which corresponds to 1 mm in actual application.

  machine.config_PPU(AXIS_X, 80.0);

  machine.config_PPU(AXIS_Y, 80.0);

  machine.config_PPU(AXIS_Z, 1600.0);

 

  // Set software limits for machine movement.

  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 by the limit switch to set the home point.

  machine.config_HomePins(2, 7, 8);

 

  // In this case the slave_machine needs to reverse the direction of the y-axis.

  slave_machine.config_ReverseDirection(AXIS_Y);

 

  // Set the PPU (pulse per unit) of 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);

 

  // Sets the software limits for slave_machine motion.

  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 the pin used by slave_machine to set the limit switch of the home point.

  slave_machine.config_HomePins(21, 22, 23);

 

  // Set slave_machine to EGearSlave of machine, which means slave_machine will calculate and follow the movement of machine.

  machine.config_EGearSlave(slave_machine, 1.5, 0.5, 1.0);

 

  // Before controlling, the machine must be started.

  machine.machineOn();

 

  // Activate software limits.

  machine.enableSoftLimit();

 

  // Sets the feed rate to the home point.

  machine.setHomeSpeed(1000, 1000, 200);

  slave_machine.setHomeSpeed(1000, 1000, 100);

 

  // Open the gcode file in the SD card

  if (SD.exists(filename)) {

    gfile = SD.open(filename);

    working = true;

  else {

    Serial.print("File not exists: ");

    Serial.println(filename);

    while (1);

  }

 

  // Start the stepper motor。

  digitalWrite(EnablePin, LOW);

 

  // Return to the home point defined by the limit switches.

  machine.home();

}

 

void loop() {

  // Read and parse gcode files.

  // slave_machine is a scaled gcode path, width x1.5, height 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;

    }

  }

}


Libraries

The text of the 86Duino reference follows the Creative Commons Attribution-ShareAlike 3.0 License. Code examples in reference materials have been published in the public domain.
86Duino cānkǎo zīliào de wénběn zūnxún zhīshì gòngxiǎng shǔmíng-x