CNCzone.com-The Largest Machinist Community on the net!



Home Page Mark Forums Read Today's Posts My Replies Classifieds Reviews Photo Gallery Web Links Share Files Advertise With Us Ad List
Go Back   CNCzone.com-The Largest Machinist Community on the net! > Machine Controllers Software and Solutions > Fanuc


Fanuc Discuss Fanuc controllers here!


This forum is sponsored by:

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Ban this user!
Old 05-24-2010, 11:09 AM
nwlynn's Avatar  
Join Date: Jan 2010
Location: USA
Age: 27
Posts: 2
nwlynn is on a distinguished road
Conditional M-code activation

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
Reply With Quote

  #2   Ban this user!
Old 05-25-2010, 11:53 PM
MysticMonkey's Avatar  
Join Date: Mar 2009
Location: Australia
Posts: 366
MysticMonkey is on a distinguished road

%
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_______*
***********************************************************
Reply With Quote

  #3   Ban this user!
Old 05-26-2010, 01:14 PM
samu's Avatar  
Join Date: Feb 2007
Location: quebec
Posts: 216
samu is on a distinguished road

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.
Reply With Quote

  #4   Ban this user!
Old 05-26-2010, 11:42 PM
MysticMonkey's Avatar  
Join Date: Mar 2009
Location: Australia
Posts: 366
MysticMonkey is on a distinguished road

Originally Posted by samu View Post
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.
He asked if there was a way to run an m-code with out using a subprogram
__________________
***********************************************************
*~~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_______*
***********************************************************
Reply With Quote

  #5   Ban this user!
Old 06-01-2010, 07:26 AM
nwlynn's Avatar  
Join Date: Jan 2010
Location: USA
Age: 27
Posts: 2
nwlynn is on a distinguished road

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!
Reply With Quote

Sponsored Links
  #6   Ban this user!
Old 07-19-2010, 09:48 AM
 
Join Date: Jul 2010
Location: south africa
Posts: 23
norbert.barnard is on a distinguished road

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
Reply With Quote

  #7   Ban this user!
Old 07-19-2010, 04:53 PM
beege's Avatar  
Join Date: Feb 2008
Location: USA
Posts: 518
beege is on a distinguished road

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.
Reply With Quote

  #8   Ban this user!
Old 07-20-2010, 05:09 AM
 
Join Date: Feb 2006
Location: india
Posts: 1,187
sinha_nsit is on a distinguished road

Originally Posted by nwlynn View Post
...
...
IF[#4EQ1]M21
IF[#4EQ1]M16
...
...
I know this doesn't work but it does illustrate what I am trying to accomplish with the IF conditional.
Since you are new to macro programming, you may not be knowing why it does not work (with or without THEN, which you missed).
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.
Reply With Quote

  #9   Ban this user!
Old 08-01-2010, 12:49 PM
 
Join Date: Jan 2010
Location: usa
Posts: 89
gwarble is on a distinguished road

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
even what your reset button does ("reset" or "clear", look it up) will not even necessarily be the same...

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.
there's even a parameter for allowing conditional gotos or not... or at least somewhat related from what i remember...

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
Reply With Quote

  #10   Ban this user!
Old 08-02-2010, 01:56 AM
 
Join Date: Feb 2006
Location: india
Posts: 1,187
sinha_nsit is on a distinguished road

Moreover, you need to seriously read programming books/manuals.
Reply With Quote

Sponsored Links
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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




All times are GMT -5. The time now is 04:14 PM.





Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO
Template-Modifications by TMS

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361