Machine.beginMpg()

[Motion86]

Description

Enable MPG mode, in this mode, the Machine can not do other motion control, only use the Encoder’s read back value and move the corresponding output axis according to the amount of change.

Syntax

machine.beginMpg(encoder);

Parameters

  • machine: is the Machine object.
  • encoder: is Encoder object.

Returns

None.

Example

Set the basic parameters of the machine and enable the MPG mode, which will link the X-axis when the Encoder value changes.

#include "Motion86.h"
#include "Encoder.h"
 
// Generate machine objects, up to machine 0~2 three machines, each machine has three axes. 
Machine machine(0);
 
// Stepper motor enable pin.
int EnablePin = 4;
 
void setup() {
 
  while (!Serial);
  // In this example, the hand crank has been installed on Enc3.
  Enc3.begin(MODE_AB_PHASE);
  pinMode(EnablePin, OUTPUT);
 
  // If necessary, the motion direction 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);
 
  // The machine must be started before control.
  machine.machineOn();
 
  // Trigger Mpg control with Enc3.
  machine.beginMpg(Enc3);
 
  // Select the target axis to be controlled by Mpg handwheel.
  machine.setMpgAxis(AXIS_X);
  // machine.setMpgAxis(AXIS_Y);
  // machine.setMpgAxis(AXIS_Z);
 
  // Feed speed in Mpg mode.
  machine.setMpgSpeed(600);
 
  // MpgRatio is the ratio of handwheel to machine travel distance, the parameter value should be greater than 0.
  machine.setMpgRatio(1);
 
  // Start the stepping motor.
  digitalWrite(EnablePin, LOW);
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);
}

See also


Libraries Reference Home

The text of the 86Duino reference is a modification of the Arduino reference and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.

Leave a Comment

Scroll to Top