Objects available:
Sample JS code:
// Move your machine to X = -10
let machine = new Machine();
machine.code( "G00 X-10" );
Object to control the device connected to Ultimate CNC.
Send G-code to device.
let machine = new Machine();
machine.code( "F100; G01 X-10; Y10; X0; Y0" );
Return current working position.
let machine = new Machine;
machine.code("G90; G21; F400; G01 X-10.5 Y-12.56 Z1; ");
let machinePosition = machine.getMachinePosition();
// machinePosition = -10.500,-12.560,1.000
Return current axis working position.
let machine = new Machine;
machine.code("G90; G21; F400; G01 X-10.5 Y-12.56 Z1; ");
let xMPosition = machine.getMachinePosition('x');
let yMPosition = machine.getMachinePosition('y');
let zMPosition = machine.getMachinePosition('z');
// xMPosition = -10.500
// yMPosition = -12.568
// zMPosition = 1.000
Set coordinates XY = 0.
Set coordinate Z = 0.
Return current machine position.
let machine = new Machine;
machine.code("G90; G21; F400; G01 X-1 Y-2 Z3; ");
machine.zeroXy();
machine.zeroZ();
machine.code("G53 G01 X0 Y0 Z0; ");
let machinePosition = machine.getMachinePosition();
let workPosition = machine.getWorkingPosition();
// machinePosition = 0.000,0.000,0.000
// workPosition = 1.000,2.000,-3.000
Return current axis machine position.
machine.code("G90; G21; F400; G01 X-1 Y-2 Z3; ");
machine.zeroXy();
machine.zeroZ();
machine.code("G53 G01 X0 Y0 Z0; ");
let machinePosition = machine.getMachinePosition();
let workPosition = machine.getWorkingPosition();
// machinePosition = 0.000,0.000,0.000
let xMPosition = machine.getMachinePosition('x');
let yMPosition = machine.getMachinePosition('y');
let zMPosition = machine.getMachinePosition('z');
// xMPosition = 0.000
// yMPosition = 0.000
// zMPosition = 0.000
Return current feedrate.
Return current vel. spindle.
Return current spindle rotation.
Return current spindle rotation.
Return mist coolant state.
Return flood coolant state.
Return device state.
Return Z from configuration.
Set Z safe.
Default device to connect.
Default bps device to connect.
Return current tool configured
Set current tool
Open manual tool change utility.
Used to know if tool change procedure is done.
Get the config parameter on your firmware.
let machine = new Machine();
let param100 = machine.getConfig( "100" );
Set parameter on your firmware. Example:
let machine = new Machine();
machine.setConfig( "100", "1280" );
Return all configuration parameters on your device. These parameters are saved on Ultimate CNC, so don't query it to your device.
Example:
// Get all configuration from your firmware
let machine = new Machine();
let params = machine.getAllConfig( );
Run probe.
Run goZeroZ.
Run goHome.
Run goZup.
Turn on spindle.
Turn off spindle.
Sleep your script.
let utils = new Utils();
let machine = new Machine();
machine.command("$$");
utils.sleep(5);
let params = machine.getAllConfig();
Kill your script.
let utils = new Utils();
let machine = new Machine;
machine.goUpZ();
utils.kill( );
machine.goHome();
// goHome() is never reached
Show message in a popup window.
let dialog = new Dialog();
dialog.alert( "Hi! alert" );
Show message in a popup window.
let dialog = new Dialog();
dialog.info( "My info message" );
Show message in a popup window and return response for user.
let confirm = dialog.confirm( "Go home ?" );
if ( confirm ) {
· machine.goHome();
}
Show you a input for coordinates [X,Y,Z] in a popup window and return response for user.
let dialog = new Dialog();
let machine = new Machine();
machine.code("G90; G21; F400");
let init = [ 0, 0 ];
let status = dialog.getCoord( "Select init coordinates", init );
if ( status ) {
· machine.code("G01 X" + init[0] + "Y" + init[1] + "Z" + init[2]);
}
let confirm = dialog.confirm( "Do you want triangle wave ?" );
if ( confirm ) {
· let triangle = [];
· triangle[0] = [ 0, 0 ];
· triangle[1] = [ 25, 25 ];
· triangle[2] = [ 50, 0 ];
· triangle[3] = [ 75, 25 ];
· triangle[4] = [ 100, 0 ];
· let gCode = "";
· for (let coordinate of triangle) {
·· gCode += "G01 X" + (coordinate[0] + init[0]) + "Y" + (coordinate[1] + init[1]) + ";";
· }
· machine.code( gCode );
}
Show popup window to inform that script is working.
let machine = new Machine();
machine.code( "G90; G21; F300" );
let dialog = new Dialog();
dialog.busy( true );
let commands = "";
for ( let x=0; x <= 100; x += 10 ) {
· commands += "G01 X" + x + ';' ;
}
machine.code( commands );
dialog.busy( false );
Receive events in your script.
Register your handler function to recipe changes in the state of your device.
let dialog = new Dialog();
function statesHandler( state ) {
· if ( state == "ALARM") {
·· dialog.alert( "Machine, alert: " + state );
· } else {
·· dialog.info( "Machine, info:" + state );
· }
}
let mEvent = new Events;
mEvent.stateMachine( statesHandler );
let machine = new Machine;
machine.code("G90; G21; F400; G01 X-10;");
machine.goHome();
Register your handler function to recipe changes in the G-code sender.
let dialog = new Dialog();
let utils = new Utils();
·
function statesHandler( state ) {
·if ( state == "ALARM") {
··utils.kill( );
·} else {
··dialog.info( "Machine, info:" + state );
·}
}
·
function stateGcodeProgramHandler( state ) {
·if ( state == "ERROR") {
··utils.kill( );
·}
}
·
let events = new Events;
events.stateMachine( statesHandler );
events.stateGcodeProgram( stateGcodeProgramHandler );
·
let machine = new Machine;
machine.goUpZ();
machine.code("G90; G21; F400;SOME_ERROR!; G01 X-10;");
machine.goHome();
machine.code("G90; G21; F400;G01 X-50;");
// G01 X-10; is not executed and goHome is never reached
Register your handler function to recipe M-Codes from G-code sender. TODO
Register your handler function to recipe some G-Codes from G-code sender. TODO
This Object allows load G-code from files, G-code list or 2D vectors array.
Load a G-code program from file.
Load a G-code program from a array (it is a list of G-code).
You must use this function to load G-code programs. Machine.code does not load G-code programs. This function does not generate any movement like Machine.code does.
// Sine wave
// From coordinates to G-code Program
const A = 10;
const CC = 5;
const SAMPLES = 1000;
const WIDTH = 100;
let lines = [];
lines.push("G21");
lines.push("G90");
lines.push("F300");
let angle = 0.0;
for ( let i = 0; i < SAMPLES; i++ )
{
··let y = (A * Math.sin(angle) + CC);
··let x = i * WIDTH / SAMPLES;
··lines.push ( "G01 X" + x.toFixed(3) + "Y" + y.toFixed(3) + "\n" );
··angle += (2 * Math.PI) / SAMPLES;
}
let program = new GCodeProgram();
program.code( lines );
Load 2D vectors, and it will be converted to G-code Program.
// Draw ellipse
// Ultimate CNC will create G-code Program
const SAMPLES = 1000;
const STEP = 2 * Math.PI/SAMPLES;
const RADIUS = 50.0;
const DEPTH = 1.0;
const DEPTH_STEPS = 0.5;
let axis = [];
for( let angle = 0; angle <= 2 * Math.PI; angle += STEP ) {
·var point = [
··RADIUS * Math.cos(angle),
··-0.5 * RADIUS * Math.sin(angle)
·];
·axis.push( point );
}
let program = new GCodeProgram();
program.vectors( axis, DEPTH, DEPTH_STEPS );
Get size of the G-code Program loaded.
// Create a G-code program from XY coordinates.
// In this case, a simple triangle.
// P0 = (0,0) P1 (-20,20) P2 (20,20)
// Show message with size of triangle
const SAMPLES = 1000;
const STEP = 2*Math.PI/SAMPLES;
const RADIUS = 50.0;
const DEPTH = 1.0;
const DEPTH_STEPS = 0.5;
let program = new GCodeProgram();
let axis = [ [0,0], [-20,20], [20,20] ];
program.vectors( axis, DEPTH, DEPTH_STEPS );
let frame = {};
program.getSize( frame );
let dialog = new Dialog();
dialog.alert( JSON.stringify(frame) );
// {"xmin":-20,"xmax":20,"ymin":0,"ymax":20,"width":40,"height":20}
This Object allows load a lot of shapes or drills into Simple CAD.
Later, you will be able to use Simple CAD to generate the G-code program.
Load a drill in SimpleCAD
Load a polygon in SimpleCAD
Load a rectangle in SimpleCAD
Load a circle in SimpleCAD
Load a triangle in SimpleCAD
Load a square in SimpleCAD