Adding ligaments using C++

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Arnab Sikidar
Posts: 9
Joined: Thu Sep 21, 2017 1:53 am

Adding ligaments using C++

Post by Arnab Sikidar » Thu Aug 23, 2018 10:38 am

Hello

I am kind off new to OpenSim API development and currently I am writing a code on developing a model with ligament. I have tried to modify the code for mainFatigue.cpp and would like to add ligaments into the model (tugofwar). The problem I am facing right now is that when I am trying to input the ligament (set1) as a pointer to the function MyModel.addForce(set1), it is not being reflected to my osim model after running the code. Is there any other way to define ligaments in the model? I get this that set1 has to be a pointer of OpenSim::Force type. How do I assign a pointer of ligament class into force class? Here is a part of the code.

GeometryPath a1;
a1.appendNewPathPoint("P1", ground, Vec3(0.0, halfLength, 0.35));
a1.appendNewPathPoint("P2", *block,Vec3(0.0, halfLength, halfLength));
Ligament *original;

original->setRestingLength (RestingLength);
original->setName("Original");
original->setsetMaxIsometricForce(p_force);
original->setForceLengthCurve(ForceLengthCurve);
original->set_GeometryPath(a1); // I have also tried using getGeometryPath to access appendNewPathPoint but it isn't working
MyModel.addForce(original);
MyModel.print("tugOfWar_Ligament_model.osim");

Kindly help me in this regard.

Thank you

Regards

Arnab

Tags:

User avatar
Thomas Uchida
Posts: 1793
Joined: Wed May 16, 2012 11:40 am

Re: Adding ligaments using C++

Post by Thomas Uchida » Sat Aug 25, 2018 8:22 am

I suggest modifying the GeometryPath that is already owned by the Ligament rather than swapping in a new one. You can get a writable reference to the Ligament's GeometryPath using the updGeometryPath() method. Here's an example in MATLAB:

Code: Select all

import org.opensim.modeling.*
model = Model('arm26.osim');
ligament = Ligament();
ligament.setName('myLigament');
% (set other ligament properties here)
geopath = ligament.updGeometryPath();
geopath.appendNewPathPoint('P1', model.getBodySet().get('r_humerus'), Vec3(0));
geopath.appendNewPathPoint('P2', model.getBodySet().get('r_ulna_radius_hand'), Vec3(0));
model.addForce(ligament);
model.print('myModel.osim');

User avatar
Arnab Sikidar
Posts: 9
Joined: Thu Sep 21, 2017 1:53 am

Re: Adding ligaments using C++

Post by Arnab Sikidar » Sat Sep 01, 2018 3:05 am

Hi Thomas

Thanks for the reply. It really helped.

Regards

Arnab

POST REPLY