Computed O-numbers for indirect subroutine calls (returning float, not integer)

More
21 Dec 2016 16:18 #84495 by clunc
This is kind of cool. But then, I think I'm handsome...

I'm calling a subroutine to repeatedly cycle through a list of other subroutines, each describing a different, but similar model.

I have a bunch of models, all the same size and spec, but just of different subjects. Artsy, you know?

A calling program defines the stock and decides how many models will fit, and this cycler sub makes sure there's a different model in each spot.

I used the MODulus function on an incrementing "count" variable, to index into a list of numbered user parameters, to retrieve one of the integer values corresponding to numbered subroutine files.

Unfortunately, the calculation produces a float, instead of a pure integer; e.g., 203.000000 instead of 203, so I have to call with the awkward:
o203.000000 call
(and name the files to match. Actually, I just soft-link them.)

Q. Is there a way to "truncate" a float (by a workaround even) to an integer? (ROUND[] leaves the decimal places and nothing else seems quite to fit.)

I'll attach the subr in case anyone wants to take a look.
Attachments:

Please Log in or Create an account to join the conversation.

More
21 Dec 2016 16:45 #84500 by Todd Zuercher
No there is not a way to convert it to an integer. Parameter values are always floats, but it should not be a problem because it is perfectly acceptable to use a parameter to call a subroutine.
linuxcnc.org/docs/html/gcode/o-code.html#ocode:indirection
So if your sub program you want to call is named 123 you can call it with a parameter who's value is 123.000000.

Please Log in or Create an account to join the conversation.

More
21 Dec 2016 17:23 #84501 by clunc
Even more remarkable is that the file can be name 123.ngc, but inside can contain references to 123.000000:
o123.000000 sub
o123.000000 endsub

I forgot to edit them after renaming to check that 123.ngc could in fact be called with:
o123.000000 call
(It can, just as you said.)

However, I found that:
o123.100000 call
fails with "not an integer."

The documentation does not mention the integer requirement.

Thanks, Todd.

Please Log in or Create an account to join the conversation.

More
21 Dec 2016 17:31 #84502 by clunc
I meant to include a correction:

Earlier I wrote:
"...(and name the files to match. Actually, I just soft-link them.)"

I don't think that works, quite.[1] I think it follows the link, but ultimately decides whether the subr meets naming requirements by the ultimate filename. I may have been fooled by an unacceptable link pointing to an acceptable filename.

[1] Indeed I just checked. I had 2081.000000.ngc as a soft link pointing to file M208.1.ngc. The linkname matched requirements, and sub references inside M208.1.ngc were to 2081.000000. However M208.1 does not match 2081.000000.

I did a hard copy of the link to a real file (cp -L 2081.000000.ngc 2081.ngc), and left the internal references at 2081.000000, and LinuxCNC had no trouble with it at all.

With all this indirection however, AXIS is not going to show me how it's all going to lay out in advance however. :^(

Please Log in or Create an account to join the conversation.

More
21 Dec 2016 17:40 #84503 by clunc
An easier way to do this, for simple code, is to make a 'switch' statements out of IF/ELSEIF/ENDIF

#<_count>=1
o100 do
#<idx>=[#<_count> MOD 3]
o101 if [#<idx> EQ 0]
o1000 call
o101 elseif [#<idx> EQ 1]
o2000 call
o101 else
o3000 call
o101 endif
#<_count>=#<_count>+1
o100 while [#<_count> < 10]

However, as my "model-placement" is already complicated and this would require posting this code at every location a model is wanted. The subroutine also makes it easier to edit the list of model routines to be called.

Okay, that's it.

Please Log in or Create an account to join the conversation.

More
21 Dec 2016 17:52 #84506 by clunc
...not quite, it.

One more error to correct:
"With all this indirection however, AXIS is not going to show me how it's all going to lay out in advance however. :^( "

Not true. After I got rid of my last mistake, all models appear, properly placed, and properly chosen from the list in AXIS.

Please Log in or Create an account to join the conversation.

Time to create page: 0.314 seconds
Powered by Kunena Forum