Ability to determine object model or array element type
-
While playing with the new user defined array functionality, a couple of things have cropped up.
Lets say I have created an array in which one of the elements is itself an array
global.myArray={1,2,{6,7,8,9,},4,}
If I were then to issuemax(global.myArray)
, I would get an error that one of the values is not numeric which is entirely expected.
But there doesn't seem to be any programmatic method of determining the data type of an array element or object model element.Would it be possible to introduce a function that exposes the
GetType()
function that the firmware seems to use?That would allow us to evaluate each element of an array and act accordingly.
for examplevar maxValue = 0 var thisValue while iterations > #global.myArray if getType(global.myArray[iterations]) = Array var thisValue = max(global.myArray[iterations]) else var thisValue = global.myArray[iterations] if var.thisValue > var.maxValue var.maxValue = var.thisValue echo "Max in all array values is", maxValue
Yes, I know I should check if all the elements are numeric before using max() , but I can't without a getType() function
It would also help debug errors in macros such as I had recently when trying to use the returned value from
move.axes[iterations].drivers[0]
to programmatically identify which axis was giving an error (by letter)
On my duet to, the returned value "looks" like an integer, but I have since found out it is a driverID type and there is no type conversion to integer.
soif param.D = move.axes[0].drivers[0]
gives an error.
Being able to determine the returned value type won't make that work, but it would help stop me pulling out the dwindling hair supplies I have when it doesn't work as expected.I'm grateful for the addition of arrays and I realise that conditional gcode is only a tiny subset of an actual programming language, so at times it's just on us to know what data we have used.
But is is a wish list right?I guess my particular example also opens the question of whether max() and min() should also evaluate arrays within arrays, but I think it's a separate question.
-
@OwenD I'm having the same issue. Maybe the isnan function could be adjusted so it returns false for an array instead of throwing an error.
-
@DonStauffer @OwenD please submit a feature request at https://github.com/Duet3D/RepRapFirmware/issues.
-
@dc42 Done. ##986