I am trying to figure out how to programmatically set, with Mathematica, the rotationType parameter in a Modelica.Mechanics.MultiBody.Parts.FixedRotation.
This is a snippet of my code where topMdlName is the name of the model, tNames4Modelica is a list of names of FixedRotation transforms in the model, and tCnt is the number of transforms.
The function, obviously, writes strings to the model and the Simulation Center stops on an error that asserts that the value of the parameter is a string and not the expected enumeration.
I know that the value of the rotationType parameter is a Modelica enumeration as explained in the documentation
type RotationTypes = enumeration(RotationAxis "Rotating frame\_a around an angle with a fixed axis", TwoAxesVectors "Resolve two vectors of frame\_b in frame\_a", PlanarRotationSequence "Planar rotation sequence") "Enumeration defining in which way the fixed orientation of frame\_b with respect to frame_a is specified" annotation(Documentation(Evaluate = true, info = "<html>
but I cannot find a way to set it in Mathematica.
I have read the SetSystemModel help pages and searched the interwebs to no avail. So I am writing to ask for help either for a pointer to documentation or a workaround.
A wrapper that allows the value setting functions to see a string as a component identifier is QuantityVariable. QuantityVariable, when representing a variable, has two arguments. For the first, we use the identifier string. Conventionally, the second argument is a physical quantity, but in this case you can use a generic IndependentPhysicalQuantity[""]. So your parameter can be added as
SystemModel::irl: The list of rules is not on the form {“variable” → numericValue, …}.
If my syntax is correct then there might be some unexpected behavior from SetSystemModel for enumeration types. I wonder if it’s a bug that I should report.
To make progress on my project I have worked around the problem like so: after all model parameters are set: 1) assign the "Modelica.Mechanics.MultiBody.Types.RotationTypes. PlanarRotationSequence" string to all rotationType parameters, 2) extract the ModelicaString of the model; 3) find the string position of all rotationType; 4) remove the enclosing double quotes " and 5) save the ModelicaString to a text file of extension type .mo. It ain’t pretty but it gets the job done.
If it’s of any help I am using Matematica 12.1.0.0 and SystemModeler 12.2.0, build 8. I cannot update to Mathematica 12.2 because it has other bugs that crash other notebooks.
I see, this is something that certainly works in the more recent versions, now that we have given more attention to other types of value setting like in enumerations. There are a couple of options. We could first try something like this that may have worked in 12.1,
Try this association in either SetSystemModel or possibly in the ConnectSystemModelComponents call, which may have already been supported at the the time.