Hello Guest it is October 23, 2019, 09:43:33 AM

Author Topic: last line not executing  (Read 385 times)

0 Members and 1 Guest are viewing this topic.

Offline Bill_O

*
  •  241 241
    • View Profile
last line not executing
« on: February 28, 2019, 05:46:03 PM »
The last line of the attached mcs file is not happening.
I am sure it is a syntax error but I can not see it.
Re: last line not executing
« Reply #1 on: February 28, 2019, 06:18:04 PM »
Hi,
the most likely reason its not executing is because the Gcode interpreter is busy or the motion controller is under command by
another chunk, the GUI chunk for instance. You are overlooking the fact that the API like all Lua functions has a return code.
You need to capture it and test it.

Quote
LUA Syntax:
rc = mc.mcCntlGcodeExecute(
      number mInst,
      string commands)

Description:
Execute G code as a unit of work and wait until it is complete.

Parameters: Parameter Description
mInst The controller instance.
commands A string buffer containing G code.


Returns: Return Code Description
MERROR_NOERROR No Error.
MERROR_INVALID_INSTANCE The mInst parameter was out of range.
MERROR_NOT_NOW The operation could not be completed at this time.
MERROR_NOT_COMPILED The macro scripts could not be compiled.

In particular MERROR_NOT_NOW, which is the same as the number -18.

So try adding this to your code:

Code: [Select]
local rc=mc.mcCntlGcodeExecuteWait(inst, GCodeXMov)
--use encoder positioning
If (rc== -18) then
       wx.wxMessageBox("MERROR_NOT_NOW)
      do return end
end


--set x position to 0.0

This wont solve your problem but will indicate if my guess that the Gcode interpreter is able to accept instructions.
You could also test and message the machine state which might give you an indication which chunk is I control.

Quote
LUA Syntax:
mcState, rc = mc.mcCntlGetState(
      MINSTANCE mInst)

Description:
Get the current controller state.

Parameters: Parameter Description
mInst The controller instance.
state The address of a mcState variable to receive the controller state.


Returns: Return Code Description
MERROR_NOERROR No Error.
MERROR_INVALID_INSTANCE The mInst parameter was out of range.
MERROR_INVALID_ARG state is NULL.

Craig

My wife left with my best friend...
     and I miss him!
Re: last line not executing
« Reply #2 on: February 28, 2019, 07:39:58 PM »
GCodeX0 = string.format("G92 X%.4f\n", zero)
mc.mcCntlGcodeExecuteWait(inst, GCodeX0)
GCodeY0 = string.format("G92 Y%.4f\n", zero)
mc.mcCntlGcodeExecuteWait(inst, GCodeY0)

--move material back to start position
GCodeXMov = "G01 X-7.0 F100.0"
mc.mcCntlGcodeExecuteWait(inst, GCodeXMov)

I believe the recommended way to do this is:

GCodeX0 = string.format("G92 X%.4f\n", zero)
GCodeY0 = string.format("G92 Y%.4f\n", zero)
GCodeXMov = "G01 X-7.0 F100.0\n"

local s=GCodeX0..GCodeY0..GCodeXMov
mc.mcCntlGCodeExecute(inst,s)
or
mc.mcCntlMdiExecute(inst,s)

HTH

RT

Offline Bill_O

*
  •  241 241
    • View Profile
Re: last line not executing
« Reply #3 on: March 01, 2019, 05:58:58 PM »
thanks all for your input.
after some testing and seeing when things are happening it really looks like mach is busy or somehow skipping lines of script
i will be trying to do some testing and see what is happening next week

is there a way to force mach to finish the instructions before it goes on to the next command?
mach3 had sleep you could you to force the script to slow down or wait a set amount of time
Re: last line not executing
« Reply #4 on: March 01, 2019, 11:14:32 PM »
Hi,

Quote
is there a way to force mach to finish the instructions before it goes on to the next command?

That is exactly what mcCntlGcodeExecuteWait() does. Your problem is you are asking an API to do something it cannot
do because the Gcode interpreter is busy. You should test the machine state prior to calling the API if it critical that the
call progresses and you can, in fact should, test the return code when it completes.

Craig
My wife left with my best friend...
     and I miss him!

Offline Bill_O

*
  •  241 241
    • View Profile
Re: last line not executing
« Reply #5 on: March 04, 2019, 08:13:41 AM »
Craig,

Obviously this is causing me some problems.
If the mcCntlGcodeExecuteWait() is to insure the gcode gets done before moving on to the next line then how is the API busy when it gets to the next line?
I really am not trying to be a jerk I just really am having a hard time understanding how some of this works.
I put the error code you recommended earlier at the end and it did nothing.
I am going to put it up farther and see if anything shows up.
I really do appreciate the help.

Bill

Offline Bill_O

*
  •  241 241
    • View Profile
Re: last line not executing
« Reply #6 on: March 04, 2019, 11:47:50 AM »
I have been commenting out lines trying to find where the problem is.
I have attached the current mcs.
In this one everything is commented out other than the home of axis 0 then a move of that axis then what i believe should be a message box.
It homes and nothing else.
If I comment out the home it will move but the message box does not appear.
Any ideas on what I can do to allow me to do anything after the home?
Re: last line not executing
« Reply #7 on: March 04, 2019, 02:19:15 PM »
Hi,
the message box only pops up if the mc.CntlGcodeExecuteWait() call FAILS. You wont see it if the call
progresses.

What's happening is the mcAxisHome() call is tying up the axis so the subsequent mcCntlGcodeExecuteWait() call
fails. We need to give some more thought to how to ensure that the X axis is homed before progressing.

I will give it some thought over the day and come back to you.

Craig
My wife left with my best friend...
     and I miss him!

Offline Bill_O

*
  •  241 241
    • View Profile
Re: last line not executing
« Reply #8 on: March 04, 2019, 02:59:08 PM »
Craig,

What about some kind of counting loop.

count = 1
while count < 10000
   count = count +1
end while

Bill

Offline smurph

*
  • *
  •  1,138 1,138
  • "That there... that's an RV."
    • View Profile
Re: last line not executing
« Reply #9 on: March 04, 2019, 05:55:32 PM »
I'm not sure what your end goal is, but you won't be able to home an axis in an M code script.  The script you posted would work (with modifications) in a button script though. 

Why do we not allow homing in M code macros?  Well..  it is because the machine is not in the IDLE state.  It is in automatic mode.  You can't do a manual mode function (jog, MPG, homing, etc...) while in automatic mode. 

The thing that isn't happening with the script is waiting for the home ops to complete.  You can wait on them by checking the state of the machine with mc.mcCntlGetState().  The first thing to do is call the home ops (checking the return codes to make sure there are no errors).  Then loop until the state is not equal to mc.MC_STATE_IDLE.  Once the state is no longer IDLE, loop and wait for it to return to idle.  The home ops will have completed at that time. 

None of that script checks any return codes.  There are no mysteries if you check the return codes.  :)

Steve