setRelative()

Description

Plans motion with relative increment values.

Syntax

Machine machine(0); machine.setRelative();

Parameters

machine: Machine object.

Return

No return value.

Example

Draw a square using relative movement.

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

#include "Motion86.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;

 

void setup() {

  while (!Serial);

  pinMode(EnablePin, OUTPUT);

  // If necessary, the direction of the motion axis can be reversed.

  machine.config_ReverseDirection(AXIS_X);

  machine.config_ReverseDirection(AXIS_Y);

  // PPU (pulse per unit) is a virtual length unit, 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);

    // Before controlling, the machine must be started.

  machine.machineOn();

    // Set the default feed rate.

  machine.setDefaultFeedrate(600);

  // Start the stepper motor.

  digitalWrite(EnablePin, LOW);

    // Use relative increments to plan movement

    machine.setRelative();

    // Based on the current position, use relative increments to move to the center position.

  machine.line(0,0,10,400);

  machine.line(170,100,0,800);

  machine.line(0,0,-10,400);

}

 

void loop() {

    // Move to this relative position. No feed rate is set here, which means the preset value is used.

    machine.line(10,0,0);

    machine.line(0,10,0);

    machine.line(-10,0,0);

    machine.line(0,-10,0);

    // Wait until the planned motion is complete

    while (machine.isMoving());

}

See also

setAbsolute()


Library Reference

86Duino Reference Text Follows Creative Commons Attribution-Share Alike 3.0 License. The code examples in the references have been released into the public domain.