Mach3 AutomationAuthor: 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:
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) |
About Me More Blogs Main Site
|
||||||||||||||||||||||||||||||||||||||