Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: rhtuttle on December 29, 2017, 11:28:46 AM

Title: Home Signal
Post by: rhtuttle on December 29, 2017, 11:28:46 AM
When you set up a motor you define a home signal pin and whether that motor homes.  Is there an api that will allow you to turn on/off, mapping enabled or input name?

On my lathe I have my spindle configured to be either run by a motor for the spindle function or alternately driven by a stepper (belt change, motor 3, drive C) to act as a rotary/indexer.  I use input 12 as the spindle index pulse and as the homing signal for the C drive.  When used as a spindle the C drive homing signal is sent on each revolution.  It doesn't affect performance but the log has a message sent for each revolution.  I know I could just use two profiles but that creates other issues (re-referencing all axes).

TIA

RT
Title: Re: Home Signal
Post by: Chaoticone on December 29, 2017, 11:38:19 AM
Look in the API doc, API Reference by Category, Mach Signals and I think you will find what you're looking for.
Title: Re: Home Signal
Post by: rhtuttle on February 18, 2018, 02:26:46 PM
Everything as stated above but have added the signal enable/disable code.  Below is the code in my Ref C button left up script.  I have un-ticked the motor3 mapping home input signal through Mach4 config.  When the button is clicked I get

 PMDX: C-axis homing error, missing or invalid home switch configuration

Mach4 is disabled.  Not what I was hoping for. :-\  When I check the mach4 config the motor3 home mapping is ticked so the code is executing correctly but it appears PMDX is not checking the status of the mapping signal before homing.  Is it supposed to or am I misunderstanding what is happening?

Code: [Select]
local function myHomeC()
  local inst=mc.mcGetInstance()
  local rc,sState
  local pos=-1
  local hSigH=mc.mcSignalGetHandle(inst,mc.ISIG_MOTOR3_HOME)
  rc=mc.mcSignalEnable(hSigH,1)
  local hSig,rc=mc.mcSignalGetHandle(inst,mc.ISIG_INDEX)
  if rc==mc.MERROR_SIGNAL_NOT_FOUND  then
    wx.wxMessageBox('wrong Signal')
  end
  sState=mc.mcSignalGetState(hSig)
  if sState==1 then  -- sitting on the slot so move off it
    mc.mcCntlGcodeExecuteWait(inst,'g0 f20000 h15\n')--g1 h366 f5000')
  end
  mc.mcAxisHome(inst,mc.C_AXIS)
  repeat
    wx.wxMilliSleep(1000)
    rc= mc.mcAxisIsHoming(inst,mc.C_AXIS)
    mc.mcCntlSetLastError('Homing: '..tostring(rc))
  until rc==0 
  rc=mc.mcSignalEnable(hSigH,0)
end

myHomeC() 

TIA

RT
Title: Re: Home Signal
Post by: joeaverage on February 19, 2018, 06:25:45 AM
Hi RT,
not sure this will help with the input signals firing all the time but it may give you some insights into how Mach assigns axes and motors, when and how it updates the profile
etc.

http://www.machsupport.com/forum/index.php/topic,33866.0.html (http://www.machsupport.com/forum/index.php/topic,33866.0.html)

Craig
Title: Re: Home Signal
Post by: rhtuttle on February 19, 2018, 12:42:44 PM
Craig,  thanks for that but unfortunately even after writing to the profile, saving and flushing the PMDX still complains of an invalid configuration. I have confirmed that the correct profile string is written to with the correct settings before calling homing.

  local hSigH=mc.mcSignalGetHandle(inst,mc.ISIG_MOTOR3_HOME)
  rc=mc.mcSignalEnable(hSigH,1)
  mc.mcProfileWriteInt(inst,'Signal68','Enabled',1)
  mc.mcProfileSave(inst)
  mc.mcProfileFlush(inst)

Evidently PMDX does not read the current profie setting before doing homing.

I think I need to have Steve Stallings address whether this is a 'feature' or bug  ;)

RT
Title: Re: Home Signal
Post by: DazTheGas on February 19, 2018, 01:16:44 PM
When ever anything config wise is being done then mach4 needs to be in a config state, this will send a MSG_CONFIG_START to plugins, on exiting the config state MSG_CONFIG_END is sent to plugins. It is here where plugins do there housework etc, so without these msg's a plugin doesnt know anything has changed. There are commands ie mc.mcCntlConfigStart etc but wether they work or not??

DazTheGas
Title: Re: Home Signal
Post by: Steve Stallings on February 19, 2018, 01:20:57 PM
If I understand what you are saying..... you are trying to change to a mode where the
spindle is just rotating, not under trajectory control, and then remove the signal that
is used as Home for the C axis. If you do this and then ask for a Home All to execute,
then the PMDX SmartBob response is correct, you cannot do that because you have an
invalid configuration for the C axis.

It may be possible to use the API to set the C axis for Home In Place, but I could not
find out how to do that in a script.

The more likely alternative is to create a new custom Home All button that is aware of
which axes actually have a home signal at the time homing is requested, and only ask
 for Mach4 to home that set of axes.

Steve Stallings, PMDX
Title: Re: Home Signal
Post by: rhtuttle on February 19, 2018, 02:18:42 PM
Daz, thanks for the suggestion , but no joy. 

Adding the mcCntlConfigStart and stop lock the GUI.  Wrapping it in the disable and enable umlocks the GUI but none of the subsequent code gets executed.  As it stands now.

local function myHomeC()
  local inst=mc.mcGetInstance()
  local rc,sState
  local pos=-1
mc.mcCntlEnable(inst,0)
mc.mcCntlConfigStart(inst)
  local hSigH=mc.mcSignalGetHandle(inst,mc.ISIG_MOTOR3_HOME)
  rc=mc.mcSignalEnable(hSigH,1)
  mc.mcProfileWriteInt(inst,'Signal68','Enabled',1)
  mc.mcProfileSave(inst)
  mc.mcProfileFlush(inst)
mc.mcCntlConfigStop(inst)
mc.mcCntlEnable(inst,1)

-- now none of this code is executed, makes sense since a disable cancels all running code

  local hSig,rc=mc.mcSignalGetHandle(inst,mc.ISIG_INDEX)
  if rc==mc.MERROR_SIGNAL_NOT_FOUND  then
    wx.wxMessageBox('wrong Signal')
  end
  sState=mc.mcSignalGetState(hSig)
  if sState==1 then  -- sitting on the slot so move off it
    mc.mcCntlGcodeExecuteWait(inst,'g0 f20000 h15\n')--g1 h366 f5000')
  end
  mc.mcAxisHome(inst,mc.C_AXIS)
 
-- None of the folowing code ever got executed

 mc.mcCntlSetLastError('Homing')
 
  repeat
    wx.wxMilliSleep(1000)
    rc= mc.mcAxisIsHoming(inst,mc.C_AXIS)
    mc.mcCntlSetLastError('Homing: '..tostring(rc))
  until rc==0 
  rc=mc.mcSignalEnable(hSigH,0)
  mc.mcProfileFlush(inst)
end

myHomeC() 

RT
Title: Re: Home Signal
Post by: DazTheGas on February 19, 2018, 05:32:55 PM
So ive been back and reread the 1st post and if I have got it right, you want to use the same profile but have 2 different kinds of homing so you can leave an Axis out. If so it can be done like Steve says.
You can add another button and say which Axis to ref, ive just tested this and it is fine apart from both Axis will home at same time.

Code: [Select]
local mInst = mc.mcGetInstance()
mc.mcAxisHome(mInst, mc.Z_AXIS)
mc.mcAxisHome(mInst, mc.X_AXIS)

To ref individually and have dro`s moving then you would need to wrap this in a coroutine.

DazTheGas
Title: Re: Home Signal
Post by: rhtuttle on February 20, 2018, 10:58:04 AM
Daz, as Strother Martin says in 'Cool Hand Luke',  "What we've got here is failure to communicate!"  ;D

Not trying to have two homing operations.  Trying to stop the PMDX411 from throwing an 'C axis homing tripped' error message every revolution when using the spindle as a spindle.  It seems to me that that message should only be thrown when that axis is being homed, but that's just me.  If on a mill you have a your x axis home switch not at the end of travel but somewhere in the middle you really don't want an error message thrown every time you travel over it during an operation.

Here's a real world example.  Let's say on my lathe I want to make a knob with 10 equally spaced markings.  First I turn the knob to my desired shape.  Now I need to change belts on the spindle and control it as a rotary with a stepper(motor 3/C axis).  I need to home the C axis, then use a diamond drag to etch the markings every 36 degrees.  Now when I go back to turn another one, change belts, I will get the tripped error every revolution. 

What I want is to enable the 'Motor 3 home' mapping before homing and disable it after homing.  I don't think that is doable.  I think I am just going to have to manually change it when I manually change the belts. :-\

RT
Title: Re: Home Signal
Post by: joeaverage on February 20, 2018, 10:47:33 PM
Hi RT,
I can understand not wanting the logfile to get clogged up logging a home signal which is not being used.

If I understand the status of the thread is that if you disable the home signal then the homing routine fails
or at least objects and throws an error.

May I suggest instead trying unmapping the motor from the axis, this is possible programmatically. My hope is
that with the motor unmapped the homing routine will not throw an error. It may not even require you to disable
the home signal.

Craig
Title: Re: Home Signal
Post by: Chaoticone on February 21, 2018, 01:17:50 AM
Do you have the home switch signal also assigned as a limit switch or something else? I thought home switches were only recognized during a homing routine. The signal may still be seen in Mach but shouldn't throw an error I don't think.
Title: Re: Home Signal
Post by: joeaverage on February 21, 2018, 01:32:51 AM
Hi,
Op's description of the problem is not that the home switch event causes a fault but every time it triggers it gets logged. If he happens to be using the axis
as a spindle the logfile becomes loaded with these events.

Craig
Title: Re: Home Signal
Post by: Chaoticone on February 21, 2018, 07:25:41 AM
OK, thanks Craig. I thought is was throwing an error.

Quote
Trying to stop the PMDX411 from throwing an 'C axis homing tripped' error message every revolution when using the spindle as a spindle.

I'll see what I can find out (hopefully today) about this.
Title: Re: Home Signal
Post by: joeaverage on February 21, 2018, 08:02:12 AM
Hi,
the error that OP referred to in the quote occurred if he disabled the homing signal.

OP would disable the C axis homing signal to prevent the log from filling up with notifications each revolution of the spindle.
Then the C axis did not have a correctly configured home switch and the 411 would object and throw a genuine error.

The challenge is to provide a programmatic means to have an indexing (C axis) OR a regular spindle without undesirable log entries when in spindle mode.

Craig
Title: Re: Home Signal
Post by: Steve Stallings on February 21, 2018, 08:45:10 AM
Everyone seems hell bent on solving this issue in software, while a very
simple hardware solution exists.

Since the operator has to stop to slip a timing belt on or off when changing
modes, it should be easy to have a switch in series with the offending home
signal from the sensor and using that the operator could use that to block the
signal so it would not fill the logs. You could even automate it by using the
RUN signal for the spindle to control a relay that switched the signal.

Title: Re: Home Signal
Post by: rhtuttle on February 21, 2018, 09:12:43 AM
But if I did that then I would have no spindle speed feedback and wouldn't be able to do threading.
Title: Re: Home Signal
Post by: Steve Stallings on February 21, 2018, 09:31:17 AM
If you have enough inputs you could feed the same signal to two inputs,
one for Home and one for Index. The switch would only kill the one for
Home.
Title: Re: Home Signal
Post by: joeaverage on February 21, 2018, 11:40:01 AM
Hi Steve,
yes, great idea.

Craig
Title: Re: Home Signal
Post by: rhtuttle on February 22, 2018, 10:48:58 AM
Steve, I think that I have one input left and that could work.  When the stepper is not engaged it is parked and I could put a NC switch that would open when parked against it.  Thanks for the idea.

RT