Hello Guest it is April 18, 2024, 06:53:06 AM

Author Topic: custom macro sequence in g code  (Read 6115 times)

0 Members and 1 Guest are viewing this topic.

custom macro sequence in g code
« on: January 30, 2008, 12:14:36 AM »
Hello to all,

My machine is a specialized pneumatic punch press machine that is controlled by a touchscreen (MACH3) and a G100.  It is basically just two axis and plenty of IO.  I have the touch screen interface plus a few buttons.  The G100 is connected to an Opto22 IO rack for interfacing the 24VDC IO.  Relays, fusesAll my IO works great. 

I am using custom macros that I have written for my machine.  I am getting better at writing macros and beleive that all my macros seem to work fine when called from the "diagnostics" screen.  Some of my macros are simply activating a signal... other macros set signals, wait for specific signals and then change other signals.

The M900X macros are used to turn off the respective output.
The M5010 retracts a cylinder and confirms this with specific sensors.
The M5011 Extends the cylinder and confirms this with sensors.
The M5062 is a bit more complex. 

I have two main problems. 
(1) The macros seem to occur out of sequence.  In the program below, the macro M021 is suppose to happen after the code G0 X1.0Y-1.  The problem is that it happens at basically the same time or even the macro happens first .  I need the code to go in order as I wrote it.  I added some code inside one macro to immediately enact a feedhold.. change the signal... wait for the sensors... change signals.... wait for sensors... press start button.  The code still seems out of sequence.  Is there some way to ensure that the macro happens after the g/m-code motion is stopped ... and the next g/m-code doesn't start until after the m-code is done.

G0 X1Y1
M5011
G0 X4Y1

The idea here is that I want to go to a specific position, stop, engage a clamp, move the part.  I tried this without the feedhold and restart commands.. but the macro wanted to engage the output while moving.  I added code to feedhold, but it basically looks like it holds the first g command.  I added the code to check for ismoving, but the macro appears to run before the first g-command.

(2) The call to subroutine doesn't run as expected.  (M98 P400 L17)  I added a beep in the M5062 macro to hear how many times it gets called.  It sounds like it runs 17 times (as expected), but it looks like there are only 9 movements.  I think this is another situation of how the macro is not running in the same time process as the g-code.  The acc/dec may be getting blended.

I would appreciate any help that would be offered.

Thank You,

Ray

(FILENAME: PUNCHTEST_SKEL.NC)

(MACHINE IS BY DEFAULT IN ABSOLUTE MODE)
G90

(CANCEL CUTTER COMP)
G40

(ENABLE LIGHT CURTAIN BYPASS)
M1008
(OPTIONAL STOP)
M01
(REMOVE LIGHT CURTAIN BYPASS)
(M9008)

(GOTO HOME/WAIT POSITION)
G0X0Y0

(Macro - ENTEND SHEET FEEDER)
M5011

(RAPID TO FIRST CLAMP POSITION)
G0 X1.0Y-1

(Close Gripper)
M5021

(Remove Sheet from feeder)
G1 X5 F200

(Macro - Retract Sheet Feeder)
M5010

(Go to LINE 1 START POSITION)
G0 X20 Y-2
M5062
(Macro - Punch and Retract)
M98 P400 L17

(Go to LINE 2 START POSITION)
G0 X20.3415 Y-1.5
M5062
(Macro - Punch and Retract)
M98 P400 L17

(ENSURE BACK TO ABSOLUTE MODE)
G90

(GO HOME)
G0X0Y0

(RESTART AT FIRST LINE)
M47

(SUBROUTINE FOR INCREMENT AND PUNCH)
O400
(CHANGE TO INCREMENTAL MODE)
G91
(MOVE)
G0 X-0.25
(PUNCH)
M5062
(BACK TO ABSOLUTE MODE)
G90
(RETURN FROM SUB)
M99

(NOTE AS LAST LINE)



The following is cut-paste from my most complex macros.

SUB M5062()
REM Extend and retract the Punch Cylinders
REM Cylinders controlled by a three position valve with two solenoids. Center blocked.

RetractOutput = OUTPUT5
ExtendOutput = OUTPUT6
ExtendedInput = INPUT4
RetractedInput = INPUT3

ActivateSignal(ExtendOutput)
REM *Activates solenoid valve to extend punch cylinders

DO WHILE NOT (ISACTIVE(ExtendedInput) and NOT ISACTIVE(RetractedInput))
LOOP

DeactivateSignal(ExtendOutput)
ActivateSignal(RetractOutput)
REM *Activates solenoid to retract punch cylinders

DO WHILE NOT (ISACTIVE(RetractedInput) and NOT ISACTIVE(ExtendedInput))
LOOP

REM * Cylinders have enough pressure to hold up while valve is closed.
DeactivateSignal(RetractOutput)

BEEP
END SUB


SUB M5011()
REM Extend Sheet Feeder
REM This macro is used to extend a cylinder controlled by a two position valve .. one solenoid.

WHILE ISMOVING
   REM * DELAYS THE CODE UNTILL PRIOR MOVEMENT IS COMPLETED
WEND

REM - CALL FOR BUTTON - FEED HOLD
DOOEMBUTTON (1001)

ExtendOutput = OUTPUT1
ExtendedInput = INPUT2
RetractedInput = INPUT1

ActivateSignal(ExtendOutput)
REM *Activates solenoid to extend cylinder

DO WHILE NOT (ISACTIVE(ExtendedInput) and NOT ISACTIVE(RetractedInput))
LOOP
REM *Meeting the desired senor states allows the macro to finish

DOOEMBUTTON (1000)
END SUB

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: custom macro sequence in g code
« Reply #1 on: January 30, 2008, 03:42:21 PM »
The problem is this you have some "While IsMoving()" statements that are not looking at positional movements.
I.e. A while is moving will work on a movement like command like G0 x1 or G4 p2....but it will NOT wait on things that dont actually move and axis.
Also, If I ma reading it right you are calling a macro sub from within your macro sub........
further: IF the non-movment commands (like cylinders extending, etc. not axis motion), are needing time, then you would be better re-writting your macros to use Pause statements to give the machine time to move the non axis things. Extimate how long in seconds it takes a cycinder to extend. at the End of that statement (with the pause gcode), do a check to see if your proxes show it is in position. If not then do a "Feed hold and scroll and error"

Scott
fun times