Hello Guest it is March 28, 2024, 05:28:40 PM

Author Topic: PMC Help  (Read 1089 times)

0 Members and 1 Guest are viewing this topic.

Offline gorf23

*
  •  183 183
    • View Profile
PMC Help
« on: July 05, 2019, 06:29:42 PM »
Is it possible to setup a PMC to turn on a relay and do a 50ms delay before and after the relay gets turned on?
and will it work if you have it turning on say macro m165() with spindleFwd relay to turn on in the macro?

and is there a way to test the PMC to see if it is working..

Thanks gary
Re: PMC Help
« Reply #1 on: July 05, 2019, 06:54:38 PM »
Hi Gary,
not quite sure what you are trying to achieve. Can you explain what it is you want to do?.

The PMC is really just a clever way to produce functioning C++ code, without having to know anything about C++.
Thus anything that you can do with C++ code, which basically means everything, C++ being the absolute basis
of the entire Mach4 program, can be done with PMC.

PMC may be the simplest way for you but then again it may not.

In most cases you can write Lua code to do the same thing and writing in Lua is a learning experience, not just about Lua
but the structure of Mach4. I suspect that even if writing Lua code is more difficult you will benefit from the learning
involved and will almost certainly result in a sense of satisfaction that other methods like PMC may miss.

I paraphrase a quote by Kennedy......'do this not because it is simple...but because it is hard'

You mention in your post running a macro and spindleFwd? If you are trying to get the spindle to turn on and off with
a given delay you might try experimenting with the spindle delay function built into Machs Control plugin.
This may prove simplest of all....at the risk of upsetting Kennedy's ghost.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: PMC Help
« Reply #2 on: July 05, 2019, 07:19:48 PM »
Hi Gary,
I just now recall that you had a thread going about using SSRs to reverse a spindle. Could this thread be related to producing
the required delay between operations such that the spindle decelerates BEFORE being switched in the other direction?

If that is the case I have some ideas that may help.

In particular all and every spindle operation is initiated by an m3 (or m4 if CCW). This is true when called from a Gcode program,
an MDI call to rotate the spindle or using the on screen <Spindle CW> (or <Spindle CCW>) button.

I would suggest that you write your own m3, m4 and m5 macros.

Normally m3, m4 and m5 are considered built in Mach macros which you can't altered...right? Well you can, if you write your own
m3  macro say, Mach will use your one in preference to its built-in macro. Mach does this by searching for a valid m3 macro
by in the first instance searching in your profiles macro folder. If it finds one it will use it. If not it will search higher up the search
tree until it fins the built in macro.

The trick is to write your own macro that contains all the Mach needs to operate normally, ie all the standard built in code, but also
any extra code that you want to do a specific thing. In this case the button codes (<Spindle CW> and <Spindle CCW>) are
available for your inspection. Thus being able to in the first instance duplicate, then subsequently modifying it is easy.

The essential benefit about writing your own m3, m4 and m5 is that it becomes fundamental behavior of your machine spindle,
at least with this profile, and that no matter how you turn the spindle on or off (Gcode, MDI, button) the delay will always
be there, not an extra thing you have to add in or otherwise think about.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline gorf23

*
  •  183 183
    • View Profile
Re: PMC Help
« Reply #3 on: July 05, 2019, 08:16:18 PM »
I did try to rewrite the m3  but it seemed to besides turning on the SpindleFWD it also was turning on the SpindleON at the same time here is a example of the code I started with.

function m3()
   inst = mc.mcGetInstance()

   local hReg = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEFWD)
   mc.mcSignalSetState(hReg, true) --Turn the output on
   
end

if (mc.mcInEditor() == 1) then
    m3()
end

Also I couldn't find a good way to put a delay in, didn't want to use the wx, call..

Gary
Re: PMC Help
« Reply #4 on: July 05, 2019, 09:00:35 PM »
Hi,
I think that you would have more success if you looked at the spindle API instructions.

You have changed the state of a signal (OSIG_SPINDLEFWD) which presumably is hooked to your spindle driver
and I would expect it to turn the spindle on. Does not 'spindle forward' imply that the spindle must also be turned on?
I suspect that Machs internal logic may be counteracting your intention.

May I suggest that you experiment with output signals 0 through 5; you can be assured that some internal logic is not
interfering with your desired sequence of operations. Secondly using those particular out siganals mean that the six LEDs
on the MachineDiagnostics tab display the signal current state.

It may well be that as a result of your experimentation you can shift the output signals to say #20-#22 say; leaving
#0-#5 free for 'playing with' later on. Or better still you may be able to unravel how Mach uses and interprets the
OSIG_SPINDLEFWD, OSIG_SPINDLEREV and OSIG_SINDLEON signals.

What you want is to set the spindle direction, a flag or variable, without also turning the spindle on. These APIs may help.

Code: [Select]
rc = mc.mcSpindleSetDirection(
number mInst,
number dir)

Description:
Set the desired spindle direction.

rc = mc.mcSpindleSetDirectionWait(
number mInst,
number dir)

Description:
Set the desired spindle direction and wait for the spindle to come to speed. The function will wait for up to 20 seconds before returning MERROR_TIMED_OUT.

The type of spindle wait is determined by the system configuration.

I confess that I don't know whether these will achieve the result you want. Does for instance setting the direction flag ALSO
cause the spindle to start? Some experimentation is in order.

No matter the result of the experimentation and whether a particular API works or not you need a logical set of steps.
I envisaged a logical structure something like this:
m3
1) if the spindle is stopped then turn it on CW.
2) if the spindle is on and in CW rotation....ignore m3
3) if the spindle is on and in CCW rotation......stop the spindle.....delay....start the spindle CW

m4
1) if the spindle is stopped then turn it on CCW.
2) if the spindle is on and in CCW rotation....ignore m4
3) if the spindle is on and in CW rotation......stop the spindle.....delay....start the spindle CCW

m5
1) if spindle is on....turn it off....delay before resuming operation
2) if spindle is stopped....ignore m5

If this looks reasonable to you THEN you can start looking at various APIs, macros, PMC scripts or whatever to enact
the desired scheme.

Quote
Also I couldn't find a good way to put a delay in, didn't want to use the wx, call..

Why not?

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline gorf23

*
  •  183 183
    • View Profile
Re: PMC Help
« Reply #5 on: July 06, 2019, 12:55:37 PM »
Thanks Craig

I will do some testing on your thoughts...

Ok here is how my relays are setup...

120v Relay1 turns on power to the spindle KB controller
DC Relay 1 and 4 turn on  Forward rotation they turn on together.
DC Relay 2 and 3 turn on  Reverse rotation they turn on together
120v Relay 2 turns on flood coolant

connecting to the ouput0 - 5 should be no problem I had the FWD REV original hooked to output0 and output1 then changed to SpindleFWD and spindleREV and if I remember right even when I was using the outout0 and 1, when I ran the M3 macro Spindle turned on also..

The Problem with the PCM is I confuse myself with the logic, i'm a little brain dead at times,,

The delay, I'm not sure what will work in a macro I tried timer event didn't seem to work timer didn't seem run  when I told it to timer:start()
I also placed a timer0 in the screen load script, and used a scr.StartTimer(0,30,1) didn't seem to work either

 Thanks gary

Offline gorf23

*
  •  183 183
    • View Profile
Re: PMC Help
« Reply #6 on: July 06, 2019, 07:10:03 PM »
Craig

This seems like it may work ok, the delays are to long but for testing script seems to work

Code: [Select]
function m3()

local inst, hSig, rc
inst = mc.mcGetInstance()

OnSig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON) -- Get handle for spindle forward output 0
if (rc~= 0) then --Check our return call
mc.mcCntlSetLastError(inst, "Spindle On Handle ERROR")
end
   
mc.mcCntlGcodeExecuteWait(inst, "G4 P1000")
rc = mc.mcSignalSetState(OnSig, 1) --turn on Spindle forward output 1
if (rc~= 0) then --Check our return call
mc.mcCntlSetLastError(inst, "Spindle On ERROR")
end

FWDSig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEFWD) -- Get handle for spindle forward output 0
if (rc~= 0) then --Check our return call
mc.mcCntlSetLastError(inst, "Spindle Forward Handle ERROR")
end

mc.mcCntlGcodeExecuteWait(inst, "G4 P1000")
rc = mc.mcSignalSetState(FWDSig, 1) --turn on Spindle forward output 1
if (rc~= 0) then --Check our return call
mc.mcCntlSetLastError(inst, "Spindle Forward ERROR")
end
end

if (mc.mcInEditor() == 1) then
    m3()
end

Gary