Hello Guest it is March 29, 2024, 09:53:34 AM

Author Topic: How to interrupt a running script?  (Read 2610 times)

0 Members and 1 Guest are viewing this topic.

How to interrupt a running script?
« on: December 11, 2020, 01:57:37 PM »
I'm writing a new tool-change z-zeroing script.  It approaches things a little differently (sorry bad pun).

The script loops at multiple points and I want the user to be able to pause and/or stop the script at various points by clicking <Feed Hold> and <Stop> buttons on the [Program Run] screen (or keys or MPG inputs).

I can't seem to find a way for the script to read the 'clicked' state of these buttons.  Is there a way to do this?  I can't edit the script behind these buttons. (?)

Clicking <Reset> seems to stop the script but clicking <Reset> again to clear the e-Stop continues the script where it stopped.  If the tool is about to crash, this isn't quite what I want...

Interrupting motion underway would be a bonus if possible, but I'm aware it's happening async in another thread if not on an external motion controller.  Maybe checking a stop flag and triggering a motion-abort in the While (IsMoving()) loop?

Ideally I'd like to do all this while not having to edit screensets or throw up modal dialogs.

This seems like it should be pretty easy to do, I think I'm probably just missing something obvious.

Hopefully this new tool setting approach will solve some of the problems I've run into (haha) with the scripts I've found online.  If it works well I plan to share it here.
Think twice before you G0 -Z...

Offline TPS

*
  •  2,501 2,501
    • View Profile
Re: How to interrupt a running script?
« Reply #1 on: December 12, 2020, 01:31:02 AM »
there is now way to get get Access do Screen button Events.

so one way is to to put:
Code: [Select]
  If IsStopped() Then
    Exit Sub
  End If

into the loop's

by editing the screenset, you can put a
Code: [Select]
  SetUserLed(*********)
to the button a react in your script.


anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: How to interrupt a running script?
« Reply #2 on: December 14, 2020, 08:24:20 PM »
Thanks for the suggestions TPS.

I can't seem to get IsStopped() to work the way you're describing though.  From what I can tell, IsStopped() only returns True when all axis are stopped.  In my case, often script is in a loop while axises are not moving.  For example while waiting for GetOEMLed(OEMLED_DigitizeInput).

And I can't seem to edit the Feed Hold, Stop, or Reset buttons, so I can't do a SetUserLed() as you mentioned either.

Am I missing something here?  Is there any way to detect these buttons being clicked?  Checking button state would be ideal so I don't have to change screenset code.

The only idea I have is to use a modal dialog and put my UI elements there.  But I'm trying to keep the design modeless if possible. (?)
Think twice before you G0 -Z...

Offline TPS

*
  •  2,501 2,501
    • View Profile
Re: How to interrupt a running script?
« Reply #3 on: December 15, 2020, 01:35:49 AM »
try to use LED(800) Reset LED instead of IsStopped()

for the buttons, you have to Change the button from an Standard button to a Basic script button
and then you can put VB code onto the button, but you have to put the originally function also into
the script.

for stop button for example
Code: [Select]
  doOemButton(1003)
  SetUserLed(xx)

https://www.machsupport.com/forum/index.php?topic=19482.0  -> the best list of button's/led's/Dro's i know.

no way to detect that a button has been clicked

do not try to detect a probe with GetOEMLed(OEMLED_DigitizeInput)
have a look for G31!
G31 provides in Var's 2000,2001,2002 the Position where probe was hit, and here we are on a Point,
where the problem's are starting. Var's 2000.. are not supported by all Motion Controllers, specialy
chinese chunk does not.



« Last Edit: December 15, 2020, 01:45:33 AM by TPS »
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: How to interrupt a running script?
« Reply #4 on: December 15, 2020, 05:36:38 PM »
Thanks so much for the help, TPS.  You will probably have some great suggestions, can you comment on the following?  (helpful suggestions from anyone are welcome!)

This is a little use-case document I threw together to think through what I'm trying to do:

Set toolheight use cases -

Use case:
   User hits Auto Tool Zero button in Mach-3 GUI

Assumptions:
   * Machine is stopped & user has or wants to change tool
   * User wants to zero Z at an arbitrary location
   * Tool change will manually initiate jogged on top of GaugeBlock to prevent probe crashes
   
Steps:
   * If tool is not currently touching, display message and wait for touching=yes
      1) change tool if necessary 2) place TouchPlate & GaugeBlock on TouchPlate
      3) ground tool 4) jog tool to just touch TouchPlate
   * Now assume tool has been jogged down to touch GaugeBlock resting on TouchPlate
   * Display request to remove GaugeBlock message and wait for touching=no for safe interval
   * Issue warning beep
   * Wait for safety interval
   * Move (optional rapid?) down to just above TouchPlate (GaugeBlock - clearance)
   * Begin Automated probing use case

Use case:
   Script executes Tn M6 gcode tool change request

Assumptions:
   * Minimize assumptions in this case
   * Toolchange location (xyz) are properly set in Mach-3

Steps:
   * Rapid move tool up to safe-z (if set) or z=0 position (if no safe-z)
   * Rapid move tool to toolchange.x, toolchange.y position
   * Message user indicating tool change request with instructions to:
      1) change tool 2) ground tool 3) place TouchPlate (no GaugeBlock)
   * Wait for user to change tool and request continue (click or M0 stop?)
   * Issue warning beep, wait a short interval
   * Rapid move tool down to toolchange.z position
   * Begin Automated probing use case

Use case:
   Automated probing (& set tool z=0)

Assumptions:
   * Tool is changed
   * Tool is reliably (offset distance) above touchplate in correct tool change position
   * Tool grouned, everything is checked and ready to go
   
Steps:
   * Store current & reset all operating assumptions
   * Reduce feedrate
   * G31 probe to TouchPlate, limiting Z travel to prevent crashes
   * Detect and safely exit on abort (e-stop, etc)
   * If probe is not successful, abort.
   * If probe is successful, touch again (optional)
   * Set true z=0, ofsetting by TouchPlate thickness
   * return tool to safe-z height
   * restore all operating assumptions (as in all cases)

Notes:
   * All messages issue a corresponding sound
   * All waits timeout and exit
   * All exits return the machine to prior state
   * All moves are as safe as possible
   * All moves can detect abort requests and exit
Think twice before you G0 -Z...

Offline TPS

*
  •  2,501 2,501
    • View Profile
Re: How to interrupt a running script?
« Reply #5 on: December 16, 2020, 01:53:30 AM »
first of all, there are many way's to handle Auto tool length or tool length correction.
i assume you will not have a ATC. the difference between Auto tool Zero and tool lenght
correction i will try to explain.

a Auto tool Zero will only set the correct part Zero surface in your selected fixture,
but this surface can be gone due machinig process, and is not avaliable any more for
the next tool.

here is the Point where tool lenght correction Comes into the Focus.
for this case you will Need to have a referenced machine via Limit Switches (best *********ion),
or by an other way. that gives you the possibility via machine coords to get a relation between
the different tool lenght.
this procedure Needs also a zool lenght sensor on a fixed place.

the procedure would be:
-put in the first used tool
-measure the tool lenght via tool lenght sensor
-set tool enghtin tooltabel
-announce tool lenght via G43H(toolnumber)
-touch material surface via touch plate
-get X0/Y0 of your fixture

now you can start your Job with the first tool
-after first tool is done, machine goes to a tool Change Position (M6T?)
-after tool has been changed machine goes to tool lenght sensor Position
and measures tool lenght of new tool.
tool lenght has allways to set by G43H(toolnumber)
-continue Job

the referenced machine machine gives you allways the safety to move in machine coord's
and not in part coord's.

a few remarks:
-referencing Needs to be checked in tool lenght script.
-Status of tool lenght sensor an touch plate Need to be checked in script.
-machine Settings feedrate,G90/G91 and so on has to restored after script exceution
-and about ten other tings i forgot to say






anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.

Offline ZASto

*
  •  423 423
    • View Profile
Re: How to interrupt a running script?
« Reply #6 on: December 16, 2020, 06:38:11 AM »
Check Big-Tex toolsetter screen set how it is done (buttons: Initial Setup and Tool Zero Setup - if I've not mistaken the "writing on the wall" :))
Make no mistake between my personality and my attitude.
My personality is who I am.
My attitude depends on who you are.
Re: How to interrupt a running script?
« Reply #7 on: December 16, 2020, 02:19:58 PM »
Thanks for the feedback & patience.  While trying to sort out my understanding of the issues, I ran across @ger21's 'Mach3 2010 Screenset'.  I wasn't aware of it.  It looks like the real deal so I'm going to buy a copy and try out out.
Think twice before you G0 -Z...