Hello Guest it is March 29, 2024, 05:51:40 AM

Author Topic: Is it possible to set z-axis softlimit using a script?  (Read 1017 times)

0 Members and 1 Guest are viewing this topic.

Is it possible to set z-axis softlimit using a script?
« on: October 03, 2018, 03:34:14 PM »
I am a member of a community workshop where many of the users are new to CNC and as consequence there is a lot of uncontrolled cutting into the spoil board.

My question is:
If we use a manual touch plate on the spoil board to set the z axis, is it possible set the value of the z axis softlimit within the same script?

Our set up is Mach4 and smoothstepper.
Re: Is it possible to set z-axis softlimit using a script?
« Reply #1 on: November 20, 2018, 01:07:38 AM »
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