robotology / gazebo-fmi

FMI import plugins for the Gazebo Simulator.
GNU Lesser General Public License v3.0
23 stars 5 forks source link

Simplify variable naming configuration #32

Closed traversaro closed 5 years ago

traversaro commented 5 years ago

At the moment, we need to explictly specify the variable names in each fmu, as in:

  <plugin name="fmi_actuator_plugin" filename="libFMIActuatorPlugin.so">
    <actuator>
      <name>actuator_0</name> 
      <joint>JOINT_0</joint> 
      <fmu>electric_motor</fmu>
      <actuatorInputName>actuatorInput</actuatorInputName>
      <jointPositionName>jointPosition</jointPositionName>
      <jointVelocityName>jointVelocity</jointVelocityName>
      <jointAccelerationName>jointAcceleration</jointAccelerationName>
      <jointTorqueName>jointTorque</jointTorqueName>
    </actuator>
   </plugin>

especially if some explicitly prepares its own FMUs to use them with gazebo-fmi, the variable names will always be the same, and manually specify them is just error prone.

I think a nice alternative is instead to assume that the variable have some default name (in the actuator case, actuatorInput, etc etc) and the user just need to specify the variable name if it is different from the default. To make an example, this:

  <plugin name="fmi_actuator_plugin" filename="libFMIActuatorPlugin.so">
    <actuator>
      <name>actuator_0</name> 
      <joint>JOINT_0</joint> 
      <fmu>electric_motor.fmu</fmu>
    </actuator>
   </plugin>

will be equivalent to this:

  <plugin name="fmi_actuator_plugin" filename="libFMIActuatorPlugin.so">
    <actuator>
      <name>actuator_0</name> 
      <joint>JOINT_0</joint> 
      <fmu>electric_motor.fmu</fmu>
      <variable_names>
      </variable_names> 
    </actuator>
   </plugin>

and to this:

  <plugin name="fmi_actuator_plugin" filename="libFMIActuatorPlugin.so">
    <actuator>
      <name>actuator_0</name> 
      <joint>JOINT_0</joint> 
      <fmu>electric_motor.fmu</fmu>
      <variable_names>
          <actuatorInput>actuatorInput</actuatorInput>
          <jointPosition>jointPosition</jointPosition>
          <jointVelocity>jointVelocity</jointVelocity>
          <jointAcceleration>jointAcceleration</jointAcceleration>
          <jointTorque>jointTorque</jointTorque>
      </variable_names> 
    </actuator>
   </plugin>

Obviously, it would not make sense to specify the names of the variables if they are the default one, so the user will actually use the variable_names tag if he has some variable names different from the default, see for example:

  <plugin name="fmi_actuator_plugin" filename="libFMIActuatorPlugin.so">
    <actuator>
      <name>actuator_0</name> 
      <joint>JOINT_0</joint> 
      <fmu>electric_motor.fmu</fmu>
      <variable_names>
          <actuatorInput>motorInput</actuatorInput>
      </variable_names> 
    </actuator>
   </plugin>

What do you think @prashanthr05 @triccyx ?

triccyx commented 5 years ago

Ok for me nice idea

prashanthr05 commented 5 years ago

variable_names tag sounds straightforward and neat.

However, in case of shorter tags, (just brainstorming here) how about descriptors or identifiers ? Would it make sense ?

traversaro commented 5 years ago

I would like to stick to something containing "variables" as this is the Jargon used in the FMI specification: https://fmi-standard.org/docs/2.0.1-develop/#_definition_of_model_variables_modelvariables , but I am definitely open to something better than variable_names.

traversaro commented 5 years ago

I think it is safer to encode the variable name as an attribute, rather than an inner text element, i.e. as in:

  <plugin name="fmi_actuator_plugin" filename="libFMIActuatorPlugin.so">
    <actuator>
      <name>actuator_0</name> 
      <joint>JOINT_0</joint> 
      <fmu>electric_motor.fmu</fmu>
      <variable_names>
          <actuatorInput name="motorInput" />
      </variable_names> 
    </actuator>
   </plugin>

The basic idea is that in FMI the variable name is indeed encoded as an attribute of the ScalarVariable tag (see https://fmi-standard.org/docs/2.0.1-develop/#_example_xml_description_file_2), so as long as we encode the name ourself as attributes, we know that we will support any kind of strange variable name. For the same reason we could encode the default name as an attribute as well (<variable_name defaultName="actuatorInput" name="motorInput"/>) but as we are choosing the default name our self I think we can ensure that we can choose simple enough names.