Note: this document discusses the use Modelica with the gazebo-fmi Actuator plugin, using OpenModelica. The content should apply also to other Modelica implementation that support the FMI 2.0 standard, but their use was not tested.
There are two ways to generate the FMU file in OpenModelica. Be sure to choose the correct parameters.
Execute OpenModelica and load your model. Eventually load all the needed libraries (i.e. Modelica_Synchronous). Open the menu Tools->Options, tab FMI now choose the correct parameters:
Version:2
Type:Co-Simulation
Platform:Dynamics
Open the menu FMI->Export FMU at this point you have generated the .fmu file.
Execute OpenModelica and load your model. Eventually load all the needed libraries (i.e. Modelica_Synchronous). Open the menu Tools->OpenModelica compiler CLI and type
buildModelFMU(<Your model name without .mo>, "2", "cs", "<default>", {"dynamic"}, true)
At this point you have generated the .fmu file.
In this repo, several examples of Modelica models are used for testing purpouses. We present each of this model as an example of Modelica models used to generate FMU suitable for the actuator co-simulation.
All models use the Modelica.Mechanics.Rotational.Components.AngleToTorqueAdaptor
component from
the Modelica Standard Library to map the acausal connectors of Modelica
to the input-output variables of the FMUs.
To read more about these interfaces between the acausal world of Modelica and the causal world of FMI, check:
- https://www.claytex.com/tech-blog/splitting-mechanical-and-fluid-devices-using-real-inputs-real-outputs/
- Martin Otter - FMI Tutorial - Connecting tightly coupled FMUs
Modelica source code: NullTransmission.mo
.
This is the simplest example of transmission: regardless of the actuatorInput
or the feedback coming from jointPosition
, jointVelocity
or jointAcceleration
, the jointTorque
output of the trasmission is always zero. In the unit test, this model
is used to verify that the PID is not able to control the joint position if this actuator is used.
Modelica source code: IdentityTransmission.mo
.
This is another simple example of transmission: regardless of the feedback coming from jointPosition
, jointVelocity
or jointAcceleration
, this model will always copy in jointTorque
the actuatorInput
value.
Modelica source code: CompliantTransmission.mo
.
This is the first non-trivial example of the transmission: the actuator input is used to drive a series of an inertia and a spring,
that then drive the actual torque delivered to the Gazebo model. Note that, due to the spring between the inertia and the output flange,
the jointTorque
output value does not depend on the jointAcceleration
input.
Modelica source code: SoftTransmission.mo
.
This model is exactly the same of the Compliant Transmission one, but with the difference that the spring stiffness is much lower. The same joint PID gains that are able to reach a given setpoint if the Compliant Transmission is used, are not able to control the joint if this transmission is used, due to the low stiffness of the spring.
Modelica source code: StiffTransmission.mo
.
This model shows a transmission with a direct coupling between the transmission inertia and the output flange.
Note that, due to the direct coupling between the inertia and the output flange,
the jointTorque
output value depends instantaneously on the jointAcceleration
input.