getFeedrateOverride()

Describe

Obtain feed rate overwrite ratio.

 

Grammar

machine.getFeedrateOverride();

 

Parameter

machine: It is an object of Machine. .

No parameters.

 

Return

double:

Feed rate overwrite ratio

 

Example

When the machine performs G-code movement, the feedrate is dynamically adjusted according to the Encoder.

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

111

112

113

114

115

116

117

118

119

120

121

#include "Motion86.h"

#include "Encoder.h"

#include "SD.h"

 

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

Machine machine(0);

 

// 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;

 

// Set the preset feed rate ratio.

volatile double FeedrateRatio = 1.0;

 

bool enc_triggered = false;

 

void encoder_callback(int flag);

 

void setup() {

  while (!Serial);

  SD.begin();

 

  // In this example, the hand wheel has been installed on Enc3.

  Enc3.begin(MODE_AB_PHASE);

  Enc3.setRange(1); // The interrupt will be triggered every time

  Enc3.attachInterrupt(encoder_callback);

 

  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);

 

  // 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);

 

  // 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.

  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;

    }

  }

 

  // Override feed rate when interrupt occurs。

  if (enc_triggered) {

    if (FeedrateRatio > 2.0) FeedrateRatio = 2.0;

    if (FeedrateRatio < 0.1) FeedrateRatio = 0.1;

    machine.feedrateOverride(FeedrateRatio);

    enc_triggered = false;

    Serial.print("FeedrateRatio = ");

    Serial.println(machine.getFeedrateOverride());

  }

}

 

void encoder_callback(int flag) {

  // The feed rate ratio should be greater than 0.

  if (flag == INTR_OVERFLOW && FeedrateRatio < 2.0)

    FeedrateRatio += 0.01;

  else if (flag == INTR_UNDERFLOW && FeedrateRatio > 0.0)

    FeedrateRatio -= 0.01;

  enc_triggered = true;

}

See also

feedrateOverride()


 

Library reference

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.