Hello Guest it is April 26, 2024, 03:41:02 AM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - dbt3000files

Pages: « 1 2 3 4 5 6 7 »
31
Mach4 General Discussion / Re: A Aixs Brake
« on: January 28, 2019, 05:56:28 PM »
Hey thanks for the reply,
I actually need something from Mach4 to initialize a check on the motor.  Essentially I am trying to create an extra level of safety in the case of a wire fault or any other reason signals might not get to the motors. I am using clearpath motors, which will know if they are out of position, but if a signal fails to reach them, they won't know they missed anything. 
I had a strange incident when Mach4 stopped sending step and direction signals intermittently when jogging.  The whole program was behaving erratically and was fine after a restart, but it was enough to make me want to create a way for the clearpath motor to verify that it is moving when Mach thinks it is.

32
Mach4 General Discussion / trouble with mc.mcaxisisstill
« on: January 28, 2019, 12:21:17 PM »
I want to have Mach4 check an output from a clearpath motor every time the axis associated with that motor is moving.  I thought using mc.mcaxisisstill would be the way to do that, but it seems to be returning a positive result whether the axis is moving or not.  Any ideas what I might be doing wrong??
Here's a test code that I was using:

    local inst = mc.mcGetInstance()
    local still
    local rc
    local gcode = ""
    gcode = gcode .. ("g0 x-2\n")
    gcode = gcode .. ("g0 x0\n")
    mc.mcCntlGcodeExecute(inst, gcode)
    wx.wxMilliSleep(400)
    still, rc = mc.mcAxisIsStill(inst, 0)
    wx.wxMessageBox(tostring(still))
    if rc ~= mc.MERROR_NOERROR then
        wx.wxMessageBox("error")
    end

33
Mach4 General Discussion / Re: A Aixs Brake
« on: January 28, 2019, 12:09:11 PM »
Any luck in getting mc.mcAxisIsStill working?  I am having the same problem that when running gcode it returns positive no matter what the axis is doing.
Thanks,
David

34
Mach4 General Discussion / Re: mcCntlGcodeExecute best practice
« on: January 28, 2019, 12:00:41 PM »
Thanks Craig for the suggestions.
I think it looks like I need to use mc.mcCntlGetState
Found my answer here: https://www.machsupport.com/forum/index.php?topic=36018.0

35
Mach4 General Discussion / mcCntlGcodeExecute best practice
« on: January 26, 2019, 04:05:03 PM »
Does anyone know if there is a way to check on the status of a gcode execution?  I have been using mc.mcCntlGcodeExecuteWait with no issues, but I want to be able to check the state of an input while the gcode is being run and then wait until it is done to move on to the next line of Lua. I am assuming that I can use mcCntlGcodeExecute to do this, but I can't figure out how to know when it is done.

Thanks,
David

36
Mach4 General Discussion / Re: call to new gcode from end of exisst gcode
« on: November 20, 2018, 01:31:12 AM »
It doesn't sound like you want to be trying to do what you are doing with just g code.  If you have many different discreet files that you need to load, you will have to use a macro and do the whole thing in Lua.  You can run subroutines in g code but it sounds like you probably need more than that. 
Here is an example of a function in Lua that will open a file and place each line of code (could be g code) into an array called file_data:

function populate(filename)                 --function to put saved parameters in appropriate boxes
   local rc            --return code     
   local file_data = {}      --array for holding data
   local file_path = c:\your directory .. filename
   if io.open(file_path,"r") == nil then   --if the file cannot be opened       
      error("error loading file: " .. filename)
      return nil, nil
   else   
      io.input(io.open(file_path,"r"))              --open the file
   end                                         
   for i = 0, 200 do                                 --read the file line by line, and place each line in the next position of the array
      file_data = io.read("*line")         
   end
   io.input():close()        -- close current file
   return file_data, mc.MERROR_NOERROR
end

or, more simply you can just dump the entirety of a file into a string called gcode

            io.input(io.open(file path,"r"))   --open file in read mode
            gcode = gcode .. io.read("*all")  --copy the whole thing to a variable called gcode
        end
        io.input():close()        -- close current file

then use mc.mcCntlGcodeExecuteWait(inst, gcode)   to execute the file


Just in case you think subroutines in g code would work, here is an example:

m98 p010 L2 (call subroutine 010, repeat 2 times)

O010           (subroutine 010) (this could be the code for your first part?)
 g0 x1
 g0 x0
M99             (end of subroutine)

O011           (subroutine 011)(second part?)
etc.

Hope that helps!

37
I assume that you found mc.mcAxisSetSoftlimitEnable in the API?  This is not really what you are looking for, but it could at least turn a soft limit on.  I was looking for the same thing as you and couldn't find it.  What I resorted to was writing a script that checked my offsets to make sure that they were within a specified range that I have set with a wizard.  This way you can have the machine set your offset automatically from the touch plate, or be confident that none of your members will set an unacceptable offset. (The retrievesettings() is to get data from the wizard, and the error() is just a function that stops the g code, spindles etc.)
Sorry it's not what you are looking for, but maybe will be some help.

function offsetsafetycheck()
   local rc            --return code     
   local inst = mc.mcGetInstance()    --Get instance
   local offset_x
   local offset_y
   local offset_z
   offset_x, rc = mc.mcCntlGetOffset(inst, 0, 1)
   if rc ~= mc.MERROR_NOERROR then
      error("error retrieving offset_x")
      return nil
   end
   offset_y, rc = mc.mcCntlGetOffset(inst, 1, 1)
   if rc ~= mc.MERROR_NOERROR then
      error("error retrieving offset_y")
      return nil
   end
   offset_z, rc = mc.mcCntlGetOffset(inst, 2, 1)
   if rc ~= mc.MERROR_NOERROR then
      error("error retrieving offset_z")
      return nil
   end   
   local probe_max_x_offset
   local probe_max_z_offset
   probe_max_x_offset, rc = retrievesettings("probe_max_x_offset")
   if rc ~= mc.MERROR_NOERROR then
      return nil
   end
   probe_max_z_offset, rc = retrievesettings("probe_max_z_offset")
   if rc ~= mc.MERROR_NOERROR then
      return nil
   end
   if math.abs(tonumber(probe_max_x_offset)) > .020 then
      error (("Max x offset setting too high! Check gouger settings.\n") .. ("Current max x offset setting: ") .. (probe_max_x_offset))
      return nil
   end
   if math.abs(tonumber(probe_max_z_offset)) > .020 then
      error (("Max Z offset setting too high! Check gouger settings.\n") .. ("Current max z offset setting: ") .. (probe_max_z_offset))
      return nil
   end
   if math.abs(tonumber(offset_x)) > math.abs(tonumber(probe_max_x_offset)) then
      error (("X offset too large") .. ("\nOffset attempted: ") .. (offset_x) .. ("\n") .. ("Max offset: ") .. (probe_max_x_offset))
      return nil
   end
   if math.abs(tonumber(offset_z)) > math.abs(tonumber(probe_max_z_offset)) then
      error (("Z offset too large") .. ("\nOffset attempted: ") .. (offset_z) .. ("\n") .. ("Max offset: ") .. (probe_max_z_offset))
      return nil
   end
   if math.abs(tonumber(offset_y)) ~= 0 then
      error (("Y offset too large") .. ("\nOffset attempted: ") .. (offset_y) .. ("\n") .. ("No offset is acceptable for y axis"))
      return nil
   end
   return mc.MERROR_NOERROR
end

38
Mach4 General Discussion / Re: terminate lua script
« on: November 18, 2018, 07:55:00 PM »
Thanks Daz. I'm glad I'm not just missing something obvious.  So am I right in thinking the best way to do this is to use a return code? I am using return nil to end everything which is what seems to be the normal way to do it, but the examples in the Mach4 Lua manual use do return end. Any thoughts on this?
Thanks!
David

function test()
   if 1 == 1 then
       return 1, mc.MERROR_NOERROR
   else
      wx.wxmessagebox("nope")
      return nil, nil
end
local answer
local rc
answer, rc = test()
if rc ~= mc.MERROR_NOERROR then
   return nil
end

39
Mach4 General Discussion / Macro keeps running after estop!
« on: November 17, 2018, 12:44:03 PM »
Hey everybody, I know this is very similar to a post I just made, but a little more perplexing. I just experienced a pretty bad crash because a macro continued running after the machine was disabled and raised a clamp jaw into a still moving spindle.

So a wood chip broke off of a part and got wedged into one of the slides, and blocked a Clearpath motor causing it trigger a "limit switch" event in Mach4. Everything good there.
The problem is, that the macro that was currently controlling everything continued running even though the machine was disabled. Although the machine was ignoring any motion commands, it still was able to operate the outputs, and did just that, opening a clamp jaw in the wrong position into a spindle that was still spooling down.

I now realize that I should have had the output pins set to be forced low in a disable condition, and had overlooked that when setting up Mach4. That would have prevented the crash, but I still would like to be able to prevent a macro from continuing in the event of a machine disable. It seems like this would be the default, but maybe there is some setting that I need to change?
If not, does anyone have any suggestions for building something into the code that would solve this problem?
Thanks for any help!
David

40
Mach4 General Discussion / terminate lua script
« on: November 13, 2018, 10:48:24 PM »
Does anyone know the best way to terminate a lua script or macro?

I have been using "do return end", but I have run into a problem.  If I run "do return end" from within a function it will end that function but not the entire macro script.

For example:
In a file called macrofunctions I could have the following:

function whatIwanttosay()
   wx.wxmessagebox("good to see you") 
   do return end    --end script so nothing else is said (this is what I was hoping I could use to stop the entire program)
end

function whatIamthinking()
   wx.wxmessagebox("looks like you gained a few pounds")
end

My macro would be:

function m90001()
   whatIwanttosay()
   whatIamthinking()
end

The do return end at the end of the function whatIwanttosay() does nothing to prevent the macro from calling the next function.  Is there a way to end an entire macro from within a function?  If not, I am wondering what is considered best practice for ending a script. 
I realize that I could have each function return a number and I could check for that number before running any further functions, but it doesn't seem like a very elegant solution.  I have quite a few nested functions, and the whole thing becomes a mess if I have to query each one to see if it has completed before continuing.

Thanks for any help!!
David


Pages: « 1 2 3 4 5 6 7 »