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 > G-Code Programing > Parametric Programing


Parametric Programing (custom macro b, fadal macro, okuma user task)


This forum is sponsored by:

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Ban this user!
Old 02-24-2009, 05:28 PM
 
Join Date: Jan 2008
Location: usa
Posts: 58
gravy is on a distinguished road
using a counter

I've used a variable as a counter in a number of macros to control the number of times things are done, in what order, etc.. Like in the logic below which does a macro at different places in X, the first at zero, the second at 6.5, third 16., fourth 22.5. (These are vise stops)


N1
G65 P20
#101=[#101+1.] (increment counter)
IF[#101EQ1.]THEN[#102=6.5]
IF[#101EQ2.]THEN[#102=16.]
IF[#101EQ3.]THEN[#102=22.5]
G52 X#102
GOTO1

What I'm wondering is if this is something where the limitations of binary arithmetic will eventually burn me. If I'm doing a bunch of math in a macro it seems to be an issue but just doing a counter seems to work. Am I just lucky?
Tweet this Post!Share on Facebook
Reply With Quote

  #2   Ban this user!
Old 02-24-2009, 08:58 PM
 
Join Date: Jan 2007
Location: USA
Posts: 355
Eurisko is on a distinguished road

Checking for equalities with floating point numbers can be a little tricky. However, your counters are essentially integers, and that's a different story.

As long as the counter is properly initialized, and is checked for a terminal value at each iteration, you should be fine.

I would also use a default (harmless) value for #102. If none of the comparisons succeed, what is the value of #102 ?
__________________
Diplomacy is the art of saying "Nice doggie" until you can find a rock. - Will Rogers
Tweet this Post!Share on Facebook
Reply With Quote

  #3   Ban this user!
Old 02-26-2009, 05:57 AM
 
Join Date: Jan 2008
Location: usa
Posts: 58
gravy is on a distinguished road

Originally Posted by Eurisko View Post
Checking for equalities with floating point numbers can be a little tricky. However, your counters are essentially integers, and that's a different story.

As long as the counter is properly initialized, and is checked for a terminal value at each iteration, you should be fine.

I would also use a default (harmless) value for #102. If none of the comparisons succeed, what is the value of #102 ?
Quick questions on break here.

What do you mean "terminal value"? So integers pretty much always succeed?

Thanks for your help!
Tweet this Post!Share on Facebook
Reply With Quote

  #4   Ban this user!
Old 02-26-2009, 06:29 PM
 
Join Date: Jan 2007
Location: USA
Posts: 355
Eurisko is on a distinguished road

Originally Posted by gravy View Post
...What do you mean "terminal value"?...
A terminal value would be the first invalid count that the routine sees.

If you're using 3 vise stops, the value of the counter can only be 1, 2 or 3.
If the counter increments to 4, your program has to recognize that and take the appropriate (terminating) action.

Originally Posted by gravy View Post
...So integers pretty much always succeed? ...
It is still a floating-point representation of an integer. It is valid only if the "integer" doesn't exceed the physical limits of the control. For example, If the control is capable of 12 significant digits, that would limit the size of the integer. You can calculate incredibly large or small numbers, but only the significant digits are stored. 3.02178362898 E +200 would truncate a LOT of digits.

The problem with comparing floating point numbers is due to these limits of precision (and rounding). Hope this makes sense.
__________________
Diplomacy is the art of saying "Nice doggie" until you can find a rock. - Will Rogers
Tweet this Post!Share on Facebook
Reply With Quote

  #5   Ban this user!
Old 02-26-2009, 07:19 PM
 
Join Date: Jan 2008
Location: usa
Posts: 58
gravy is on a distinguished road

Originally Posted by Eurisko View Post
A terminal value would be the first invalid count that the routine sees.

If you're using 3 vise stops, the value of the counter can only be 1, 2 or 3.
If the counter increments to 4, your program has to recognize that and take the appropriate (terminating) action.


It is still a floating-point representation of an integer. It is valid only if the "integer" doesn't exceed the physical limits of the control. For example, If the control is capable of 12 significant digits, that would limit the size of the integer. You can calculate incredibly large or small numbers, but only the significant digits are stored. 3.02178362898 E +200 would truncate a LOT of digits.

The problem with comparing floating point numbers is due to these limits of precision (and rounding). Hope this makes sense.

I just thought of this. If it is really a problem I could do this

#101=[#101+.1]
#101=FIX[#101]

before the IF THEN statements to first make the numbers greater than the target integer and then truncate them.

That's a lot of trouble. Is it really necessary do you think?
Tweet this Post!Share on Facebook
Reply With Quote

Sponsored Links
  #6   Ban this user!
Old 02-26-2009, 07:48 PM
 
Join Date: Jan 2007
Location: USA
Posts: 355
Eurisko is on a distinguished road

Originally Posted by gravy View Post
I just thought of this. If it is really a problem I could do this

#101=[#101+.1]
#101=FIX[#101]

before the IF THEN statements to first make the numbers greater than the target integer and then truncate them.

That's a lot of trouble. Is it really necessary do you think?
Don't do it. Your counters will work fine just by incrementing them. The control will have no problem adding 1 to a small integer. It will have no problem comparing 2 small integers. Precision won't be a problem.
__________________
Diplomacy is the art of saying "Nice doggie" until you can find a rock. - Will Rogers
Tweet this Post!Share on Facebook
Reply With Quote

  #7   Ban this user!
Old 03-03-2009, 09:12 AM
 
Join Date: Jun 2008
Location: United States
Posts: 1,503
stevo1 is on a distinguished road

Gravy,
What Eurisko is referring to on "if the comparisons don’t succeed" is how do you end the program. If you come out of your program 20 sub on vise #3 this means that #101=3. Now when it runs through your calculations it get’s set #101=4. You have no X#102 value or equation programmed for #101 if it’s set to 4 so you would run the same vise(3) over and over again.

I would stick a calculation in the program so when your 3 vises are complete then the program ends.

N1
G65 P20
#101=[#101+1.] (increment counter)
IF[#101EQ1.]THEN[#102=6.5]
IF[#101EQ2.]THEN[#102=16.]
IF[#101EQ3.]THEN[#102=22.5]
IF[#101GT3.]GOTO2
G52 X#102
GOTO1
N2M30

Ahhhh the joys of floating point math. This just burned me about 6 months ago. I write a lot of extensive macros and never had a problem until I came to this new place. I was writing a C-bore macro and the data would show equal to each other when viewing the variable settings but it would not jump out of the loop of the macro. An example of what Eurisko is referring to is:
I was using #2 as a counter but this counter was adding the pick. And at the end the last pick could be any amount past the decimal 0.xxxxxxxxxx. I set #1 as a hard number for #2 to be equal to and end.

#1=2.
N1
IF[#2GE#1]GOTO100


#2=#2+.039
GOTO1
N100M30

My problem was that even though #2 would read 2. It was actually 1.999999999999999 so it never jumped out of the loop until the next pass. So the fix was to add a rounding function in the program. This would round the 1.99xxx number to the placement that I wanted which was .xxxx

#25=10000(ROUNDING)
#1=2.
N1
IF[ROUND[[#2*#25]/#25]GE#1]GOTO100


#2=#2+.039
GOTO1
N100M30

(these numbers are just examples they don’t actually add up to the 1.9)

Stevo
Tweet this Post!Share on Facebook
Reply With Quote

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
Parts Counter HelicopterJohn Haas Mills 4 04-20-2008 12:05 PM
UP/DOWN COUNTER Elijah Turner General Electronics Discussion 8 02-01-2008 11:10 AM
Parts counter daewooevc Daewoo/Doosan 1 11-01-2006 09:38 AM
Parts counter daewooevc Mazak, Mitsubishi, Mazatrol 1 10-26-2006 05:36 PM
counter cncsdr Haas Mills 2 11-08-2005 08:56 AM




All times are GMT -5. The time now is 01:26 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