[Mi...] Posted October 1, 2021 Share Posted October 1, 2021 Months ago I asked about using the CMM to check it's position, when I barely understood PCM, now I have a better grasp after diving head first into making the CMM do things it's not quite meant to do... I am curious about the getParameterNamed() function though.... When I was asked, I was basically given this parkPos=vector(450.0,-125.0,-50.0) x=getParameterNamed(getPositionCMM().rounded - parkPos).x y=getParameterNamed(getPositionCMM().rounded - parkPos).y z=getParameterNamed(getPositionCMM().rounded - parkPos).z maxdev=max(abs(x),abs(y),abs(z)) It works just fine, but I was going back over old work trying to improve, and don't really understand what getParameterNamed() is doing, or why I would want to use it instead of just doing this: parkPos=vector(450.0,-25.0,-50.0) x=getPositionCMM().x.rounded - parkPos.x y=getPositionCMM().y.rounded - parkPos.y z=getPositionCMM().z.rounded - parkPos.z maxdev=max(abs(x),abs(y),abs(z)) I've tried asking other programmers and I either get shrugs, or told it's pulling info from the controller and is dangerous ( not likely) Could somebody dumb down the purpose of getParameterNamed()? Link to comment Share on other sites More sharing options...
[Is...] Posted October 3, 2021 Share Posted October 3, 2021 ... Link to comment Share on other sites More sharing options...
[No...] Posted October 4, 2021 Share Posted October 4, 2021 The explanation is quite simple: getParameterNamed allows you to use dynamic parameter names. Imagine you have a series of parameters named with incrementing numbers: diameter1 diameter2 diamater3 diameter4 .... Now you want to read the values of these parameters in a loop by using the loop counter in the parameter name. How would you do that? With normal PCM functions you can't just write "diameter" + i (or better "diameter + text(i) ), but need to write an explicit parameter name. The solution is getParameterNamed. With it you can "build" a parameter name from the content of variables etc. and then use it in a function as if it was a normal parameter name. If you know Excel functions, it's similar to the function INDIRECT(). Link to comment Share on other sites More sharing options...
[Is...] Posted October 4, 2021 Share Posted October 4, 2021 ... Link to comment Share on other sites More sharing options...
[Mi...] Posted October 4, 2021 Author Share Posted October 4, 2021 Thank you both, now it's clear! Link to comment Share on other sites More sharing options...
[Me...] Posted October 5, 2021 Share Posted October 5, 2021 You can reduce the number of lines in your code by using it.... parkPos = vector(450, -125, -50) maxDev = getParameterNamed(getPositionCMM() - parkPos).rounded.abs.maxValue Link to comment Share on other sites More sharing options...
[Mi...] Posted November 4, 2021 Author Share Posted November 4, 2021 Expansion on this question.... setParameterNamed() seemed more correct in this case but... index = 1 variable_name = "test_" for index = 16 to 30 setParameterNamed(variable_name+index,getActual("Space "+index+" Index Error Calc Point").y) next index This is doing what I want, gives me variables test_16 through test_30, and assigns them the correct number value. But now I want the min and max of those values... and I'm just not getting that. Also, the point numbers ill be using this for in the real situation have an uneven distribution. So I can’t just set the step, is there a way to say, “16 to 30 and 41 to 50” etc? or will I need to use a couple loops/manually type the list? Thanks! Link to comment Share on other sites More sharing options...
[Is...] Posted November 9, 2021 Share Posted November 9, 2021 you have a Loop there anyway just put a condition: variable_name = "test_" maxval=-999 for index = 16 to 30 setParameterNamed(variable_name+index,getActual("Space "+index+" Index Error Calc Point").y) if maxval < (getActual("Space "+index+" Index Error Calc Point").y) then maxval = (getActual("Space "+index+" Index Error Calc Point").y) endif next index Link to comment Share on other sites More sharing options...
[Is...] Posted November 9, 2021 Share Posted November 9, 2021 of course there are many other options: variable_name = "test_" items="" for index = 16 to 30 setParameterNamed(variable_name+index,getActual("Space "+index+" Index Error Calc Point").y) items=items + "," + variable_name+index next index display("Max Value: " + compute("max(" + compute( "mid(items,2,len(items))" ) + ")") ) Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in