Exercise: Creating simple SimObjects

Goal

In this exercise you will create two new SimObjects. For simplicity it is suggested to work directly in the FhSimTutorialLibrary. General steps:

  1. Making the source code for the two SimObjects
  2. Referencing them in the CMakeLists.txt file
  3. Including their header files FhsimTutorialLib.h
  4. Adding references to them in FhsimTutorialLib.cpp
  5. Building the install target
  6. Createing the input file
  7. Running a simulation including the new SimObjects

Implement a linear spring with damping in 3D

  1. Copy the file CLinearSpring.h and CLinearSpring.cpp to e.g. CDampedSpring.h and CDampedSpring.cpp, respectively.
  2. Replace all “CLinearSpring” with “CDampedSpring” in CDampedSpring.h and CDampedSpring.cpp.
  3. Implement the additional functionality.
  4. Do step 2-4 from the list “General steps” above.

Implement a mass object which can take a variable number of forces as input (enough to include translations to begin with)

  1. Copy the file CMass.h and CMass.cpp to e.g. CMultiPortMass.h and CMultiPortMass.cpp, respectively.
  2. Replace all “CMass” with “CMultiPortMass” in CMultiPortMass.h and CMultiPortMass.cpp.
  3. Implement the additional functionality.
  4. Do step 2-4 from the list “General steps” above.

Build the install target

Visual Studio: Right click the target installand select build. Command line (fron the build directory folder): Run cmake –build . –target install`

Create the input file

It is recommended to copy the existing input file as a templat when creating a new input file. The rest is to a large extent offered as an exercise. Althoug, remember that:

  • every input port must be connected
  • every state must be initialized (almost true).
  • the sizes of input and output ports must match.
  • the SimObject type is the name maching the alias given in FhsimTutorialLib.cpp.

Run the simulation

In the following, it is assumed that you are using the Debugconfiguration and have built the project with visualization.

From Visual Studio:

  1. In the Solution Explorer, right click on FhsimTutorialLibrary and select Set as startup project.
  2. In the Solution Explorer, right click on FhsimTutorialLibrary and select Properties.
  3. Click Debugging
  4. Set the following:
    • Command: FhRtVis_d
    • Command arguments: <INPUT_FILE>
    • Working Directory: <PLAYPEN_DIR>/bin
  5. Press <F5> to start the simulation.

Some of these properties may be found using the browse-button.

  • <INPUT_FILE> may e.g. be C:_work_DEV_FhSim\fhsimTutorial\input\MassLinearSpring.xml
  • <PLAYPEN_DIR> may be e.g. C:_work_DEV\FhSimPlayPen_vs14-64

From the command prompt on Windows:

Start a command prompt and execute the following:

cd <PLAYPEN_DIR>/bin
FhRtVis_d <INPUT_FILE>