![]() | |
| Home Page | Mark Forums Read | Today's Posts | My Replies | Classifieds | Reviews | Photo Gallery | Web Links | Share Files | Advertise With Us | Ad List |
| |||||||
| Fanuc Discuss Fanuc controllers here! |
| This forum is sponsored by: |
![]() |
| | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
| ||||
| ||||
Hi all, is there a simple way to activate an M code using an IF statement? I'm attempting to modify an existing logic program at my workplace so that an operator may set a local variable in a main program to activate/deactivate mirroring (X and A axis) when executing the associated subprograms. Several thousand existing programs will be affected by this so I am attempting to keep edits to a minimum. abbreviated example: % O1000 (MAIN PROGRAM) G65P2001A.....D1. (D0. FOR MIRRORING OFF, D1. FOR MIRRORING ON) ... % % O2001 (SUB PROGRAM) .... IF[#4EQ1]M21 (X MIRROR ON) IF[#4EQ1]M16 (A MIRROR ON) X0.Y0.A.Z1. .... M99 % I know this doesn't work but it does illustrate what I am trying to accomplish with the IF conditional. Is there a way to do this without adding reference to a sequence number like the following: i.e. % O2001 (SUB PROGRAM) .... IF[#4EQ1]GOTO10 M21 M16 N10 X0.Y0.A.Z1. .... M99 % I'm new to the macro game so take it easy on me! Thank you in advance for any tips. Nick |
|
#2
| ||||
| ||||
| % O2001 (SUB PROGRAM) .... IF[#4NE1]GOTO10 M21 (X MIRROR ON) 10 ; ; IF[#4NE1]GOTO20 M16 (A MIRROR ON) X0.Y0.A.Z1. 20 .... M99 % OR % O2001 (SUB PROGRAM) .... IF[#4NE1]GOTO10 M21 (X MIRROR ON) M16 (A MIRROR ON) 10 .... M99 %
__________________ *********************************************************** *~~Darwinian Man, though well-behaved, At best is only a monkey shaved!~~* *********************************************************** *__________If you feel inclined to pay for the support you receive__________* *_______Please give to charity http://www.oxfam.org/en/getinvolved_______* *********************************************************** |
|
#3
| ||||
| ||||
| no need to edit any program. Set two custom macro called by M code. One by M16 an other by M21. On my 0MD its is prm#230 to #239 to call macro 9020 to 9029. Asume that you set prm #231 to 16 and prm#232 to 21. So each time M16 appear, it call macro 9021 and each time M21 appear, it call macro 9022. You just have to dedicate 2 variables that can be set manually. Say #501 for M16 and #502 for M21 (i choose Variable in the 500's cause they remain after power off) O9021 IF [#501 EQ 0] GOTO 10 IF [#501 EQ 1] GOTO 20 #3000=1(#500 WRONG VALUE) N10 M99 N20 M16 M99 O9022 IF [#502 EQ 0] GOTO 10 IF [#502 EQ 1] GOTO 20 #3000=1(#500 WRONG VALUE) N10 M99 N20 M21 M99 We could think that M16 or M21 code inside the macro will recall the macro, but not. It will be executed as it should be inside the macro. #501 and #502 can be set manually or in the main program. |
|
#4
| ||||
| ||||
__________________ *********************************************************** *~~Darwinian Man, though well-behaved, At best is only a monkey shaved!~~* *********************************************************** *__________If you feel inclined to pay for the support you receive__________* *_______Please give to charity http://www.oxfam.org/en/getinvolved_______* *********************************************************** |
|
#5
| ||||
| ||||
| Thanks guys, I appreciate your input. I'm forced to be very picky about how I do this because it needs to be completely idiot proof for the operator. A single incorrectly machined product will cost many thousand $$ to repair/replace. I think I've found a way to accomplish what I need. I'm currently proving this out for different scenarios in my spare time before I implement. I will post what I have come up with after I know it works properly. Thanks again, great forum! |
| Sponsored Links |
|
#6
| |||
| |||
| answer to original question; (DEFAULT= MIRROR OFF) #30=20(M20,X MIRROR OFF) #31=15(M15,A MIRROR OFF) IF[#4EQ1]THEN#30=21 (X MIRROR ON) IF[#4EQ1]THEN#31=16 (A MIRROR ON) M#30 M#31 ... M99 Last edited by norbert.barnard; 07-19-2010 at 09:50 AM. Reason: typing error |
|
#7
| ||||
| ||||
| That "if/then" should work. Be aware that #4 will be reset to zero when reset is pushed. The 500 + variables retain their value even when the machine is shut off. 100-199 don't, but retain their values if you reset the control. |
|
#8
| |||
| |||
| The format of IF_THEN_ is IF<a conditional expression>THEN<a macro statement>; An M-code is an NC statement, hence it is not allowed. Some alternate methods have already been suggested. |
|
#9
| |||
| |||
| i recommend familiarizing yourself with the parameters available on your control before you assume ANYTHING... for example, beware when someone suggests the way your machine will act, like what your variables #1-33, #100-149, #500-999 will do when reset is pressed or M30 is reached... as this is customizable via parameters and will not necessarily be the same on all of the same control Code: 6001 CCV Custom macro’s common variables Nos. 100 through 149 0: Cleared to “vacant” by reset 1: Not cleared by reset CLV Custom macro’s local variables Nos. 1 through 33 0: Cleared to “vacant” by reset 1: Not cleared by reset Code: 3402 CLR Reset button on the CRT/MDI panel, external reset signal, reset and rewind signal, and emergency stop signal 0 : Cause reset state. 1 : Cause clear state. so read the parameter manual so you at least know what is variable... setting as much the same as i could on all my machines (9 mills of 6 MTB's and with 7 different controls) has really helped my ability to make custom posts, macros, and procedures that apply everywhere in the shop - gwarble |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Conditional and Loop Statements in Mach3 | Monotoba | LittleMachineShop CNC Machines | 5 | 04-24-2010 09:12 PM |
| Conditional gcode execution in Mach3 | bobeson | Tormach PCNC | 5 | 12-13-2009 08:39 PM |
| Conditional loop problem | eagle73 | Controller & Computer Solutions | 0 | 12-19-2008 04:14 PM |
| Activation switch question | Toolmaker | General Electronics Discussion | 6 | 11-28-2005 02:28 PM |