#include "Motion86.h"
#include "Encoder.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);
// In this example, the hand wheel has been installed on Enc3.
Enc3.begin(MODE_AB_PHASE);
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);
// Before controlling, the machine must be started.
machine.machineOn();
// Use Enc3 to trigger Mpg control.
machine.beginMpg(Enc3);
// Select the target axis to be controlled by the Mpg handwheel.
machine.setMpgAxis(AXIS_X);
// machine.setMpgAxis(AXIS_Y);
// machine.setMpgAxis(AXIS_Z);
// Feed rate in Mpg mode.
machine.setMpgSpeed(600);
// MpgRatio refers to the ratio of the moving distance of the handwheel to the machine, and the parameter value should be greater than 0.
machine.setMpgRatio(1);
// Start the stepper motor.
digitalWrite(EnablePin, LOW);
}
void loop() {
Serial.print("Mpg position = ");
Serial.print(machine.getJogPos(AXIS_X));
Serial.print(", ");
Serial.print(machine.getJogPos(AXIS_Y));
Serial.print(", ");
Serial.println(machine.getJogPos(AXIS_Z));
delay(500);
}
|