Python/NC routine just stops executing

More
23 Aug 2024 23:51 #308503 by JetForMe
Starting a new thread about this specific problem I'm having (I no longer have the original problem described here ). I have a routine I invoke from my VCP to vacuum the table. It's a bit of Python code that invokes an NC subroutine. You can see the Python code and NC routine on Github.

When I click the button on the VCP to run the routine, it starts, but then stops a few seconds into execution. Where and when it stops is random. However, the code completes execution without any indication of error. The Python code prints this to stdout:
vacuumTable called poop
Current coordinate system:  1
Current tool: 0.000000, current pocket: 0.000000
vacuumTable finished

It was suggested to insert lots of `M66 L0 E0` statements in the Gcode, but this strikes me as an unreliable way to ensure code is run. Surely `linuxcnc.command().wait_complete()` should be enough to ensure the code runs to completion?

Please Log in or Create an account to join the conversation.

More
24 Aug 2024 13:45 - 24 Aug 2024 17:31 #308532 by Aciera
Not sure if this is the root of your problem but it's certainly possible.
The problem with '.wait_complete()' is that it does not work the way many of us think it does. It's not as simple as just slapping it in after an '.mdi()' because it's purpose is not to actually ensure that the command has been executed. Also many are not aware that it works with a timeout that has a built in default value of 5 seconds.
 
linuxcnc.org/docs/stable/html/config/pyt...inuxcnc_command_code

So '.wait_complete()' actually returns a value (-1 if timed out, RCS_DONE if the command has been executed successfully or RCS_ERROR if not).

If you now look at this snippet in your code as an example:
            sCommand.mode(linuxcnc.MODE_MDI)
            sCommand.wait_complete()
            sCommand.mdi("o<vacuum> call")
            sCommand.wait_complete()
            sCommand.mode(saveMode)
            print("vacuumTable finished")

It becomes clear that whenever you are calling '.wait_complete()' you are really not doing much at all because no matter the return value you just continue anyway and if the MDI command takes more then 5 seconds your code also just carries on and changes the mode. So if '.wait_complete()' is not used to actually receive its return value and make decisions upon that value it's basically nothing more than a timer with the benefit of allowing code execution to go on before the timeout occurs if the mdi command either executed successfully (RCS_DONE) or failed (RCS_ERROR).

Have a look at this example from '/lib/python/qtvcp/qt_action.py':

 

[edit]
In your case it may be as simple as extending the timeout of the second '.wait_complete()' to say 200s, depending on how long 'vacuum.ngc' takes to complete as it clearly does not seem to be as simple a task as switching on a vac:
            sCommand.mode(linuxcnc.MODE_MDI)
            sCommand.wait_complete()
            sCommand.mdi("o<vacuum> call")
            sCommand.wait_complete(200)
            sCommand.mode(saveMode)
            print("vacuumTable finished")
Attachments:
Last edit: 24 Aug 2024 17:31 by Aciera. Reason: clarification
The following user(s) said Thank You: tommylight

Please Log in or Create an account to join the conversation.

More
26 Aug 2024 03:23 #308644 by JetForMe
Thank you, that was indeed the problem.

That it has a default 5-second timeout (as opposed to no timeout), I would argue, is a mistake.

My routine runs the dust collector shoe over the table to vacuum up debris, hence the need to be able to run for a couple of minutes.

Please Log in or Create an account to join the conversation.

Time to create page: 0.098 seconds
Powered by Kunena Forum