-
 

fmi_adapter package from fmi_adapter repo

fmi_adapter fmi_adapter_examples

Package Summary

Tags No category tags.
Version 2.1.2
License Apache License 2.0
Build type AMENT_CMAKE
Use RECOMMENDED

Repository Summary

Checkout URI https://github.com/boschresearch/fmi_adapter.git
VCS Type git
VCS Version humble
Last Updated 2023-06-09
Dev Status MAINTAINED
CI status No Continuous Integration
Released RELEASED
Tags No category tags.
Contributing Help Wanted (0)
Good First Issues (0)
Pull Requests to Review (0)

Package Description

Wraps FMUs for co-simulation

Additional Links

Maintainers

  • Ralph Lange

Authors

No additional authors.

General information about this repository, including legal information, build instructions and known issues/limitations, are given in README.md in the repository root.

The fmi_adapter package

fmi_adapter is a small ROS 2 package for wrapping functional mockup units (FMUs) for co-simulation of physical models into ROS nodes. FMUs are defined in the FMI standard. Currently, this package supports co-simulation FMUs according to the FMI 2.0 standard only.

FMUs can be created with a variety of modeling and simulation tools. Examples are Dymola, MATLAB/Simulink, OpenModelica, SimulationX, and Wolfram System Modeler.

Technically, a co-simulation FMU is a zip file (with suffix .fmu) containing a physical model and the corresponding solver as a shared library together with an XML file describing the inputs, outputs and parameters of the model and details of the solver configuration. An addition, the zip file may contain the source code of the model and solver in the C programming language.

fmi_adapter_node

fmi_adapter provides a ROS node fmi_adapter_node (class FMIAdapterNode derived from LifecycleNode), which takes an FMU and creates subscribers and publishers for the input and output variables of the FMU, respectively. Then, it runs the FMU’s solver with a user-definable update period. This approach is illustrated in the following diagram.

fmi_adapter in application node

The fmi_adapter_node also searches for counterparts for each FMU parameter and variable in the ROS node parameters and initializes the FMU correspondingly.

For this purpose, this package provide a launch file with argument fmu_path. Simply call

ros2 launch fmi_adapter fmi_adapter_node.launch.py fmu_path:=[PathToTheFMUFile]

Please see the README.md of the fmi_adapter_examples package for a step-by-step description how to use the fmi_adapter_node with a damped pendulum model and FMU.

fmi_adapter library

fmi_adapter provides a library with convenience functions based on common ROS types to load an FMU during runtime, to retrieve the input, output, and parameter names, to set timestamped input values, to run the FMU’s numeric solver, and to query the resulting output. These functions are provided by the class FMIAdapter. Instances of this class may be integrated in application-specific ROS nodes or libraries as illustrated in the following architecture diagram.

fmi_adapter in application node

For parsing the XML description of an FMU and for running the FMU’s solver, fmi_adapter uses the C library FMI Library. For this purpose, fmi_adapter depends on the fmilibrary_vendor package, which downloads and builds the FMI Library using cmake’s externalproject_add command.

Running an FMU inside a ROS node or library

In the following, we give some code snippets how to load and run an FMU file from an application-specific ROS node or library.

Step 1: Include the FMIAdapter.hpp from the fmi_adapter package in your C++ code.

#include "fmi_adapter/FMIAdapter.hpp"

Step 2: Instantiate the adapter class with the path to the FMU file and the desired simulation step size. If the step-size argument is omitted, the default step size specified in the FMU file will be used.

rclcpp::Duration stepSize(0.001);
auto adapter = std::make_shared<fmi_adapter::FMIAdapter>(get_logger(), fmuPath, stepSize);

Step 3: Create subscribers or timers to set the FMU’s input values. For example:

auto subscription = create_subscription<std_msgs::msg::Float64>("angle_x", 1000, 
    [this](std_msgs::msg::Float64::SharedPtr msg) {
      adapter->setInputValue("angleX", now(), msg->data);
    });

In this example, angle_x is the topic name whereas angleX is the corresponding input variable of the FMU.

Use adapter->getInputVariableNames() to get a list of all input variables.

Step 4: Create a timer or subscriber that triggers the simulation of the FMU using adapter->doStepsUntil(..). For example:

auto timer = create_wall_timer(update_period,
    [this]() {
      adapter->doStepsUntil(now());
      double y = adapter->getOutputValue("angleY");
      // ... e.g., publish y on a topic ...
    });

Use adapter->getOutputVariableNames() to get a list of all output variables.

Step 5: Set parameters and initial values of the FMU:

adapter->setInitialValue("dampingParam", 0.21);
adapter->setInitialValue("angleX", 1.3);

The function adapter->initializeFromROSParameters(get_node_parameters_interface()) may be used to initialize all parameters from the corresponding ROS parameters. Please note that all characters in the FMU parameter names that are not supported by ROS are replaced by an ‘_’, cf. FMIAdapter::rosifyName(name).

Step 6: As last setup step, exit the FMU’s initialization mode and set the ROS time that refers to the FMU’s internal timepoint 0.0.

adapter->exitInitializationMode(now());

Papers

If you want to cite this repository/package, please cite the following book chapter (PDF available at Springer Link) instead:

Ralph Lange, Silvio Traversaro, Oliver Lenord, and Christian Bertsch: Integrating the Functional Mock-Up Interface with ROS and Gazebo. In: Anis Koubaa (ed.) Robot Operating System (ROS): The Complete Reference (Volume 5), Springer, pp. 187–231, 2021.

@INBOOK{Lange_et_al_2021_Integrating_the_FMI_with_ROS_and_Gazebo,
  author = {Ralph Lange and Silvio Traversaro and Oliver Lenord and Christian Bertsch},
  title = {Integrating the Functional Mock-Up Interface with ROS and Gazebo},
  editor = {Anis Koubaa},
  booktitle = {Robot Operating System (ROS): The Complete Reference (Volume 5)},
  year = {2021},
  publisher = {Springer},
  pages = {187--231},
  doi = {10.1007/978-3-030-45956-7_7}
}

CHANGELOG

Changelog for package fmi_adapter

2.1.2 (2023-04-13)

  • Updated link to lifecycle_node.hpp.
  • Updated include get_env.h to env.h.
  • Contributors: Ralph Lange

2.1.1 (2021-06-11)

  • Adapted to statically typed parameters introduced in Galactic.

2.1.0 (2021-03-24)

  • Adapted launch files to API changes.

2.0.0 (2021-03-24)

  • Added function 'getValue' to return value of any given variable name Co-authored-by: Sebastian Zarnack <<sebastian.zarnack@eas.iis.fraunhofer.de>>
  • Improved readability of unit tests by chrono literals.
  • Replaced use of deprecated Duration ctor.
  • Added virtual to lifecycle callbacks, as in interface.

0.1.8 (2020-05-14)

  • Prepared for Foxy release.

0.1.7 (2020-01-30)

  • Fixed sporadic exception in case of small external steps.
  • Fixed fmuLocation argument for fmi2_import_instantiate.

0.1.6 (2019-11-05)

  • Release for ROS 2 Eloquent.
  • Changed build files for use of fmilibrary_vendor package.

0.1.5 (2019-05-24)

  • Adapted to new Dashing features, including QoS, parameter declaration and node composition.

0.1.4 (2019-05-23)

  • Fixed link to FMU-SDK.

0.1.3 (2019-02-01)

  • Fixed install target location of shared library.
  • Improved code snippets on use of FMIAdapter class in README.

0.1.2 (2019-01-25)

  • Cleaned up dependency entries in package.xml.
  • Added explicit target dependencies for parallel building.

0.1.1 (2019-01-23)

  • Fixed missing testing and launch dependencies.

0.1.0 (2019-01-18)

Wiki Tutorials

This package does not provide any links to tutorials in it's rosindex metadata. You can check on the ROS Wiki Tutorials page for the package.

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged fmi_adapter at Robotics Stack Exchange

fmi_adapter package from fmi_adapter repo

fmi_adapter fmi_adapter_examples

Package Summary

Tags No category tags.
Version 2.1.2
License Apache License 2.0
Build type AMENT_CMAKE
Use RECOMMENDED

Repository Summary

Checkout URI https://github.com/boschresearch/fmi_adapter.git
VCS Type git
VCS Version rolling
Last Updated 2023-06-09
Dev Status MAINTAINED
CI status No Continuous Integration
Released RELEASED
Tags No category tags.
Contributing Help Wanted (0)
Good First Issues (0)
Pull Requests to Review (0)

Package Description

Wraps FMUs for co-simulation

Additional Links

Maintainers

  • Ralph Lange

Authors

No additional authors.

General information about this repository, including legal information, build instructions and known issues/limitations, are given in README.md in the repository root.

The fmi_adapter package

fmi_adapter is a small ROS 2 package for wrapping functional mockup units (FMUs) for co-simulation of physical models into ROS nodes. FMUs are defined in the FMI standard. Currently, this package supports co-simulation FMUs according to the FMI 2.0 standard only.

FMUs can be created with a variety of modeling and simulation tools. Examples are Dymola, MATLAB/Simulink, OpenModelica, SimulationX, and Wolfram System Modeler.

Technically, a co-simulation FMU is a zip file (with suffix .fmu) containing a physical model and the corresponding solver as a shared library together with an XML file describing the inputs, outputs and parameters of the model and details of the solver configuration. An addition, the zip file may contain the source code of the model and solver in the C programming language.

fmi_adapter_node

fmi_adapter provides a ROS node fmi_adapter_node (class FMIAdapterNode derived from LifecycleNode), which takes an FMU and creates subscribers and publishers for the input and output variables of the FMU, respectively. Then, it runs the FMU’s solver with a user-definable update period. This approach is illustrated in the following diagram.

fmi_adapter in application node

The fmi_adapter_node also searches for counterparts for each FMU parameter and variable in the ROS node parameters and initializes the FMU correspondingly.

For this purpose, this package provide a launch file with argument fmu_path. Simply call

ros2 launch fmi_adapter fmi_adapter_node.launch.py fmu_path:=[PathToTheFMUFile]

Please see the README.md of the fmi_adapter_examples package for a step-by-step description how to use the fmi_adapter_node with a damped pendulum model and FMU.

fmi_adapter library

fmi_adapter provides a library with convenience functions based on common ROS types to load an FMU during runtime, to retrieve the input, output, and parameter names, to set timestamped input values, to run the FMU’s numeric solver, and to query the resulting output. These functions are provided by the class FMIAdapter. Instances of this class may be integrated in application-specific ROS nodes or libraries as illustrated in the following architecture diagram.

fmi_adapter in application node

For parsing the XML description of an FMU and for running the FMU’s solver, fmi_adapter uses the C library FMI Library. For this purpose, fmi_adapter depends on the fmilibrary_vendor package, which downloads and builds the FMI Library using cmake’s externalproject_add command.

Running an FMU inside a ROS node or library

In the following, we give some code snippets how to load and run an FMU file from an application-specific ROS node or library.

Step 1: Include the FMIAdapter.hpp from the fmi_adapter package in your C++ code.

#include "fmi_adapter/FMIAdapter.hpp"

Step 2: Instantiate the adapter class with the path to the FMU file and the desired simulation step size. If the step-size argument is omitted, the default step size specified in the FMU file will be used.

rclcpp::Duration stepSize(0.001);
auto adapter = std::make_shared<fmi_adapter::FMIAdapter>(get_logger(), fmuPath, stepSize);

Step 3: Create subscribers or timers to set the FMU’s input values. For example:

auto subscription = create_subscription<std_msgs::msg::Float64>("angle_x", 1000, 
    [this](std_msgs::msg::Float64::SharedPtr msg) {
      adapter->setInputValue("angleX", now(), msg->data);
    });

In this example, angle_x is the topic name whereas angleX is the corresponding input variable of the FMU.

Use adapter->getInputVariableNames() to get a list of all input variables.

Step 4: Create a timer or subscriber that triggers the simulation of the FMU using adapter->doStepsUntil(..). For example:

auto timer = create_wall_timer(update_period,
    [this]() {
      adapter->doStepsUntil(now());
      double y = adapter->getOutputValue("angleY");
      // ... e.g., publish y on a topic ...
    });

Use adapter->getOutputVariableNames() to get a list of all output variables.

Step 5: Set parameters and initial values of the FMU:

adapter->setInitialValue("dampingParam", 0.21);
adapter->setInitialValue("angleX", 1.3);

The function adapter->initializeFromROSParameters(get_node_parameters_interface()) may be used to initialize all parameters from the corresponding ROS parameters. Please note that all characters in the FMU parameter names that are not supported by ROS are replaced by an ‘_’, cf. FMIAdapter::rosifyName(name).

Step 6: As last setup step, exit the FMU’s initialization mode and set the ROS time that refers to the FMU’s internal timepoint 0.0.

adapter->exitInitializationMode(now());

Papers

If you want to cite this repository/package, please cite the following book chapter (PDF available at Springer Link) instead:

Ralph Lange, Silvio Traversaro, Oliver Lenord, and Christian Bertsch: Integrating the Functional Mock-Up Interface with ROS and Gazebo. In: Anis Koubaa (ed.) Robot Operating System (ROS): The Complete Reference (Volume 5), Springer, pp. 187–231, 2021.

@INBOOK{Lange_et_al_2021_Integrating_the_FMI_with_ROS_and_Gazebo,
  author = {Ralph Lange and Silvio Traversaro and Oliver Lenord and Christian Bertsch},
  title = {Integrating the Functional Mock-Up Interface with ROS and Gazebo},
  editor = {Anis Koubaa},
  booktitle = {Robot Operating System (ROS): The Complete Reference (Volume 5)},
  year = {2021},
  publisher = {Springer},
  pages = {187--231},
  doi = {10.1007/978-3-030-45956-7_7}
}

CHANGELOG

Changelog for package fmi_adapter

2.1.2 (2023-04-13)

  • Updated link to lifecycle_node.hpp.
  • Updated include get_env.h to env.h.
  • Contributors: Ralph Lange

2.1.1 (2021-06-11)

  • Adapted to statically typed parameters introduced in Galactic.

2.1.0 (2021-03-24)

  • Adapted launch files to API changes.

2.0.0 (2021-03-24)

  • Added function 'getValue' to return value of any given variable name Co-authored-by: Sebastian Zarnack <<sebastian.zarnack@eas.iis.fraunhofer.de>>
  • Improved readability of unit tests by chrono literals.
  • Replaced use of deprecated Duration ctor.
  • Added virtual to lifecycle callbacks, as in interface.

0.1.8 (2020-05-14)

  • Prepared for Foxy release.

0.1.7 (2020-01-30)

  • Fixed sporadic exception in case of small external steps.
  • Fixed fmuLocation argument for fmi2_import_instantiate.

0.1.6 (2019-11-05)

  • Release for ROS 2 Eloquent.
  • Changed build files for use of fmilibrary_vendor package.

0.1.5 (2019-05-24)

  • Adapted to new Dashing features, including QoS, parameter declaration and node composition.

0.1.4 (2019-05-23)

  • Fixed link to FMU-SDK.

0.1.3 (2019-02-01)

  • Fixed install target location of shared library.
  • Improved code snippets on use of FMIAdapter class in README.

0.1.2 (2019-01-25)

  • Cleaned up dependency entries in package.xml.
  • Added explicit target dependencies for parallel building.

0.1.1 (2019-01-23)

  • Fixed missing testing and launch dependencies.

0.1.0 (2019-01-18)

Wiki Tutorials

This package does not provide any links to tutorials in it's rosindex metadata. You can check on the ROS Wiki Tutorials page for the package.

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged fmi_adapter at Robotics Stack Exchange

fmi_adapter package from fmi_adapter repo

fmi_adapter fmi_adapter_examples

Package Summary

Tags No category tags.
Version 2.1.2
License Apache License 2.0
Build type AMENT_CMAKE
Use RECOMMENDED

Repository Summary

Checkout URI https://github.com/boschresearch/fmi_adapter.git
VCS Type git
VCS Version rolling
Last Updated 2023-06-09
Dev Status MAINTAINED
CI status No Continuous Integration
Released RELEASED
Tags No category tags.
Contributing Help Wanted (0)
Good First Issues (0)
Pull Requests to Review (0)

Package Description

Wraps FMUs for co-simulation

Additional Links

Maintainers

  • Ralph Lange

Authors

No additional authors.

General information about this repository, including legal information, build instructions and known issues/limitations, are given in README.md in the repository root.

The fmi_adapter package

fmi_adapter is a small ROS 2 package for wrapping functional mockup units (FMUs) for co-simulation of physical models into ROS nodes. FMUs are defined in the FMI standard. Currently, this package supports co-simulation FMUs according to the FMI 2.0 standard only.

FMUs can be created with a variety of modeling and simulation tools. Examples are Dymola, MATLAB/Simulink, OpenModelica, SimulationX, and Wolfram System Modeler.

Technically, a co-simulation FMU is a zip file (with suffix .fmu) containing a physical model and the corresponding solver as a shared library together with an XML file describing the inputs, outputs and parameters of the model and details of the solver configuration. An addition, the zip file may contain the source code of the model and solver in the C programming language.

fmi_adapter_node

fmi_adapter provides a ROS node fmi_adapter_node (class FMIAdapterNode derived from LifecycleNode), which takes an FMU and creates subscribers and publishers for the input and output variables of the FMU, respectively. Then, it runs the FMU’s solver with a user-definable update period. This approach is illustrated in the following diagram.

fmi_adapter in application node

The fmi_adapter_node also searches for counterparts for each FMU parameter and variable in the ROS node parameters and initializes the FMU correspondingly.

For this purpose, this package provide a launch file with argument fmu_path. Simply call

ros2 launch fmi_adapter fmi_adapter_node.launch.py fmu_path:=[PathToTheFMUFile]

Please see the README.md of the fmi_adapter_examples package for a step-by-step description how to use the fmi_adapter_node with a damped pendulum model and FMU.

fmi_adapter library

fmi_adapter provides a library with convenience functions based on common ROS types to load an FMU during runtime, to retrieve the input, output, and parameter names, to set timestamped input values, to run the FMU’s numeric solver, and to query the resulting output. These functions are provided by the class FMIAdapter. Instances of this class may be integrated in application-specific ROS nodes or libraries as illustrated in the following architecture diagram.

fmi_adapter in application node

For parsing the XML description of an FMU and for running the FMU’s solver, fmi_adapter uses the C library FMI Library. For this purpose, fmi_adapter depends on the fmilibrary_vendor package, which downloads and builds the FMI Library using cmake’s externalproject_add command.

Running an FMU inside a ROS node or library

In the following, we give some code snippets how to load and run an FMU file from an application-specific ROS node or library.

Step 1: Include the FMIAdapter.hpp from the fmi_adapter package in your C++ code.

#include "fmi_adapter/FMIAdapter.hpp"

Step 2: Instantiate the adapter class with the path to the FMU file and the desired simulation step size. If the step-size argument is omitted, the default step size specified in the FMU file will be used.

rclcpp::Duration stepSize(0.001);
auto adapter = std::make_shared<fmi_adapter::FMIAdapter>(get_logger(), fmuPath, stepSize);

Step 3: Create subscribers or timers to set the FMU’s input values. For example:

auto subscription = create_subscription<std_msgs::msg::Float64>("angle_x", 1000, 
    [this](std_msgs::msg::Float64::SharedPtr msg) {
      adapter->setInputValue("angleX", now(), msg->data);
    });

In this example, angle_x is the topic name whereas angleX is the corresponding input variable of the FMU.

Use adapter->getInputVariableNames() to get a list of all input variables.

Step 4: Create a timer or subscriber that triggers the simulation of the FMU using adapter->doStepsUntil(..). For example:

auto timer = create_wall_timer(update_period,
    [this]() {
      adapter->doStepsUntil(now());
      double y = adapter->getOutputValue("angleY");
      // ... e.g., publish y on a topic ...
    });

Use adapter->getOutputVariableNames() to get a list of all output variables.

Step 5: Set parameters and initial values of the FMU:

adapter->setInitialValue("dampingParam", 0.21);
adapter->setInitialValue("angleX", 1.3);

The function adapter->initializeFromROSParameters(get_node_parameters_interface()) may be used to initialize all parameters from the corresponding ROS parameters. Please note that all characters in the FMU parameter names that are not supported by ROS are replaced by an ‘_’, cf. FMIAdapter::rosifyName(name).

Step 6: As last setup step, exit the FMU’s initialization mode and set the ROS time that refers to the FMU’s internal timepoint 0.0.

adapter->exitInitializationMode(now());

Papers

If you want to cite this repository/package, please cite the following book chapter (PDF available at Springer Link) instead:

Ralph Lange, Silvio Traversaro, Oliver Lenord, and Christian Bertsch: Integrating the Functional Mock-Up Interface with ROS and Gazebo. In: Anis Koubaa (ed.) Robot Operating System (ROS): The Complete Reference (Volume 5), Springer, pp. 187–231, 2021.

@INBOOK{Lange_et_al_2021_Integrating_the_FMI_with_ROS_and_Gazebo,
  author = {Ralph Lange and Silvio Traversaro and Oliver Lenord and Christian Bertsch},
  title = {Integrating the Functional Mock-Up Interface with ROS and Gazebo},
  editor = {Anis Koubaa},
  booktitle = {Robot Operating System (ROS): The Complete Reference (Volume 5)},
  year = {2021},
  publisher = {Springer},
  pages = {187--231},
  doi = {10.1007/978-3-030-45956-7_7}
}

CHANGELOG

Changelog for package fmi_adapter

2.1.2 (2023-04-13)

  • Updated link to lifecycle_node.hpp.
  • Updated include get_env.h to env.h.
  • Contributors: Ralph Lange

2.1.1 (2021-06-11)

  • Adapted to statically typed parameters introduced in Galactic.

2.1.0 (2021-03-24)

  • Adapted launch files to API changes.

2.0.0 (2021-03-24)

  • Added function 'getValue' to return value of any given variable name Co-authored-by: Sebastian Zarnack <<sebastian.zarnack@eas.iis.fraunhofer.de>>
  • Improved readability of unit tests by chrono literals.
  • Replaced use of deprecated Duration ctor.
  • Added virtual to lifecycle callbacks, as in interface.

0.1.8 (2020-05-14)

  • Prepared for Foxy release.

0.1.7 (2020-01-30)

  • Fixed sporadic exception in case of small external steps.
  • Fixed fmuLocation argument for fmi2_import_instantiate.

0.1.6 (2019-11-05)

  • Release for ROS 2 Eloquent.
  • Changed build files for use of fmilibrary_vendor package.

0.1.5 (2019-05-24)

  • Adapted to new Dashing features, including QoS, parameter declaration and node composition.

0.1.4 (2019-05-23)

  • Fixed link to FMU-SDK.

0.1.3 (2019-02-01)

  • Fixed install target location of shared library.
  • Improved code snippets on use of FMIAdapter class in README.

0.1.2 (2019-01-25)

  • Cleaned up dependency entries in package.xml.
  • Added explicit target dependencies for parallel building.

0.1.1 (2019-01-23)

  • Fixed missing testing and launch dependencies.

0.1.0 (2019-01-18)

Wiki Tutorials

This package does not provide any links to tutorials in it's rosindex metadata. You can check on the ROS Wiki Tutorials page for the package.

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged fmi_adapter at Robotics Stack Exchange

fmi_adapter package from fmi_adapter repo

fmi_adapter fmi_adapter_examples

Package Summary

Tags No category tags.
Version 2.1.2
License Apache License 2.0
Build type AMENT_CMAKE
Use RECOMMENDED

Repository Summary

Checkout URI https://github.com/boschresearch/fmi_adapter.git
VCS Type git
VCS Version rolling
Last Updated 2023-06-09
Dev Status MAINTAINED
CI status No Continuous Integration
Released RELEASED
Tags No category tags.
Contributing Help Wanted (0)
Good First Issues (0)
Pull Requests to Review (0)

Package Description

Wraps FMUs for co-simulation

Additional Links

Maintainers

  • Ralph Lange

Authors

No additional authors.

General information about this repository, including legal information, build instructions and known issues/limitations, are given in README.md in the repository root.

The fmi_adapter package

fmi_adapter is a small ROS 2 package for wrapping functional mockup units (FMUs) for co-simulation of physical models into ROS nodes. FMUs are defined in the FMI standard. Currently, this package supports co-simulation FMUs according to the FMI 2.0 standard only.

FMUs can be created with a variety of modeling and simulation tools. Examples are Dymola, MATLAB/Simulink, OpenModelica, SimulationX, and Wolfram System Modeler.

Technically, a co-simulation FMU is a zip file (with suffix .fmu) containing a physical model and the corresponding solver as a shared library together with an XML file describing the inputs, outputs and parameters of the model and details of the solver configuration. An addition, the zip file may contain the source code of the model and solver in the C programming language.

fmi_adapter_node

fmi_adapter provides a ROS node fmi_adapter_node (class FMIAdapterNode derived from LifecycleNode), which takes an FMU and creates subscribers and publishers for the input and output variables of the FMU, respectively. Then, it runs the FMU’s solver with a user-definable update period. This approach is illustrated in the following diagram.

fmi_adapter in application node

The fmi_adapter_node also searches for counterparts for each FMU parameter and variable in the ROS node parameters and initializes the FMU correspondingly.

For this purpose, this package provide a launch file with argument fmu_path. Simply call

ros2 launch fmi_adapter fmi_adapter_node.launch.py fmu_path:=[PathToTheFMUFile]

Please see the README.md of the fmi_adapter_examples package for a step-by-step description how to use the fmi_adapter_node with a damped pendulum model and FMU.

fmi_adapter library

fmi_adapter provides a library with convenience functions based on common ROS types to load an FMU during runtime, to retrieve the input, output, and parameter names, to set timestamped input values, to run the FMU’s numeric solver, and to query the resulting output. These functions are provided by the class FMIAdapter. Instances of this class may be integrated in application-specific ROS nodes or libraries as illustrated in the following architecture diagram.

fmi_adapter in application node

For parsing the XML description of an FMU and for running the FMU’s solver, fmi_adapter uses the C library FMI Library. For this purpose, fmi_adapter depends on the fmilibrary_vendor package, which downloads and builds the FMI Library using cmake’s externalproject_add command.

Running an FMU inside a ROS node or library

In the following, we give some code snippets how to load and run an FMU file from an application-specific ROS node or library.

Step 1: Include the FMIAdapter.hpp from the fmi_adapter package in your C++ code.

#include "fmi_adapter/FMIAdapter.hpp"

Step 2: Instantiate the adapter class with the path to the FMU file and the desired simulation step size. If the step-size argument is omitted, the default step size specified in the FMU file will be used.

rclcpp::Duration stepSize(0.001);
auto adapter = std::make_shared<fmi_adapter::FMIAdapter>(get_logger(), fmuPath, stepSize);

Step 3: Create subscribers or timers to set the FMU’s input values. For example:

auto subscription = create_subscription<std_msgs::msg::Float64>("angle_x", 1000, 
    [this](std_msgs::msg::Float64::SharedPtr msg) {
      adapter->setInputValue("angleX", now(), msg->data);
    });

In this example, angle_x is the topic name whereas angleX is the corresponding input variable of the FMU.

Use adapter->getInputVariableNames() to get a list of all input variables.

Step 4: Create a timer or subscriber that triggers the simulation of the FMU using adapter->doStepsUntil(..). For example:

auto timer = create_wall_timer(update_period,
    [this]() {
      adapter->doStepsUntil(now());
      double y = adapter->getOutputValue("angleY");
      // ... e.g., publish y on a topic ...
    });

Use adapter->getOutputVariableNames() to get a list of all output variables.

Step 5: Set parameters and initial values of the FMU:

adapter->setInitialValue("dampingParam", 0.21);
adapter->setInitialValue("angleX", 1.3);

The function adapter->initializeFromROSParameters(get_node_parameters_interface()) may be used to initialize all parameters from the corresponding ROS parameters. Please note that all characters in the FMU parameter names that are not supported by ROS are replaced by an ‘_’, cf. FMIAdapter::rosifyName(name).

Step 6: As last setup step, exit the FMU’s initialization mode and set the ROS time that refers to the FMU’s internal timepoint 0.0.

adapter->exitInitializationMode(now());

Papers

If you want to cite this repository/package, please cite the following book chapter (PDF available at Springer Link) instead:

Ralph Lange, Silvio Traversaro, Oliver Lenord, and Christian Bertsch: Integrating the Functional Mock-Up Interface with ROS and Gazebo. In: Anis Koubaa (ed.) Robot Operating System (ROS): The Complete Reference (Volume 5), Springer, pp. 187–231, 2021.

@INBOOK{Lange_et_al_2021_Integrating_the_FMI_with_ROS_and_Gazebo,
  author = {Ralph Lange and Silvio Traversaro and Oliver Lenord and Christian Bertsch},
  title = {Integrating the Functional Mock-Up Interface with ROS and Gazebo},
  editor = {Anis Koubaa},
  booktitle = {Robot Operating System (ROS): The Complete Reference (Volume 5)},
  year = {2021},
  publisher = {Springer},
  pages = {187--231},
  doi = {10.1007/978-3-030-45956-7_7}
}

CHANGELOG

Changelog for package fmi_adapter

2.1.2 (2023-04-13)

  • Updated link to lifecycle_node.hpp.
  • Updated include get_env.h to env.h.
  • Contributors: Ralph Lange

2.1.1 (2021-06-11)

  • Adapted to statically typed parameters introduced in Galactic.

2.1.0 (2021-03-24)

  • Adapted launch files to API changes.

2.0.0 (2021-03-24)

  • Added function 'getValue' to return value of any given variable name Co-authored-by: Sebastian Zarnack <<sebastian.zarnack@eas.iis.fraunhofer.de>>
  • Improved readability of unit tests by chrono literals.
  • Replaced use of deprecated Duration ctor.
  • Added virtual to lifecycle callbacks, as in interface.

0.1.8 (2020-05-14)

  • Prepared for Foxy release.

0.1.7 (2020-01-30)

  • Fixed sporadic exception in case of small external steps.
  • Fixed fmuLocation argument for fmi2_import_instantiate.

0.1.6 (2019-11-05)

  • Release for ROS 2 Eloquent.
  • Changed build files for use of fmilibrary_vendor package.

0.1.5 (2019-05-24)

  • Adapted to new Dashing features, including QoS, parameter declaration and node composition.

0.1.4 (2019-05-23)

  • Fixed link to FMU-SDK.

0.1.3 (2019-02-01)

  • Fixed install target location of shared library.
  • Improved code snippets on use of FMIAdapter class in README.

0.1.2 (2019-01-25)

  • Cleaned up dependency entries in package.xml.
  • Added explicit target dependencies for parallel building.

0.1.1 (2019-01-23)

  • Fixed missing testing and launch dependencies.

0.1.0 (2019-01-18)

Wiki Tutorials

This package does not provide any links to tutorials in it's rosindex metadata. You can check on the ROS Wiki Tutorials page for the package.

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged fmi_adapter at Robotics Stack Exchange

fmi_adapter package from fmi_adapter repo

fmi_adapter fmi_adapter_examples

Package Summary

Tags No category tags.
Version 1.0.4
License Apache License 2.0
Build type CATKIN
Use RECOMMENDED

Repository Summary

Checkout URI https://github.com/boschresearch/fmi_adapter.git
VCS Type git
VCS Version melodic_and_noetic
Last Updated 2022-11-22
Dev Status MAINTAINED
CI status
Released RELEASED
Tags No category tags.
Contributing Help Wanted (0)
Good First Issues (0)
Pull Requests to Review (0)

Package Description

Wraps FMUs for co-simulation

Additional Links

Maintainers

  • Ralph Lange

Authors

  • Ralph Lange

General information about this repository, including legal information, build instructions and known issues/limitations, are given in README.md in the repository root.

The fmi_adapter package

fmi_adapter is a small ROS package for wrapping functional mockup units (FMUs) for co-simulation of physical models into ROS nodes. FMUs are defined in the FMI standard. Currently, this package supports co-simulation FMUs according to the FMI 2.0 standard only.

FMUs can be created with a variety of modeling and simulation tools. Examples are Dymola, MATLAB/Simulink, OpenModelica, SimulationX, and Wolfram System Modeler.

Technically, a co-simulation FMU is a zip file (with suffix .fmu) containing a physical model and the corresponding solver as a shared library together with an XML file describing the inputs, outputs and parameters of the model and details of the solver configuration. An addition, the zip file may contain the source code of the model and solver in the C programming language.

fmi_adapter node

fmi_adapter provides a ROS node (fmi_adapter_node.cpp), which takes an FMU and creates subscribers and publishers for the input and output variables of the FMU, respectively. Then, it runs the FMU’s solver with a user-definable update period according to the ROS clock. This approach is illustrated in the following diagram.

fmi_adapter in application node

The fmi_adapter_node also searches for counterparts for each FMU parameter and variable in the ROS parameter server and initializes the FMU correspondingly.

For this purpose, this package provide a launch file with argument fmu_path. Simply call

roslaunch fmi_adapter fmi_adapter_node.launch fmu_path:=[PathToTheFMUFile]

Please see the README.md of the fmi_adapter_examples package for a step-by-step description how to use the fmi_adapter node with a damped pendulum model and FMU.

fmi_adapter library

fmi_adapter provides a library with convenience functions based on common ROS types to load an FMU during runtime, to retrieve the input, output, and parameter names, to set timestamped input values, to run the FMU’s numeric solver, and to query the resulting output. These functions are provided by the class FMIAdapter. Instances of this class may be integrated in application-specific ROS nodes or libraries as illustrated in the following architecture diagram.

fmi_adapter in application node

For parsing the XML description of an FMU and for running the FMU’s solver, fmi_adapter uses the C library FMI Library. This library is downloaded, compiled and linked in the CMakeLists.txt of this package using cmake’s externalproject_add command.

Running an FMU inside a ROS node or library

In the following, we give some code snippets how to load and run an FMU file from an application-specific ROS node or library.

Step 1: Include the FMIAdapter.h from the fmi_adapter package in your C++ code.

#include "fmi_adapter/FMIAdapter.h"

Step 2: Instantiate the adapter class with the path to the FMU file and the desired simulation step size. If the step-size argument is omitted, the default step size specified in the FMU file will be used.

ros::Duration stepSize(0.001);
fmi_adapter::FMIAdapter adapter(fmuPath, stepSize);

Step 3: Create subscribers or timers to set the FMU’s input values. For example:

ros::Subscriber subscriber =
    nHandle.subscribe<std_msgs::Float64>("angle_x", 1000, [&adapter](const std_msgs::Float64::ConstPtr& msg) {
      adapter.setInputValue("angleX", ros::Time::now(), msg->data);
    });

In this example, angle_x is the topic name whereas angleX is the corresponding input variable of the FMU.

Use adapter.getInputVariableNames() to get a list of all input variables.

Step 4: Create a timer or subscriber that triggers the simulation of the FMU using adapter.doStepsUntil(..). For example:

ros::Timer timer = nHandle.createTimer(ros::Duration(0.01), [&](const ros::TimerEvent& event) {
    adapter.doStepsUntil(event.current_expected);
    double y = adapter.getOutputValue("angleY");
    // ... e.g., publish y on a topic ...
  });

Use adapter.getOutputVariableNames() to get a list of all output variables.

Step 5: Set parameters and initial values of the FMU:

adapter.setInitialValue("dampingParam", 0.21);
adapter.setInitialValue("angleX", 1.3);

The function adapter.initializeFromROSParameters(nodeHandle) may be used to initialize all parameters from the corresponding ROS parameters. Please note that all characters in the FMU parameter names that are not supported by ROS are replaced by an ‘_’, cf. FMIAdapter::rosifyName(name).

Step 6: Just before starting the spin thread, exit the FMU’s initialization mode and set the ROS time that refers to the FMU’s internal timepoint 0.0.

adapter.exitInitializationMode(ros::Time::now());
ros::spin();

Papers

If you want to cite this repository/package, please cite the following book chapter (PDF available at Springer Link) instead:

Ralph Lange, Silvio Traversaro, Oliver Lenord, and Christian Bertsch: Integrating the Functional Mock-Up Interface with ROS and Gazebo. In: Anis Koubaa (ed.) Robot Operating System (ROS): The Complete Reference (Volume 5), Springer, pp. 187–231, 2021.

@INBOOK{Lange_et_al_2021_Integrating_the_FMI_with_ROS_and_Gazebo,
  author = {Ralph Lange and Silvio Traversaro and Oliver Lenord and Christian Bertsch},
  title = {Integrating the Functional Mock-Up Interface with ROS and Gazebo},
  editor = {Anis Koubaa},
  booktitle = {Robot Operating System (ROS): The Complete Reference (Volume 5)},
  year = {2021},
  publisher = {Springer},
  pages = {187--231},
  doi = {10.1007/978-3-030-45956-7_7}
}

CHANGELOG

Changelog for package fmi_adapter

1.0.4 (2021-03-22)

  • Updated to version 2.2.3 of FMILibrary.

1.0.3 (2020-01-30)

  • Fixed sporadic exception in case of small external steps.
  • Updated to FMILibrary version 2.1 and to new location of FMILibrary sources.
  • Fixed fmuLocation argument for fmi2_import_instantiate.

1.0.2 (2018-10-12)

  • Added parameter to configure update period of fmi_adapter node.
  • Introduced functions for single step and replaced calcUntil with doStepsUntil.
  • Enable automatic use of default experiment step-size from FMU in FMIAdapter ctor.
  • Added function to query default experiment step-size given in the FMU.
  • Added step_size parameter and function to query whether the FMU supports a variable communication step size.

1.0.1 (2018-07-16)

  • Throwing runtime_error in case of failed fmi2 function call.

1.0.0 (2018-07-13)

  • Initial version.

Wiki Tutorials

This package does not provide any links to tutorials in it's rosindex metadata. You can check on the ROS Wiki Tutorials page for the package.

Package Dependencies

System Dependencies

Name
git

Dependant Packages

Launch files

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged fmi_adapter at Robotics Stack Exchange

No version for distro ardent. Known supported distros are highlighted in the buttons above.
No version for distro bouncy. Known supported distros are highlighted in the buttons above.
No version for distro crystal. Known supported distros are highlighted in the buttons above.
No version for distro eloquent. Known supported distros are highlighted in the buttons above.

fmi_adapter package from fmi_adapter repo

fmi_adapter fmi_adapter_examples

Package Summary

Tags No category tags.
Version 2.0.0
License Apache License 2.0
Build type AMENT_CMAKE
Use RECOMMENDED

Repository Summary

Checkout URI https://github.com/boschresearch/fmi_adapter.git
VCS Type git
VCS Version dashing
Last Updated 2022-11-23
Dev Status MAINTAINED
CI status No Continuous Integration
Released RELEASED
Tags No category tags.
Contributing Help Wanted (0)
Good First Issues (0)
Pull Requests to Review (0)

Package Description

Wraps FMUs for co-simulation

Additional Links

Maintainers

  • Ralph Lange

Authors

No additional authors.

General information about this repository, including legal information, build instructions and known issues/limitations, are given in README.md in the repository root.

The fmi_adapter package

fmi_adapter is a small ROS 2 package for wrapping functional mockup units (FMUs) for co-simulation of physical models into ROS nodes. FMUs are defined in the FMI standard. Currently, this package supports co-simulation FMUs according to the FMI 2.0 standard only.

FMUs can be created with a variety of modeling and simulation tools. Examples are Dymola, MATLAB/Simulink, OpenModelica, SimulationX, and Wolfram System Modeler.

Technically, a co-simulation FMU is a zip file (with suffix .fmu) containing a physical model and the corresponding solver as a shared library together with an XML file describing the inputs, outputs and parameters of the model and details of the solver configuration. An addition, the zip file may contain the source code of the model and solver in the C programming language.

fmi_adapter_node

fmi_adapter provides a ROS node fmi_adapter_node (class FMIAdapterNode derived from LifecycleNode), which takes an FMU and creates subscribers and publishers for the input and output variables of the FMU, respectively. Then, it runs the FMU’s solver with a user-definable update period. This approach is illustrated in the following diagram.

fmi_adapter in application node

The fmi_adapter_node also searches for counterparts for each FMU parameter and variable in the ROS node parameters and initializes the FMU correspondingly.

For this purpose, this package provide a launch file with argument fmu_path. Simply call

ros2 launch fmi_adapter fmi_adapter_node.launch.py fmu_path:=[PathToTheFMUFile]

Please see the README.md of the fmi_adapter_examples package for a step-by-step description how to use the fmi_adapter_node with a damped pendulum model and FMU.

fmi_adapter library

fmi_adapter provides a library with convenience functions based on common ROS types to load an FMU during runtime, to retrieve the input, output, and parameter names, to set timestamped input values, to run the FMU’s numeric solver, and to query the resulting output. These functions are provided by the class FMIAdapter. Instances of this class may be integrated in application-specific ROS nodes or libraries as illustrated in the following architecture diagram.

fmi_adapter in application node

For parsing the XML description of an FMU and for running the FMU’s solver, fmi_adapter uses the C library FMI Library. For this purpose, fmi_adapter depends on the fmilibrary_vendor package, which downloads and builds the FMI Library using cmake’s externalproject_add command.

Running an FMU inside a ROS node or library

In the following, we give some code snippets how to load and run an FMU file from an application-specific ROS node or library.

Step 1: Include the FMIAdapter.hpp from the fmi_adapter package in your C++ code.

#include "fmi_adapter/FMIAdapter.hpp"

Step 2: Instantiate the adapter class with the path to the FMU file and the desired simulation step size. If the step-size argument is omitted, the default step size specified in the FMU file will be used.

rclcpp::Duration stepSize(0.001);
auto adapter = std::make_shared<fmi_adapter::FMIAdapter>(get_logger(), fmuPath, stepSize);

Step 3: Create subscribers or timers to set the FMU’s input values. For example:

auto subscription = create_subscription<std_msgs::msg::Float64>("angle_x", 1000, 
    [this](std_msgs::msg::Float64::SharedPtr msg) {
      adapter->setInputValue("angleX", now(), msg->data);
    });

In this example, angle_x is the topic name whereas angleX is the corresponding input variable of the FMU.

Use adapter->getInputVariableNames() to get a list of all input variables.

Step 4: Create a timer or subscriber that triggers the simulation of the FMU using adapter->doStepsUntil(..). For example:

auto timer = create_wall_timer(update_period,
    [this]() {
      adapter->doStepsUntil(now());
      double y = adapter->getOutputValue("angleY");
      // ... e.g., publish y on a topic ...
    });

Use adapter->getOutputVariableNames() to get a list of all output variables.

Step 5: Set parameters and initial values of the FMU:

adapter->setInitialValue("dampingParam", 0.21);
adapter->setInitialValue("angleX", 1.3);

The function adapter->initializeFromROSParameters(get_node_parameters_interface()) may be used to initialize all parameters from the corresponding ROS parameters. Please note that all characters in the FMU parameter names that are not supported by ROS are replaced by an ‘_’, cf. FMIAdapter::rosifyName(name).

Step 6: As last setup step, exit the FMU’s initialization mode and set the ROS time that refers to the FMU’s internal timepoint 0.0.

adapter->exitInitializationMode(now());

Papers

If you want to cite this repository/package, please cite the following book chapter (PDF available at Springer Link) instead:

Ralph Lange, Silvio Traversaro, Oliver Lenord, and Christian Bertsch: Integrating the Functional Mock-Up Interface with ROS and Gazebo. In: Anis Koubaa (ed.) Robot Operating System (ROS): The Complete Reference (Volume 5), Springer, pp. 187–231, 2021.

@INBOOK{Lange_et_al_2021_Integrating_the_FMI_with_ROS_and_Gazebo,
  author = {Ralph Lange and Silvio Traversaro and Oliver Lenord and Christian Bertsch},
  title = {Integrating the Functional Mock-Up Interface with ROS and Gazebo},
  editor = {Anis Koubaa},
  booktitle = {Robot Operating System (ROS): The Complete Reference (Volume 5)},
  year = {2021},
  publisher = {Springer},
  pages = {187--231},
  doi = {10.1007/978-3-030-45956-7_7}
}

CHANGELOG

Changelog for package fmi_adapter

2.0.0 (2021-03-24)

  • Added function 'getValue' to return value of any given variable name Co-authored-by: Sebastian Zarnack <<sebastian.zarnack@eas.iis.fraunhofer.de>>
  • Improved readability of unit tests by chrono literals.
  • Replaced use of deprecated Duration ctor.
  • Added virtual to lifecycle callbacks, as in interface.

0.1.8 (2020-05-14)

  • Prepared for Foxy release.

0.1.7 (2020-01-30)

  • Fixed sporadic exception in case of small external steps.
  • Fixed fmuLocation argument for fmi2_import_instantiate.

0.1.6 (2019-11-05)

  • Release for ROS 2 Eloquent.
  • Changed build files for use of fmilibrary_vendor package.

0.1.5 (2019-05-24)

  • Adapted to new Dashing features, including QoS, parameter declaration and node composition.

0.1.4 (2019-05-23)

  • Fixed link to FMU-SDK.

0.1.3 (2019-02-01)

  • Fixed install target location of shared library.
  • Improved code snippets on use of FMIAdapter class in README.

0.1.2 (2019-01-25)

  • Cleaned up dependency entries in package.xml.
  • Added explicit target dependencies for parallel building.

0.1.1 (2019-01-23)

  • Fixed missing testing and launch dependencies.

0.1.0 (2019-01-18)

Wiki Tutorials

This package does not provide any links to tutorials in it's rosindex metadata. You can check on the ROS Wiki Tutorials page for the package.

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged fmi_adapter at Robotics Stack Exchange

No version for distro galactic. Known supported distros are highlighted in the buttons above.

fmi_adapter package from fmi_adapter repo

fmi_adapter fmi_adapter_examples

Package Summary

Tags No category tags.
Version 2.1.2
License Apache License 2.0
Build type AMENT_CMAKE
Use RECOMMENDED

Repository Summary

Checkout URI https://github.com/boschresearch/fmi_adapter.git
VCS Type git
VCS Version foxy
Last Updated 2023-06-09
Dev Status MAINTAINED
CI status No Continuous Integration
Released RELEASED
Tags No category tags.
Contributing Help Wanted (0)
Good First Issues (0)
Pull Requests to Review (0)

Package Description

Wraps FMUs for co-simulation

Additional Links

Maintainers

  • Ralph Lange

Authors

No additional authors.

General information about this repository, including legal information, build instructions and known issues/limitations, are given in README.md in the repository root.

The fmi_adapter package

fmi_adapter is a small ROS 2 package for wrapping functional mockup units (FMUs) for co-simulation of physical models into ROS nodes. FMUs are defined in the FMI standard. Currently, this package supports co-simulation FMUs according to the FMI 2.0 standard only.

FMUs can be created with a variety of modeling and simulation tools. Examples are Dymola, MATLAB/Simulink, OpenModelica, SimulationX, and Wolfram System Modeler.

Technically, a co-simulation FMU is a zip file (with suffix .fmu) containing a physical model and the corresponding solver as a shared library together with an XML file describing the inputs, outputs and parameters of the model and details of the solver configuration. An addition, the zip file may contain the source code of the model and solver in the C programming language.

fmi_adapter_node

fmi_adapter provides a ROS node fmi_adapter_node (class FMIAdapterNode derived from LifecycleNode), which takes an FMU and creates subscribers and publishers for the input and output variables of the FMU, respectively. Then, it runs the FMU’s solver with a user-definable update period. This approach is illustrated in the following diagram.

fmi_adapter in application node

The fmi_adapter_node also searches for counterparts for each FMU parameter and variable in the ROS node parameters and initializes the FMU correspondingly.

For this purpose, this package provide a launch file with argument fmu_path. Simply call

ros2 launch fmi_adapter fmi_adapter_node.launch.py fmu_path:=[PathToTheFMUFile]

Please see the README.md of the fmi_adapter_examples package for a step-by-step description how to use the fmi_adapter_node with a damped pendulum model and FMU.

fmi_adapter library

fmi_adapter provides a library with convenience functions based on common ROS types to load an FMU during runtime, to retrieve the input, output, and parameter names, to set timestamped input values, to run the FMU’s numeric solver, and to query the resulting output. These functions are provided by the class FMIAdapter. Instances of this class may be integrated in application-specific ROS nodes or libraries as illustrated in the following architecture diagram.

fmi_adapter in application node

For parsing the XML description of an FMU and for running the FMU’s solver, fmi_adapter uses the C library FMI Library. For this purpose, fmi_adapter depends on the fmilibrary_vendor package, which downloads and builds the FMI Library using cmake’s externalproject_add command.

Running an FMU inside a ROS node or library

In the following, we give some code snippets how to load and run an FMU file from an application-specific ROS node or library.

Step 1: Include the FMIAdapter.hpp from the fmi_adapter package in your C++ code.

#include "fmi_adapter/FMIAdapter.hpp"

Step 2: Instantiate the adapter class with the path to the FMU file and the desired simulation step size. If the step-size argument is omitted, the default step size specified in the FMU file will be used.

rclcpp::Duration stepSize(0.001);
auto adapter = std::make_shared<fmi_adapter::FMIAdapter>(get_logger(), fmuPath, stepSize);

Step 3: Create subscribers or timers to set the FMU’s input values. For example:

auto subscription = create_subscription<std_msgs::msg::Float64>("angle_x", 1000, 
    [this](std_msgs::msg::Float64::SharedPtr msg) {
      adapter->setInputValue("angleX", now(), msg->data);
    });

In this example, angle_x is the topic name whereas angleX is the corresponding input variable of the FMU.

Use adapter->getInputVariableNames() to get a list of all input variables.

Step 4: Create a timer or subscriber that triggers the simulation of the FMU using adapter->doStepsUntil(..). For example:

auto timer = create_wall_timer(update_period,
    [this]() {
      adapter->doStepsUntil(now());
      double y = adapter->getOutputValue("angleY");
      // ... e.g., publish y on a topic ...
    });

Use adapter->getOutputVariableNames() to get a list of all output variables.

Step 5: Set parameters and initial values of the FMU:

adapter->setInitialValue("dampingParam", 0.21);
adapter->setInitialValue("angleX", 1.3);

The function adapter->initializeFromROSParameters(get_node_parameters_interface()) may be used to initialize all parameters from the corresponding ROS parameters. Please note that all characters in the FMU parameter names that are not supported by ROS are replaced by an ‘_’, cf. FMIAdapter::rosifyName(name).

Step 6: As last setup step, exit the FMU’s initialization mode and set the ROS time that refers to the FMU’s internal timepoint 0.0.

adapter->exitInitializationMode(now());

Papers

If you want to cite this repository/package, please cite the following book chapter (PDF available at Springer Link) instead:

Ralph Lange, Silvio Traversaro, Oliver Lenord, and Christian Bertsch: Integrating the Functional Mock-Up Interface with ROS and Gazebo. In: Anis Koubaa (ed.) Robot Operating System (ROS): The Complete Reference (Volume 5), Springer, pp. 187–231, 2021.

@INBOOK{Lange_et_al_2021_Integrating_the_FMI_with_ROS_and_Gazebo,
  author = {Ralph Lange and Silvio Traversaro and Oliver Lenord and Christian Bertsch},
  title = {Integrating the Functional Mock-Up Interface with ROS and Gazebo},
  editor = {Anis Koubaa},
  booktitle = {Robot Operating System (ROS): The Complete Reference (Volume 5)},
  year = {2021},
  publisher = {Springer},
  pages = {187--231},
  doi = {10.1007/978-3-030-45956-7_7}
}

CHANGELOG

Changelog for package fmi_adapter

2.1.2 (2023-04-13)

  • Updated link to lifecycle_node.hpp.
  • Updated include get_env.h to env.h.
  • Contributors: Ralph Lange

2.1.1 (2021-06-11)

  • Adapted to statically typed parameters introduced in Galactic.

2.1.0 (2021-03-24)

  • Adapted launch files to API changes.

2.0.0 (2021-03-24)

  • Added function 'getValue' to return value of any given variable name Co-authored-by: Sebastian Zarnack <<sebastian.zarnack@eas.iis.fraunhofer.de>>
  • Improved readability of unit tests by chrono literals.
  • Replaced use of deprecated Duration ctor.
  • Added virtual to lifecycle callbacks, as in interface.

0.1.8 (2020-05-14)

  • Prepared for Foxy release.

0.1.7 (2020-01-30)

  • Fixed sporadic exception in case of small external steps.
  • Fixed fmuLocation argument for fmi2_import_instantiate.

0.1.6 (2019-11-05)

  • Release for ROS 2 Eloquent.
  • Changed build files for use of fmilibrary_vendor package.

0.1.5 (2019-05-24)

  • Adapted to new Dashing features, including QoS, parameter declaration and node composition.

0.1.4 (2019-05-23)

  • Fixed link to FMU-SDK.

0.1.3 (2019-02-01)

  • Fixed install target location of shared library.
  • Improved code snippets on use of FMIAdapter class in README.

0.1.2 (2019-01-25)

  • Cleaned up dependency entries in package.xml.
  • Added explicit target dependencies for parallel building.

0.1.1 (2019-01-23)

  • Fixed missing testing and launch dependencies.

0.1.0 (2019-01-18)

Wiki Tutorials

This package does not provide any links to tutorials in it's rosindex metadata. You can check on the ROS Wiki Tutorials page for the package.

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged fmi_adapter at Robotics Stack Exchange

No version for distro lunar. Known supported distros are highlighted in the buttons above.
No version for distro jade. Known supported distros are highlighted in the buttons above.
No version for distro indigo. Known supported distros are highlighted in the buttons above.
No version for distro hydro. Known supported distros are highlighted in the buttons above.
No version for distro kinetic. Known supported distros are highlighted in the buttons above.

fmi_adapter package from fmi_adapter repo

fmi_adapter fmi_adapter_examples

Package Summary

Tags No category tags.
Version 1.0.4
License Apache License 2.0
Build type CATKIN
Use RECOMMENDED

Repository Summary

Checkout URI https://github.com/boschresearch/fmi_adapter.git
VCS Type git
VCS Version melodic_and_noetic
Last Updated 2022-11-22
Dev Status MAINTAINED
CI status
Released RELEASED
Tags No category tags.
Contributing Help Wanted (0)
Good First Issues (0)
Pull Requests to Review (0)

Package Description

Wraps FMUs for co-simulation

Additional Links

Maintainers

  • Ralph Lange

Authors

  • Ralph Lange

General information about this repository, including legal information, build instructions and known issues/limitations, are given in README.md in the repository root.

The fmi_adapter package

fmi_adapter is a small ROS package for wrapping functional mockup units (FMUs) for co-simulation of physical models into ROS nodes. FMUs are defined in the FMI standard. Currently, this package supports co-simulation FMUs according to the FMI 2.0 standard only.

FMUs can be created with a variety of modeling and simulation tools. Examples are Dymola, MATLAB/Simulink, OpenModelica, SimulationX, and Wolfram System Modeler.

Technically, a co-simulation FMU is a zip file (with suffix .fmu) containing a physical model and the corresponding solver as a shared library together with an XML file describing the inputs, outputs and parameters of the model and details of the solver configuration. An addition, the zip file may contain the source code of the model and solver in the C programming language.

fmi_adapter node

fmi_adapter provides a ROS node (fmi_adapter_node.cpp), which takes an FMU and creates subscribers and publishers for the input and output variables of the FMU, respectively. Then, it runs the FMU’s solver with a user-definable update period according to the ROS clock. This approach is illustrated in the following diagram.

fmi_adapter in application node

The fmi_adapter_node also searches for counterparts for each FMU parameter and variable in the ROS parameter server and initializes the FMU correspondingly.

For this purpose, this package provide a launch file with argument fmu_path. Simply call

roslaunch fmi_adapter fmi_adapter_node.launch fmu_path:=[PathToTheFMUFile]

Please see the README.md of the fmi_adapter_examples package for a step-by-step description how to use the fmi_adapter node with a damped pendulum model and FMU.

fmi_adapter library

fmi_adapter provides a library with convenience functions based on common ROS types to load an FMU during runtime, to retrieve the input, output, and parameter names, to set timestamped input values, to run the FMU’s numeric solver, and to query the resulting output. These functions are provided by the class FMIAdapter. Instances of this class may be integrated in application-specific ROS nodes or libraries as illustrated in the following architecture diagram.

fmi_adapter in application node

For parsing the XML description of an FMU and for running the FMU’s solver, fmi_adapter uses the C library FMI Library. This library is downloaded, compiled and linked in the CMakeLists.txt of this package using cmake’s externalproject_add command.

Running an FMU inside a ROS node or library

In the following, we give some code snippets how to load and run an FMU file from an application-specific ROS node or library.

Step 1: Include the FMIAdapter.h from the fmi_adapter package in your C++ code.

#include "fmi_adapter/FMIAdapter.h"

Step 2: Instantiate the adapter class with the path to the FMU file and the desired simulation step size. If the step-size argument is omitted, the default step size specified in the FMU file will be used.

ros::Duration stepSize(0.001);
fmi_adapter::FMIAdapter adapter(fmuPath, stepSize);

Step 3: Create subscribers or timers to set the FMU’s input values. For example:

ros::Subscriber subscriber =
    nHandle.subscribe<std_msgs::Float64>("angle_x", 1000, [&adapter](const std_msgs::Float64::ConstPtr& msg) {
      adapter.setInputValue("angleX", ros::Time::now(), msg->data);
    });

In this example, angle_x is the topic name whereas angleX is the corresponding input variable of the FMU.

Use adapter.getInputVariableNames() to get a list of all input variables.

Step 4: Create a timer or subscriber that triggers the simulation of the FMU using adapter.doStepsUntil(..). For example:

ros::Timer timer = nHandle.createTimer(ros::Duration(0.01), [&](const ros::TimerEvent& event) {
    adapter.doStepsUntil(event.current_expected);
    double y = adapter.getOutputValue("angleY");
    // ... e.g., publish y on a topic ...
  });

Use adapter.getOutputVariableNames() to get a list of all output variables.

Step 5: Set parameters and initial values of the FMU:

adapter.setInitialValue("dampingParam", 0.21);
adapter.setInitialValue("angleX", 1.3);

The function adapter.initializeFromROSParameters(nodeHandle) may be used to initialize all parameters from the corresponding ROS parameters. Please note that all characters in the FMU parameter names that are not supported by ROS are replaced by an ‘_’, cf. FMIAdapter::rosifyName(name).

Step 6: Just before starting the spin thread, exit the FMU’s initialization mode and set the ROS time that refers to the FMU’s internal timepoint 0.0.

adapter.exitInitializationMode(ros::Time::now());
ros::spin();

Papers

If you want to cite this repository/package, please cite the following book chapter (PDF available at Springer Link) instead:

Ralph Lange, Silvio Traversaro, Oliver Lenord, and Christian Bertsch: Integrating the Functional Mock-Up Interface with ROS and Gazebo. In: Anis Koubaa (ed.) Robot Operating System (ROS): The Complete Reference (Volume 5), Springer, pp. 187–231, 2021.

@INBOOK{Lange_et_al_2021_Integrating_the_FMI_with_ROS_and_Gazebo,
  author = {Ralph Lange and Silvio Traversaro and Oliver Lenord and Christian Bertsch},
  title = {Integrating the Functional Mock-Up Interface with ROS and Gazebo},
  editor = {Anis Koubaa},
  booktitle = {Robot Operating System (ROS): The Complete Reference (Volume 5)},
  year = {2021},
  publisher = {Springer},
  pages = {187--231},
  doi = {10.1007/978-3-030-45956-7_7}
}

CHANGELOG

Changelog for package fmi_adapter

1.0.4 (2021-03-22)

  • Updated to version 2.2.3 of FMILibrary.

1.0.3 (2020-01-30)

  • Fixed sporadic exception in case of small external steps.
  • Updated to FMILibrary version 2.1 and to new location of FMILibrary sources.
  • Fixed fmuLocation argument for fmi2_import_instantiate.

1.0.2 (2018-10-12)

  • Added parameter to configure update period of fmi_adapter node.
  • Introduced functions for single step and replaced calcUntil with doStepsUntil.
  • Enable automatic use of default experiment step-size from FMU in FMIAdapter ctor.
  • Added function to query default experiment step-size given in the FMU.
  • Added step_size parameter and function to query whether the FMU supports a variable communication step size.

1.0.1 (2018-07-16)

  • Throwing runtime_error in case of failed fmi2 function call.

1.0.0 (2018-07-13)

  • Initial version.

Wiki Tutorials

This package does not provide any links to tutorials in it's rosindex metadata. You can check on the ROS Wiki Tutorials page for the package.

Package Dependencies

System Dependencies

Name
git

Dependant Packages

Launch files

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged fmi_adapter at Robotics Stack Exchange