Mach3 Automation


Author: Dave
Date: 02.13.16 - 12:39am



So the project I am working on is a mix between a traditional CNC machine and an Arduino project. The short story is I want to record and train paths with rotary encoders and then replay the paths with steppers. You can read more in a seperate blog post here.

Especially for testing and calibration of the two systems I want a quick and easy way to move the steppers while taking readings from the arduino using X/Y coordinate conversions. I know I can control the steppers from Arduino, but I didnt have 2 stepper boards on hand, nor did I want to work out all the GCode details and positioning stuff. I figured I would look for a cheap shot solution.

To replay the full tool paths, I will generate a gcode file from the encoder positions and then run it in Mach3. I already have a license for it, and already had a $50 3 axis sain smart driver board for it, power supply, and old laptop with a parallel port.

I went to setup mach and got looking around the site, it turns out Mach supports a plugin model. I never knew this! You can write traditional plugins that it loads in process using C++ which could be a bit hairy, but it turns out Mach is also an ActiveX exe server and can be automated from external applications very easily !

You can find the VB6 Mach3 Automation Sample here.

This is perfect for this project, especially since I still use VB6 which is a master of simple COM integration. Controlling the steppers to goto a specific X/Y position will literally be a single line of code for me now without having to worry about any of the details.

mach.RunGCode("G0 X2 Y3.5")

Its also worth mentioning that Mach exposed its entire internal macro scripting language interface in this manner. Its very robust and you have access to basically everything. Its pretty awesome and will make for some interesting projects I am sure.

So here is some thoughts for a hybrid test machine:
  • arduino reads encoder output and seds them to serial
  • vb6 app reads position and converts them to X/Y coordinates
  • vb6 app records the positions in a list
  • replay mode, power steppers and click a button in vb6
  • mach is commanded to move to this position for calibration tests
  • coordinates can be adjusted in bulk on the fly if off
  • click vb button to cycle through the list one by one
  • additional I can use the serial link to also control a hobby servo for Z movement to put marker down and mark spots or draw lines
I know its a technology mash up, maybe even sloppy, definitely not for purists, but for a testing app and a minimal effort throw together its pretty elegant. Handing off the complex stuff to a specialized system designed for it and being able to control it with an extremely simple interface.

Certain things such as drawing out test patterns, planing a table flat, or marking grid lines on your table can also be represented easily with a programming interface. These should be much more readable as VB6 or Javascript code than having to generate a GCODE file. Mach does already support its own internal VBA script language though so maybe no need to do externally.

In Javascript it would look like this: (you can see the gcode it generates in your browser here)

//draw 1" grid lines on table with marker

limitY = 15
limitX = 9

//RunGCode, true returns when movement complete.
function go(x,y){mach.RunGCode("G0 X" + x + " Y" + y, true); }
function  x(pos){mach.RunGCode("G0 X"+pos, true); }
function  y(pos){mach.RunGCode("G0 Y"+pos, true); }
function  z(pos){mach.RunGCode("G0 Z"+pos, true); }

function drawRect(x0,y0,w,h){
	z(1);
	go(x0,y0);
	z(0);
	x(x0+w);
	y(y0+h);
	x(x0);
	y(y0);
	z(1);
}

go(0,0); // home pos
z(0);    // marker down

i=0;
while(1){ //draw horz X lines
	x(limitX); //all way right
	i++
	if(i > limitY) break;
	y(i); //up to next line
	x(0);  //all way left
	i++;
	if(i > limitY) break;
	y(i); //up to next line
}

z(1);    //marker up..
go(0,0); //go home
z(0);    //marker down

i=0;
while(1){ //draw vertical Y lines
	y(limitY); //all way up
	i++
	if(i > limitX) break;
	x(i);   //right one
	y(0);  //all way down
	i++;
	if(i > limitX) break;
	x(i);   //right one
}

//finally draw rectangle around entire perimiter 
drawRect(0,0,limitX,limitY);

//complete goto center 
z(1)
go(limitX/2, limitY/2);







Comments: (0)

 
Leave Comment:
Name:
Email: (not shown)
Message: (Required)
Math Question: 88 + 1 = ? followed by the letter: T 



About Me
More Blogs
Main Site
Posts: (All)
2024 ( 2 )
2023 ( 9 )
2022 ( 4 )
2021 ( 2 )
2020 ( 4 )
2019 ( 5 )
2018 ( 6 )
2017 ( 6 )
2016 (22)
     VB6 CDECL
     UDT Tricks pt2
     Remote Data Extraction
     Collection Extender
     VB6 FindResource
     CDO.Message
     DirList Single Click
     Reset CheckPoint VPN Policy
     VB6 BSTR Oddities Explained
     SafeArrays in C
     BSTR and Variant in C++
     Property let optional args
     Misc Libs
     Enum Named Pipes
     Vb6 Collection in C++
     VB6 Overloaded Methods
     EXPORT FUNCDNAME Warning
     VB6 Syncronous Socket
     Simple IPC
     VB6 Auto Resize Form Elements
     Mach3 Automation
     Exit For in While
2015 ( 15 )
2014 ( 25 )
2013 ( 4 )
2012 ( 10 )
2011 ( 7 )
2010 ( 11 )
2009 ( 3 )