This tutorial is an exercise which aims at adding two simple SimObjects to the fhsim_tutorial
.
Goal
In this exercise you will create two new SimObjects. For simplicity it is suggested to work directly in the fhsim_tutorial.
General steps:
- Making the source code for the two SimObjects
- Referencing them in the
CMakeLists.txt
file
- Including their header files fhsim_tutorial.h
- Adding references to them in fhsim_tutorial.cpp (
ADD_SIMOBJECT_REF
)
- Building the install target
- Creating the input file
- Running a simulation including the new SimObjects
Implement a linear spring with damping in 3D
- Copy the file CLinearSpring.h and CLinearSpring.cpp to e.g. CDampedSpring.h and CDampedSpring.cpp, respectively.
- Replace all "CLinearSpring" with "CDampedSpring" in CDampedSpring.h and CDampedSpring.cpp.
- Implement the additional functionality.
- 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)
- Copy the file CMass.h and CMass.cpp to e.g. CMultiPortMass.h and CMultiPortMass.cpp, respectively.
- Replace all "CMass" with "CMultiPortMass" in CMultiPortMass.h and CMultiPortMass.cpp.
- Implement the additional functionality.
- Do step 2-4 from the list "General steps" above.
Build the install target
- Visual Studio: Right click the target and select
build
.
- Command line: Run
cd build && conan build ..
Create the input file
It is recommended to copy the existing input file as a template when creating a new input file. The rest is to a large extent offered as an exercise. Although, 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 matching the reference given in fhsim_tutorial.cpp.
Run the simulation
See Running a compiled SimObject.