Parameters

More
07 Nov 2013 01:42 #40595 by grey1beard
Parameters was created by grey1beard
Is there a way to use an XY position as a parameter ?
For example, is there a way to give the position X[5] Y[10] as #1, and X[6] Y[15] as #2
I presume that #1 = <x[5]y[10]> doesn't work, nor #1 = <x[5]_y[10]> likewise ?

John

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

More
07 Nov 2013 02:29 #40599 by BigJohnT
Replied by BigJohnT on topic Parameters
No, you can only pass numbers as a parameter.

What are you trying to do?

JT

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

More
07 Nov 2013 05:30 #40610 by grey1beard
Replied by grey1beard on topic Parameters
What I'd like to be able to do is write lines of g code where a particular pair of XY values equated to a single musical note being played by a musical automaton.
For example, if
G01 x[55] y[60]
took the arm to be above the F strings, and
G01 x[55 + #4] y[60 + #5]
took it on to the F#, and
G01 x[55+[12*#4]] y[60+[12*#5]]
sends it up an octave to top F, it would be nice to be able to indicate the value of X for the particular note more compactly in the form of a single parameter.
I can see that I'm trying to get one parameter to indicate two different axis at the same time, so I suspect it's time to draw a line under that train of thought.
J

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

More
17 Jan 2014 04:33 - 17 Jan 2014 04:34 #42890 by clunc
Replied by clunc on topic Parameters
This is probably nuts, but I'm thinking "Subroutine" or "tines".

Playsub(Xposn,Yposn)
take the arm to Xposn,Yposn
bang it
do something else (maybe call OctaveSub to play an octave higher)
endsub

And the G-code "player" is a sequence of calls to the subroutine(s) with appropriate values of XY.
Last edit: 17 Jan 2014 04:34 by clunc. Reason: nuts sounds better to my sophisticated eye

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

More
17 Jan 2014 09:32 #42900 by clunc
Replied by clunc on topic Parameters
grey1beard,

I don't have a clear picture, but will throw out a couple of things to maybe make you think in a new direction.

You asked:
> For example, is there a way to give the position X[5] Y[10] as #1, and X[6] Y[15] as #2?

I wonder.

If X and Y were each bounded, and you had enough vars at your disposal, you store both as a single "code" value by some formal; e.g., X[5]Y[10] is stored as 5.1099999 and X[6]Y[15] as 6.1599999, presuming no negative numbers. Negative numbers might be handled by adding a very large number to each first 999990000000000 to each before converting. How about -5.1109999 to represent X[-5]Y[-10]? The problem of saving X[-5.1]Y[-5.1] is left as an exercise to the math professors who are reading this, while looking for help with the CNC machines they built for relaxation. I wonder if "prime numbers" would help... but I diva...

I also stumbled on this in this:
linuxcnc.org/docs/html/gcode/overview.ht...umbered_parameters_a
which refers to what in programming circles is called pointer arithmetic, and indirect pointers.

"Of course, #[1+2] does mean the value found in parameter 3. The # character may be repeated; for example ##2 means the value of the parameter whose index is the (integer) value of parameter 2."

This suggests that it might be possible to create an "indexed" array of say R rows and C columns, stored as a 1-dimensional array, also common with programmers. A single number "index" i refers to a single element of the array; if the index is less than R, it is in the first row: it's position being given by the column its in. So in that case, the i-th element is in Row0,ColC: one number indicates 2.

If i is larger than R, multiples of C are subracted from i (corresponding to the number of rows that have to be traversed, each of length C) before the remainder is a number less than R, after which you know it's the "i-th element of the array refers to the element in ColC of RowR.

So you'd be treating X and Y positions as R and C into an array, computing an I and storing something in #<I>.

Moving to the last bit, about ##2, it's easy for mere mortals to grasp WHAT it is, but hard to conceive how it's to be used. It's an "indirect parameter" which says, "fetch the contents of param #2, and interpret that as the number of ANOTHER parameter and fetch the contents from there to get the value". Right away you can guess that storing non-positive integers or floats would be bad for a ## use, but consider storing the number 5420 in #2, and reading it out and iterating. ##2 would give you the value of whatever's stored in #5420, which happens to be current X, after iterating #2=[#2+1] , the same expression ##2 would now give you the value of Y.

Anyway I hope this helps--even if only to give you some much-need shuteye.

Cheerio,

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

More
17 Jan 2014 16:24 #42908 by newbynobi
Replied by newbynobi on topic Parameters
Why not make a subroutine for every note?

than you would program:

call play_note_c [1] [200] [4]

the parameters in the sub would be
#1 = Oktave to play
#2 = Dwell between repeats
#3 = repeats

so the example will play 4 time the c in the first octave with a delay of 200 ms inbetween each note.

You just have to make subroutines for each note and in everey sub you look for the octave and call a different sub in the sub,

Norbert

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

More
17 Jan 2014 22:16 #42921 by andypugh
Replied by andypugh on topic Parameters

For example, is there a way to give the position X[5] Y[10] as #1, and X[6] Y[15] as #2


Yes, sort of.

#11 = 5
#31 = 10
#12 = 6
#32 = 6

O<mysub>call [1] [2]

O<mysub> sub
G0 X#[#1 + 10] Y#[#1 + 30] U#[#2 + 10] V#[#2 + 30]

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

More
18 Jan 2014 01:17 - 18 Jan 2014 01:18 #42930 by clunc
Replied by clunc on topic Parameters
I went off of this:

...it would be nice to be able to indicate the value of X for the particular note more compactly in the form of a single parameter.

and based on later information that it's to play music, I think it wants something like the following.

(main program)
(define a table of XY pairs for all the notes to be played, odd numbers are the Xposn, evens the Yposn)
( to necessary to play each note)
(88*2 ought to be enough for all the notes of a piano, ymmv)
(I put the table out here in main so it would be loaded once and not EACH time the sub is called)
#1= ; Xposn to play lowest note
#2= ; Yposn to play lowest note
#3= ; Xposn to play 2nd-lowest note
...
#175= ; Xposn to play highest note
#176= ; Yposn to play highest note

(define a set of "memorable" params to "point to" the top of each note pair)
( you will call sub with ONLY these, odd, numbers)
#<_C_OCTAVE0>=1 ; or whatever lowest note and octave are ; global so sub can read them
#<_Cs_OCTAVE0>=3
...
#<_F_OCTAVEn>=175 ; or whatever highest note and octave are

#<_MIDDLEC>=2500 ; every note has an EVEN number (something tells me 88 ought to be enough...)
O<mysub> call [#<_C_OCTAVE0>]

O<mysub> sub
(check that #1 is an odd number, else complain and stop)
(the parameter passed-in is the ADDRESS-OF a parameter pair containing)
( the Xposn, Yposn to play a note)
G0 X[##1] Y[#[#1+1]] ; go to (contents of #1 and #2 in main)
G91 G0 Z#<hammerdepth> F#<hammerspeed>
(dwell)
G91 G0 Z#<hammerdepth> F#<rapid>
O<mysub> endsub

...or something like it.
Last edit: 18 Jan 2014 01:18 by clunc. Reason: add clarif.

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

Time to create page: 0.102 seconds
Powered by Kunena Forum