-
Notifications
You must be signed in to change notification settings - Fork 1
New Models
Some commonalities are required for every model. Refer to implemented models (such as SoftTrunkModel
) if things are unclear.
Your model must contain a public dyn_
object which can be read by the Model
. This object can be loaded from SoftTrunk_common.h
Your model have an update
method which takes an srl::State
object as an argument and then updates it's dynamic parameters dyn_
accordingly.
Your model's constructor must take a SoftTrunkParameters
object to be able to verify states to be correct. Upon initialization, ensure it is finalized:
assert(st_params_.is_finalized());
Upon destruction, your model must stop all loops and join all threads so it can terminate correctly.
First, we'll need to do some management stuff to ensure you can write it correctly.
Put your header file in include/3d-soft-trunk/Models/
Put your implementation file in src/Models
So that the project will take your new model into account, you'll have to edit the main CMake file.
It is called CMakeLists.txt
and is in the main directory.
Add a new library for your model and link dependencies (around line 70): Recommended link libraries are Eigen, Boost, fmt, and yaml-cpp.
add_library(YourModel SHARED src/models/Yourmodel.cpp)
target_link_libraries(YourModel ${Boost_LIBRARIES} ${EIGEN3_LIBRARIES} fmt yaml-cpp YourModelDependency1 YourModelDependency2)
Then, add your model to the Model
as a link library by editing the respective line:
target_link_libraries(Model SoftTrunkModel Lagrange)
This header file contains the SoftTrunkParameters
definition, which you'll want to edit to account for your new model.
Add your model to the enum class ModelType
and edit the SoftTrunkParameters::write_yaml
and SoftTrunkParameters::load_yaml
functions to read/write your model.
Now you can update the Model
header: include your model's header:
#include "3d-soft-trunk/models/YourModel.h"
and add an object for your model in the class:
std::unique_ptr<YourModel> yourmodel_;
Now, add an initialization of your model's pointer to the Model
constructor by adding it to the switch on line 7 of Model.cpp
.
Simply add a new case to the switch, and initialize your model:
yourmodel_ = std::make_unique<Yourmodel>(st_params_);
You'll also need to update the Model::update
method. Similarily, add a new case to the switch and read in your model's state:
yourmodel_->update(state);
this->dyn_ = yourmodel_.dyn_;