Hello Guest it is June 06, 2023, 01:12:09 AM

Author Topic: Simple button script to rapid to a know position.  (Read 4965 times)

0 Members and 1 Guest are viewing this topic.

Offline Chaoticone

  • *
  •  5,626 5,626
  • Precision Chaos
    • View Profile
Simple button script to rapid to a know position.
« on: December 15, 2014, 11:39:34 PM »
This simple script is for a button. It will rapid the Z to machine (G53) 0 (zero). Once the Z is at 0 it will move the X and Y to machine (G53) 0 (zero). The \n in the script makes this code run as it would if it were 2 lines of gcode.

Code: [Select]
local inst = mc.mcGetInstance();
--Becasue Mach4 can run multiple instances, we need to tell the script which instance to run in.
mc.mcCntlGcodeExecute (inst, "G53 G90 G0 Z0\n G53 G0 X0 Y0");
--The above line will be executed as 2 lines of Gcode. G53 G90 G0 Z0 will be executed then
--\n means a new line so G53 G0 X0 Y0 will be executed after the code before the \n is finished.
--Everything between the quotation marks " " will be interpreted as a string.

I edited the Keyboard Jog On/Off button for this and have attached a few screen shots to help.
« Last Edit: December 15, 2014, 11:41:25 PM by Chaoticone »
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!

Offline Pedio

  •  200 200
    • View Profile
Re: Simple button script to rapid to a know position.
« Reply #1 on: June 22, 2015, 08:15:03 PM »
I am new to all of this so please forgive me if I am asking a silly question. Is it possible to enter coordinates into the boxes on the screen and have the machine go to those coordinates? e.g., in the X box if I enter 20 it goes to 20" (on my machine) from the X=0 position. This would make it very easy to navigate to remote work pieces.
I know I can use the MDI but that has a lot of screen changing for something that happens often.

Offline DazTheGas

  •  776 776
  • DazTheGas
    • View Profile
Re: Simple button script to rapid to a know position.
« Reply #2 on: June 23, 2015, 03:20:34 AM »
would it not be best to wrap that in an if statement ie,

if all axis are homed then
else do nothing

New For 2022 - Instagram: dazthegas
Re: Simple button script to rapid to a know position.
« Reply #3 on: June 24, 2015, 11:24:00 PM »
yes, yes, and yes :o) There a hundreds of way's to this, tailor this, or implement whatever you want. True Daz, I would enable the button or execute the movement to position zero 'if axisIsHomed then...." execute gCode movement just to be safe else if the call was executed before all axes are referenced then the positioning might be off. Example, x axis is binding (with stepper motors) and DROs continue movement. When I stop movement and then Goto Zero before homing my axes, the positioning will be off. I know you know but just in case someone new might like an example. Senior and experienced operators know this and would not need such a conditional statement. But m4 is so easy and flexible, why not!

...it is a lot of screen changing for an MDI input? It is one click, enter block of instructions, press cycle start...oh it's sooo hard! haha, just kidding. You can create a button and label it say 'Offset 3' and you can execute movement to your offset position, or create offset registers and reference those registers in the button to goto that position, or create a DRO that accepts manual input and read that input as a string value variable (screen get property call) and execute gCode movement from there (I think that may be what you are asking...that's a good project, I'll work on it for a bit and let ya know...great idea :)
« Last Edit: June 24, 2015, 11:33:23 PM by Screwie Louie »