Marine systems simulation
Create a new SimObject library

SimObject libraries are loadable modules (dll or so files) that contain one or more classes inheriting from the SimObject interface. These modules get loaded by FhSim at runtime and their SimObjects made available for the simulation.

Herein, a sketch of the procedure for creating a new SimObject library with a set of SimObjects. In practice, it is recommended to use the SimObject template tool. This tool makes it easier to create a new SimObject library that follow good coding practices, see SimObject template tool. Alternatively, one could consider to base new library on an existing library.

Creating a new SimObject library

Each implemented SimObject must be referenced using ADD_SIMOBJECT_REF or ADD_SIMOBJECT_REF3 macros in a CMake MODULE target. The MODULE target must link to the target FhSim::fhsim, which contains the SimObject base implementation. Suppose fhsim_example.cpp contains a class my::deep::space::VanDerPol and Pendulum, both implementing the SimObject interface. To create a SimObject library with these models, we add to fhsim_example.cpp:

#include <dllLib.h>
IMPORT_EXPORT SimObject* getSimObject(std::string subClassName,
std::sttring simObjectName, ISimObjectCreator* creator)
{
ADD_SIMOBJECT_REF3(my::deep::space,VanDerPol,Oscillator/VanDerPol);
ADD_SIMOBJECT_REF(Pendulum,Oscillator/Pendulum);
return nullptr;
}
Definition: Pendulum.h:66

An excerpt of the CMakeLists.txt is:

find_package(FhSim CONFIG REQUIRED)
add_library(fhsim_example MODULE fhsim_example.cpp fhsim_example.h)
target_link_libraries(fhsim_example PRIVATE FhSim::fhsim)

The resulting dll/so is now a SimObject library with two SimObjects: Oscillator/VanDerPol and Oscillator/Pendulum.

SimObject template tool

The simobject template tool is a command line interface that help create a minimal SimObject library, with ready-made scripts for CMake, conan and documentation. If you are lucky, you are almost completely relieved the burden of writing build system scripts.

Installation

The tool is available from sintef-ocean conan remote:

conan remote add sintef-public https://artifactory.smd.sintef.no/artifactory/api/conan/conan-local
mkdir temp && cd temp
conan install --tool-requires simobject/1.2.0@sintef/stable
# run conanbuild.{sh,bat,ps1} for your platform
# simobject is available
# run deactivate_conanbuild for your platform

Usage

Run simobject --help to get available commands. A user scenario is typically

  1. simobject new config_dir
  2. Edit config_dir/simobject.cfg in a text editor. A simobject.cfg file will be on the format:
[SimObjectLibrary]
name = fhsim_awesome
short_name = fhawe
author = John Doe
author_email = John.Doe@examplemail.com
url = https://www.example.com
homepage = https://www.fhsim.no
license = LICENCE_SHORTHAND
description = A SimObjectLibrary for the purpose of learning how to develop in FhSim.
topics = FhSim, Simulation, Marine, Robotics, Cybernetics
  1. simobject create config_dir --output generated_dir
  2. cd generated_dir && git init
  3. conan install . && conan build .
  4. Write you own SimObjects, see DEVELOPING.md and README.md in the generated directory.