0% found this document useful (0 votes)
80 views23 pages

OPENSIM

This document discusses scripting an OpenSim musculoskeletal model of the human body in MATLAB and XML. It describes modeling the skeletal system, including declaring the pelvis bone with three components, and adding the right femur bone connected to the pelvis with a free joint. Possible errors in placement or connection of bones are also outlined. The goal is to accurately represent the human skeleton and its movements through programming.

Uploaded by

Akash Naik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views23 pages

OPENSIM

This document discusses scripting an OpenSim musculoskeletal model of the human body in MATLAB and XML. It describes modeling the skeletal system, including declaring the pelvis bone with three components, and adding the right femur bone connected to the pelvis with a free joint. Possible errors in placement or connection of bones are also outlined. The goal is to accurately represent the human skeleton and its movements through programming.

Uploaded by

Akash Naik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

OPENSIM: SCRIPTING

IN MATLAB AND XML

Tanmay Debnath
PDPM Indian Institute of Information Technology
Design and Manufacturing
Jabalpur; Madhya Pradesh – 482005
India

ABSTRACT:

Page | 1
Biomechanics is one of the important domains to study and research. There are certain
domains within the broad spectrum of biomechanics which is based on the precise
representation of the biomechanics of a particular body. Some of the applications of the
same are evident in the department of sports and exercise, where the improvement in
the biomechanics of the body directly affects the improvement in the game or sport. It is
not only related to the study of the sports and the related mechanics. But it is evident
that it has a wide range of applications on the domain of injury recovery. Worth
mentioning, Hugh Herr, the director of the Biomechatronics lab at MIT Media Lab is
one of the key people to have established the domain in a way no one could have ever
imagined. Using the paradigms of biomechanics and electronics, he revolutionised the
mechanics in human body for those who are required to have some form of body
prosthetics.

In analysing the same, we find the usage of the OpenSim to be most crucial and hence
in turn, determine the scripting of the same to be one of the important paradigms to be
learnt in the same. In this report, I have presented the entire modelling segment of the
human skeleton model using OPENSIM classes in MATLAB. The code shall be utilised in
all versions of MATLAB and can be modified as per requirements.

1. Introduction:
In this internship, I have modelled various methods of scripting an OpenSim model
using MATLAB and XML. There are several factors which are needed to be considered
while constructing the entire model of the Musculoskeletal model of the human body
using just programming. There is a comprehensive class list on the OpenSim website
(predominantly built on C++). The extensive use of C++ in the module, however, made
it a little vague for the implementation of the same in other programming platforms like
MATLAB, XML or Python Scripts etc. The names of the classes have been stated in the
user manual along with their usages which made it rather clear to perform the
implementation of the code in the MATLAB and XML systems. Hence for making the

system perfect, I have cleared out the module and made an entire system of human
skeleton using the MATLAB and XML platforms, starting from scratch.
Figure 1: The class-list definitions as presented on SimTK website (source)

There has been a ambiguity in the application of the similar classes directly into the
MATLAB platform. Applications of most the above cited functions would result in an
error in the MATLAB command line window and hence required an important view to
find out the underlying commands that would lead to the generation of the model. There

Page | 2
are some examples in the website stating some of the commonly used applications of
specific commands, but they clearly miss out the applications of the human skeletal
system and have compared the actual body to that of free body diagrams and hence the
same cannot be considered as a commensurate for the real-life applications. For proper
experimentation, we need a proper model with proper dimensions and actuations .

Figure 2: Some of the class instances in the MATLAB environment

Using the same, I am modelling the entire skeletal system of the human body using the
same, in a step-by-step manner.

2. The skeletal System:


In this section, I would be discussing the segments I have considered to be present in
the model for the analysis and presentation.

2.1 Pelvis:
The human pelvis is the first piece to be considered for the starting of the base of the
human body. Based on the positioning of the pelvis in space the other system models
have been implemented and coded. The human pelvis has been placed out of no
boundaries in the visualisation space on the OpenSim environment. The human pelvis
has been depicted as an integration of three different bone sets.

Figure 3: The Human Pelvis

In the meshing geometry section of the code, three VTP files have been used, namely:
‘pelvis.vtp’, ‘sacrum.vtp’, and ‘l_pelvis.vtp’. These files are already added in the
OpenSim geometry folder of respective systems. The ‘sacrum.vtp’ stands for the
segment in the middle of the diagram, against which the entire torso segment is
supported and the spinal cord along with the other skeletal systems are attached.
Whereas the ‘pelvis.vtp’ and ‘l_pelvis.vtp’ represents the right and left side of the
attached bones, respectively. The right and the left of the human gait model is attached

Page | 3
to the same, respectively. Now the possible method for the implementation of the same
in the form of a code is pretty intriguing. OpenSim and MATLAB follows a specific set of
rules and a systematic design format for the initialisation and attachment of the bodies
to each other and making them function in unison.

- Parent: (Located free in space)


- Child: 2 [Femur Right, Femur Left]

Figure 4: Initialisation of the Pelvis and setting some of the observed values of the body

The function ‘Body()’ is one of the class functions in the OpenSim library which
introduces a new set of body to the OpenSim environment. It declares to MATLAB that a
new body would be introduced and setting the properties of the same, based on the
demo samples already present on the OpenSim environment module. Here, the module
of 2392 has been preferred because of the additional sets of muscle derivations in the
system. However, the model of 2354 and 2392, anatomically remains the same.

Page | 4
Figure 5: Declaration of joints and further operations

After the declaration of the bone sets in the environment, we have to derive the relation
of the same with the environment. We declare a specialised joint, from the classes of
OpenSim. I have chosen ‘FreeJoint’ in this regard because it is the best matching form
of motion that can be replicated to that of the original movement of an individual. Free
Joint would allow the constant movement and rotation in every plane in the 3D space.
Some of the values are also implemented above are based on the experimentation and
largely varies from person-to-person.

Figure 6: Meshing the VTP files into the environment and adding them to the system
environment

After all the necessary steps, adding all the data and declaring all the joints, the object
(3D diagram) of the specific body parts are added and meshed into the system
environment and the final set is added to the OpenSim environment model. This brings
us to the end of the Pelvis declaration.

2.2 Femur Right:


Femur is the longest bone in our human skeleton system. All the major loading
conditions, including the whole load of the torso and the hips are supported by this
segment and forms the connection in between the torso and the lower half of the body.
The process of addressing Femur would remain the same as that of the other body
segments as well.

Page | 5
Figure 7: The Human Femur Bone

The majority of the force shall pass on through this segment of the body. The following
shall be initialised and attached to the main body segment as mentioned above. The
body (OBJ file) which would correspond to the segment is the ‘femur.vtp’ file. This file
would be directly connected to the right-hand side of the pelvis model. The coordinates
shall remain (0,0,0) w.r.t the original parent file, for the orientation. Whereas,
considering the location of the same, there would be a slight change in the coordinates
because of the change in the parent location and the base of the model, Since, the
model is placed at (0,0,0) w.r.t to the OpenSim environment, hence it is crucial to apply
the necessary changes otherwise the system would run into an error.

- Parent: 1 [Pelvis]
- Child: 1 [Tibia Right]

Figure 8: The declaration of the joint


and adding the joint into the system
environment

2.2.1 Possible Errors


There are a plenty of possible errors that might happen while modelling the system.
Some of them are listed below:

- One of the major possibilities of the error is the placement of the femur bone
w.r.t the pelvis of the skeletal system. If the coordinates are not adjusted
according to the requirements of the model, then there wouldn’t be an error
depicted in the MATLAB command window but during visualisation, there would
be an error.

Page | 6
Figure 9: Incorrect placement of the Femur w.r.t the Pelvis

The error can be fixed by placing the right coordinates for the location in parent,
which is (-0.0707, -0.0661,0.0835). This would eventually bring the bring the
femur to the right of the pelvis model and hence the accurate model would be
generated.

- Another form of error arises when there is a mismatch in the connection in


between the current model and its parent. This is administered by the finalising
function stated at the last of the entire script. We shall discuss it afterwards.

2.3 Tibia Right:


Tibia, also known as the shankbone, is the larger, stronger and anterior of the two
bones in the leg below the knee in the vertebrates. In human anatomy, it is regarded as
the second largest bone in the human body, just after the human femur. For
representing the same in the model of the OpenSim environment, we need the files
named, ‘tibia_r.vtp’ and ‘fibula.vtp’. The following files represents exactly the bone
segments which would move into the final body.

Figure 10: The code for the addition of the tibia into the system environment

The addition of the same, like others, remain the same, without any change. We have to
follow the same procedures as mentioned above to get the body attached into the
system and make it visualize in the OpenSim environment. But we have to be careful
while adding the following component into the body because we have the same anomaly
as discussed in the femur region. The body is not directly connected to the parent body
and is at a little offset to that of the parent. The exact dimensions for the same, as
shown is: (0, -0.38, 0). The error generated because of this value error would happen
similar to that of the figure 9. This might serious hinder the model and might happen to

Page | 7
disrupt the dynamics of the model. The updates in the joints are made in accordance to
the body of a human and the extent to which the particular segment can move. The
values can be manipulated based on the requirement of the model and the type of
motion that the user wants to simulate.
- Parent: 1 [Femur Right]
- Child: 1 [Talus Right]

2.4 Talus Right:


Talus is the bone that makes up the lower part of the ankle joint (tibia and fibula make
up the upper part). The ankle joint allows the foot to move up and down. The talus also
site above of the heel bone (calcaneus). Together the talus and the calcaneus form the
subtalar joint. The bone, in OpenSim, is also addressed in the file named as ‘talus.vtp’.
This gives a great advantage to easily read and write the files directly into the MATLAB
environment for the visualization.

Figure 11: The dimensions of Talus right used in


the model

Here, as well we can observe a slight deviation in the data for the connection of the
child model to that of the parent model. This changes actually fully fit the model into the
bone structure. The data has been counted as to be (0, -0.43, 0). Apart from that, we
can see a normal form of the instruction and not anything to be exclusive in nature.
- Parent: 1 [Tibia Right]
- Child: 1 [Calcaneus Right]

2.5 Calcaneus Right:


The Calcaneus, also called the heel bone, is a large bone that forms the foundation of
the rear part of the foot. The calcaneus connects with the talus and cuboid bones. The
connection between the talus and calcaneus forms the subtalar joint. The joint is
important for normal foot function. In OpenSim, we characterise the same using the file
‘foot.vtp’. This would form the base of the foot.

Page | 8
Figure 12: Adding Calcaneus to the model

In the above figure, it can be observed that


the calcaneus body has been chosen and
given a free movement rather than a fixed
joint. Because here, it has been considered
that the body is free to move and have been
tried to resemble to realistic conditions as
much as possible. Since using the calcaneus,
we can also move the lower end of the foot,
hence it has been preferred to keep it movable. The datapoints for the location of the
model should be noted. Special considerations have to be taken while writing the codes
for the modelling at such stages. Otherwise, the model is bound to visualize and perform
abnormally.
- Parent: 1 [Talus Right]
- Child: 1 [Toes Right]

2.6 Toes Right:


Here, the toes are referred to the collective manipulation of the metatarsals and
phalanges. They are combined in a single displayable file in OpenSim and named as
‘bofoot.vtp’. The metatarsal bones are a group of five long bones in the foot, located
between the tarsal bones of the hind and mid-foot and the phalanges of the toes. The
phalanges are digital bones in the hands an d feet of most vertebrates.

Figure 13: Adding the toes into the environment

This was a comprehensive idea about adding some of the important parts of the human
body and adding them into the system of human body in the OpenSim visualization
environment.
- Parent: 1 [Calcaneus Right]
- Child: -None-

2.7 Torso:

Page | 9
The torso stands for the upper part of the body. The anatomical term used to define the
central part of the body, which extends from the neck to the ribs. The torso includes:
the thoracic segment of the trunk, the abdominal segment of the trunk and the
perineum. For the OpenSim visualisation, we have collectively addressed the torso as
one single segment. However, it can be defined discreetly based on the demands of the
model to be analysed. Since we are moving ahead with the model of the below-knee
prosthesis settings hence we would be preferring the lower half of the body more
profoundly than the upper part of the body. Collectively, the segment of the torso has
been meshed and have been placed into the model. The model comprises of 4 files for
the visualization, ‘hat_spine.vtp’, ‘hat_jaw.vtp’, ‘hat_skull.vtp’, and ‘hat_ribs.vtp’ – which
corresponds to the various segments of the facial and other structural bones of the
human body in the upper and the central torso.

Figure 14: The instantiation of the Torso and the joints associated with the same

Now since the joints have been instantiated then there is a requirement for certain
parameters to be assigned to the same for the process of creating a model of utmost
reality and which resembles the nature of the actual human skeleton.

- Parent: 1 [Pelvis]
- Child: -None-

Page | 10
Figure 15: Changing the parameters of the movement and also adding the geometry
files to the system

The torso model would be automatically placed and well attached to the previous
created model of the lower segment of the body. This has created the entire model of
the human skeleton (without the ends). The hands have been removed here because of
the fact that they sometimes create unnecessary vibrations on the body during gait that
might hinder the results. However, these results might be useful if we are considering
to make something for the people with osteoarthritis or osteoporosis, because the hand
vibrations would then create an efficient model of locomotion and movement.

2.8 Femur Left:


After the right and upper segment of the body, we move our concentration to the lower
left-side of the human body. The code for the same remains non-trivial because of the
fact that we have already mentioned the procedure of the coding in the segment [2.2].
Femur Left has to be coded similar to that of the Femur Right. However, there are
certain nuances to the same.

Figure 16: The instantiation of the Femur Left segment

Notice the nuances in the ‘LocationInParent’ variable in figure 15. This is quite different
to that of the one described in figure 8. The only difference that can be observed in
between the two is the difference in the Z-axis. Since the model is horizontally opposite
to that of the Femur Right [2.2]. The possible errors remain to be same and no other
extra outcomes of errors are possible, as of now.
- Parent: 1 [Pelvis]
- Child: 1 [Tibia Left]

2.9 Tibia Left:


Tibia left is considered to be the left shank of the human lower half body segment.
Similar to the coding paradigm to that of the tibia right, as described in [2.3]. Here, the
body parts are represented using the data of the files, ‘tibia_l.vtp’ and ‘l_fibula.vtp’.

Page | 11
Figure 17: The instantiation, adding and
changing the parameters of the tibia left
segment

Notice that the value in the


‘LocationInParent’ has not been changes
in comparison to [2.3]. This is because the
z-axis was 0 in the former case and there
is no point in putting the negative sign in
front of a zero-number. Refer to [2.3] for
the proper explanation.
- Parent: 1 [Femur Left]
- Child: 1[Talus Left]

2.10 Talus Left:


The left part of the talus, in the left leg, is all similar to that of the right leg. The only
notable difference here is the name of the file which has been replaced to
commensurate to actual visualization in the OpenSim environment. The files used here
for the association into the system is
‘l_talus.vtp’

Figure 18: The instantiation and adding of


the parameters of the subtalar joints and
the corresponding bones

Similar to the [2.4], there has been no changes in the ‘LocationInParent’ because of the
fact that the Z-axis is turned to zero and hence it makes no sense to have a negative end
to the zero segment.
- Parent: 1 [Tibia Left]
- Child: 1 [Calcaneus Left]

2.11 Calcaneus Left:


Calcaneus on the left leg is similar in structure and to that of the segment described in
[2.5]. However, in this case, the name of the file which has been put forward for the
visualisation purpose is the ‘l_foot.vtp’. Special consideration should be taken while
considering the mass centre and the inertia of the model. I should be duly noted that the
values can be changed via code but should be calculated well enough before
implementation.

Page | 12
Figure 19: The instantiation adding of parameters of the subtalar joints and the
corresponding bones

It has to be noted here, that the z-axis is not zero and hence there would be significant
difference in reference to that of the description showed in [2.5]. So, the z-axis would
have the exact negative to that of what shown in [2.5].
- Parent: 1 [Talus Left]
- Child: 1[Toes Left]

2.12 Toes Left:


Toes on the left leg is similar in structure and to that of the segment described in [2.6].
However, in this case, the name of the file which has been put forward for the
visualisation purpose is the ‘l_bofoot.vtp’. Special consideration should be taken while
considering the mass centre and the inertia of the model. I should be duly noted that the
values can be changed via code but should be calculated well enough before
implementation.

Figure 20: The instantiation adding of


parameters of the Toes left bones

It has to be noted here, that the z-axis is not zero and hence there would be significant
difference in reference to that of the description showed in [2.6]. So, the z-axis would
have the exact negative to that of what shown in [2.6].
- Parent: 1 [Calcaneus Left]
- Child: -None-

3. Review of the Coded functions used


Some of the functions used in the module above:

Function Name Function Purpose


Body () Adding a new body into the system of OpenSim
environment
Body.SetName () Providing a nomenclature to the added model for inspection
purposes
Body.SetMass () Providing a mass to the body
Body.SetMassCenter () Setting a mass centre to the body; needed for the physics
analysis
Body.SetInertia () Setting the inertia to the body
Body.attachGeometry () Attaching a particular geometry to the environment
Body.attachBody () Adding the body finally to the model

Page | 13
Vec3 () Vector (3-D) representation in any form
FreeJoint () Adding free-joint to the bodies and connecting them
FreeJoint.upd_coordinat Updating the coordinates in the motion
es ()
FreeJoint.setRange () Sets the range for the movement in the joints
Model () Instantiating a model that is our prime focus
Model.finalizeConnectio Finalize the connections and make the model forward for
ns () generation
Model.print () Printing the model into a .osim file (readable by the
OpenSim software)

Using these functions, the entire model has been prepared. The entire code of the same
is present in the repository.

4. Results

Figure 21: Correlating the data from 2392 model and from the created model

From the above figures, we can determine that we have almost matched both the flexion
and adduction readings in out pilot testing. The model requires further grooming as to
receive the proper interaction with the environment. Some of the joint angles and
features are to be determined externally using experiments and hence laterwards can
be implemented directly. Some of the important results include the vibrational features
that the model experience while performing the gait, for a fixed amount of time.

5. Future Work
For future work, the same model can be enhanced into utilisation in several domains,
like prosthetic analysis and fracture analysis. One of the major tasks would be to make
the system user friendly and make any MATLAB access the diversity of the modelling a
musculoskeletal model. In terms of documentation, a proper website or information

Page | 14
brochure can be designed dedicated to the modelling parameters of the human model
and hence finding the optimum gait mechanism. In the report some of the functions
(that have been heavily used in modelling the sections have been mentioned), while
others are subjected to frequent experimentations.

6. Code
Here is the full code prepared for the demonstration of the same.

%% MATLAB script for the generation of a model


clc;
clear all;
close all;

% importing the existing model


import org.opensim.modeling.*
myModel = Model();

%% Geometry path
path = 'C:\OpenSim 4.1\Geometry';
ModelVisualizer.addDirToGeometrySearchPaths(path);

%% Adding ground
ground = myModel.getGround();
%
% % Add display geometry to the ground to visualize in the GUI
% % For the ground plane, an arbitrary plane of 5X5X(0.2)mm^3 shape is
taken
ground.attachGeometry(Mesh('treadmill.vtp'));
% --------------------------------------------------------------------
%% Adding pelvis
pelvis = Body();
pelvis.setName('pelvis');
pelvis.setMass(11.777);
pelvis.setMassCenter(Vec3(-0.0707,0,0));
pelvis.setInertia(Inertia(0.1028,0.0871,0.0579,0,0,0));

% Adding the Joint


LocationInParent = Vec3(0,0,2);
OrientationInParent = Vec3(0,0,0);
LocationInChild = Vec3(0,0,0);
OrientationInChild = Vec3(0,0,0);

ground_pelvis = FreeJoint('ground_pelvis', ground, ...


LocationInParent, OrientationInParent, pelvis, ...
LocationInChild, OrientationInChild);

pelvis_tilt = ground_pelvis.upd_coordinates(0);
pelvis_tilt.setName('pelvis_tilt');
pelvis_tilt.setRange([-1.57079633, 1.57079633]);
pelvis_tilt.setDefaultValue(0);

pelvis_list = ground_pelvis.upd_coordinates(1);
pelvis_list.setName('pelvis_list');
pelvis_list.setRange([-1.57079633, 1.57079633]);
pelvis_list.setDefaultValue(0);

Page | 15
pelvis_rotation = ground_pelvis.upd_coordinates(2);
pelvis_rotation.setName('pelvis_rotation');
pelvis_rotation.setRange([-1.57079633, 1.57079633]);
pelvis_rotation.setDefaultValue(0);

pelvis_tx = ground_pelvis.upd_coordinates(3);
pelvis_tx.setRange([-5,5]);
pelvis_tx.setName('pelvis_tx');
pelvis_tx.setDefaultValue(0);
pelvis_tx.setDefaultSpeedValue(0);

pelvis_ty = ground_pelvis.upd_coordinates(4);
pelvis_ty.setRange([-1,2]);
pelvis_ty.setName('pelvis_ty');
pelvis_ty.setDefaultValue(0.95);
pelvis_ty.setDefaultSpeedValue(0);

pelvis_tz = ground_pelvis.upd_coordinates(5);
pelvis_tz.setRange([-3,3]);
pelvis_tz.setName('pelvis_tz');
pelvis_tz.setDefaultValue(0);
pelvis_tz.setDefaultSpeedValue(0);

% Add visible objects


pelvis.attachGeometry(Mesh('pelvis.vtp'));
pelvis.attachGeometry(Mesh('sacrum.vtp'));
pelvis.attachGeometry(Mesh('l_pelvis.vtp'));
% myModel.addJoint(ground_pelvis);
% myModel.addJoint(ground_pelvis);
% pelvis.getDisplayer().setScaleFactors([1,1,1]);

% Add Body to Model


myModel.addBody(pelvis);
% ---------------------------------------------------------------------
%% Adding Femur_Right
femur_r = Body();
femur_r.setName('femur_r');
femur_r.setMass(9.3014);
femur_r.setMassCenter(Vec3(0,-0.17,0));
femur_r.setInertia(Inertia(0.1339,0.0351,0.1412,0,0,0));

% Adding the Joint


LocationInParent = Vec3(-0.0707,-0.0661,0.0835);
OrientationInParent = Vec3(0,0,0);
LocationInChild = Vec3(0,0,0);
OrientationInChild = Vec3(0,0,0);

hip_r = FreeJoint('hip_r', pelvis, ...


LocationInParent, OrientationInParent, femur_r, ...
LocationInChild, OrientationInChild);

hip_flexion_r = hip_r.upd_coordinates(0); % T about x


hip_flexion_r.setRange([-2.0943951, 2.0943951]);
hip_flexion_r.setName('hip_flexion_r');
hip_flexion_r.setDefaultValue(0);
hip_flexion_r.setDefaultSpeedValue(0);

hip_adduction_r = hip_r.upd_coordinates(1);
hip_adduction_r.setRange([-2.0943951, 2.0943951]);

Page | 16
hip_adduction_r.setName('hip_adduction_r');
hip_adduction_r.setDefaultValue(0);
hip_adduction_r.setDefaultSpeedValue(0);

hip_rotation_r = hip_r.upd_coordinates(1);
hip_rotation_r.setRange([-2.0943951, 2.0943951]);
hip_rotation_r.setName('hip_adduction_r');
hip_rotation_r.setDefaultValue(0);
hip_rotation_r.setDefaultSpeedValue(0);

femur_r.attachGeometry(Mesh('femur_r.vtp'));
myModel.addJoint(hip_r);

myModel.addBody(femur_r);
% --------------------------------------------------------------------
% % Adding Tibia_Right
tibia_r = Body();
tibia_r.setName('tibia_r');
tibia_r.setMass(3.7075);
tibia_r.setMassCenter(Vec3(0,-0.1867,0));
tibia_r.setInertia(Inertia(0.0504,0.0051,0.0511,0,0,0));

LocationInParent = Vec3(0,-0.38,0);
OrientationInParent = Vec3(0,0,0);
LocationInChild = Vec3(0,0,0);
OrientationInChild = Vec3(0,0,0);

knee_r = FreeJoint('knee_r', femur_r, ...


LocationInParent, OrientationInParent, tibia_r, ...
LocationInChild, OrientationInChild);

knee_angle_r = knee_r.upd_coordinates(0);
knee_angle_r.setName('knee_angle_r');
knee_angle_r.setRange([-2.0943951, 0.17453293]);
knee_angle_r.setDefaultValue(0);
knee_angle_r.setDefaultSpeedValue(0);

tibia_r.attachGeometry(Mesh('tibia_r.vtp'));
tibia_r.attachGeometry(Mesh('fibula.vtp'));
myModel.addJoint(knee_r);

myModel.addBody(tibia_r);
% --------------------------------------------------------------------
% Adding the Talus Right
talus_r = Body();
talus_r.setName('talus_right');
talus_r.setMass(0.10000000000000001);
talus_r.setMassCenter(Vec3(0,-0.1867,0));
talus_r.setInertia(Inertia(0.0504,0.0051000000000000004,0.0511,0,0,0));

LocationInParent = Vec3(0,-0.43,0);
OrientationInParent = Vec3(0,0,0);
LocationInChild = Vec3(0,0,0);
OrientationInChild = Vec3(0,0,0);

ankle_r = FreeJoint('ankle_r', tibia_r, ...


LocationInParent, OrientationInParent, talus_r, ...
LocationInChild, OrientationInChild);

Page | 17
ankle_angle_r = ankle_r.upd_coordinates(0);
ankle_angle_r.setName('ankle_angle_r');
ankle_angle_r.setRange([-1.57079633, 1.57079633]);
ankle_angle_r.setDefaultValue(0);
ankle_angle_r.setDefaultSpeedValue(0);

talus_r.attachGeometry(Mesh('talus.vtp'));
myModel.addJoint(ankle_r);

myModel.addBody(talus_r);
% --------------------------------------------------------------------
% Adding Calcn Right
calcn_r = Body();
calcn_r.setName('calcn_r');
calcn_r.setMass(1.25);
calcn_r.setMassCenter(Vec3(0.10000000000000001,0.02999999999999999,0));
calcn_r.setInertia(Inertia(0.0014,0.0038999999999999998,0.00410000000000000
03,0,0,0));

LocationInParent = Vec3(-0.04877,-0.04195,0.00792);
OrientationInParent = Vec3(0,0,0);
LocationInChild = Vec3(0,0,0);
OrientationInChild = Vec3(0,0,0);

subtalar_r = FreeJoint('subtalar_r', talus_r, ...


LocationInParent, OrientationInParent, calcn_r, ...
LocationInChild, OrientationInChild);

subtalar_angle_r = subtalar_r.upd_coordinates(0);
subtalar_angle_r.setName('subtalar_angle_r');
subtalar_angle_r.setRange([-1.57079633, 1.57079633]);
subtalar_angle_r.setDefaultValue(0);
subtalar_angle_r.setDefaultSpeedValue(0);

calcn_r.attachGeometry(Mesh('foot.vtp'));
myModel.addJoint(subtalar_r);

myModel.addBody(calcn_r);
% --------------------------------------------------------------------
% Adding Toes_right
toes_r = Body();
toes_r.setName('toes_r');
toes_r.setMass(0.21659999999999999);
toes_r.setMassCenter(Vec3(0.034599999999999999,0.0060000000000000001,-
0.017500000000000002));
toes_r.setInertia(Inertia(0.0001,0.00020000000000000001,0.0001,0,0,0));

LocationInParent = Vec3(0.1788,-0.002,0.00108);
OrientationInParent = Vec3(0,0,0);
LocationInChild = Vec3(0,0,0);
OrientationInChild = Vec3(0,0,0);

mtp_r = FreeJoint('mtp_r', calcn_r, ...


LocationInParent, OrientationInParent, ...
toes_r, LocationInChild, OrientationInChild);

mtp_angle_r = mtp_r.upd_coordinates(0);
mtp_angle_r.setName('mtp_angle_r');
mtp_angle_r.setRange([-1.57079633, 1.57079633]);

Page | 18
mtp_angle_r.setDefaultValue(0);
mtp_angle_r.setDefaultSpeedValue(0);

toes_r.attachGeometry(Mesh('bofoot.vtp'));
myModel.addJoint(mtp_r);

myModel.addBody(toes_r);
% --------------------------------------------------------------------
% Adding the prosthesis
pros_r = Body();
pros_r.setName('pros_r');
pros_r.setMass(1.5666);
pros_r.setMassCenter(Vec3(0,-0.1867,0));
pros_r.setInertia(Inertia(0,0,0,0,0,0));

LocationInParent = Vec3(-10,-10,10);
OrientationInParent = Vec3(0,0,0);
LocationInChild = Vec3(0,0,0);
OrientationInChild = Vec3(0,-90,0);

foot_r = FreeJoint('knee_r', tibia_r, ...


LocationInParent, OrientationInParent, pros_r, ...
LocationInChild, OrientationInChild);

foot_angle_l = foot_r.upd_coordinates(0);
foot_angle_l.setName('foot_angle_r');
foot_angle_l.setRange([-2.0943951, 0.17453293]);
foot_angle_l.setDefaultValue(0);
foot_angle_l.setDefaultSpeedValue(0);

pros_r.attachGeometry(Mesh('humanfootv5.obj'));
myModel.addJoint(foot_r);

myModel.addBody(pros_r);

% --------------------------------------------------------------------
% Adding Femur_Left
femur_l = Body();
femur_l.setName('femur_l');
femur_l.setMass(9.3014);
femur_l.setMassCenter(Vec3(0,-0.17,0));
femur_l.setInertia(Inertia(0.1339,0.0351,0.14121,0,0,0));

LocationInParent = Vec3(-0.0707,-0.0611,-0.0835);
OrientationInParent = Vec3(0,0,0);
LocationInChild = Vec3(0,0,0);
OrientationInChild = Vec3(0,0,0);

hip_l = FreeJoint('hip_l', pelvis, ...


LocationInParent, OrientationInParent, femur_l, ...
LocationInChild, OrientationInChild);

hip_flexion_l = hip_l.upd_coordinates(0); % T about x


hip_flexion_l.setRange([-2.0943951, 2.0943951]);
hip_flexion_l.setName('hip_flexion_l');
hip_flexion_l.setDefaultValue(0);
hip_flexion_l.setDefaultSpeedValue(0);

hip_adduction_l = hip_l.upd_coordinates(1);

Page | 19
hip_adduction_l.setRange([-2.0943951, 2.0943951]);
hip_adduction_l.setName('hip_adduction_l');
hip_adduction_l.setDefaultValue(0);
hip_adduction_l.setDefaultSpeedValue(0);

hip_rotation_l = hip_l.upd_coordinates(2);
hip_rotation_l.setRange([-2.0943951, 2.0943951]);
hip_rotation_l.setName('hip_adduction_l');
hip_rotation_l.setDefaultValue(0);
hip_rotation_l.setDefaultSpeedValue(0);

femur_l.attachGeometry(Mesh('femur_l.vtp'));
myModel.addJoint(hip_l);

myModel.addBody(femur_l);
% --------------------------------------------------------------------
% Adding Tibia_left
tibia_l = Body();
tibia_l.setName('tibia_l');
tibia_l.setMass(0.0504);
tibia_l.setMassCenter(Vec3(0,-0.1867,0));
tibia_l.setInertia(Inertia(0.0504,0.0051,0.0511,0,0,0));

LocationInParent = Vec3(0,-0.38,0);
OrientationInParent = Vec3(0,0,0);
LocationInChild = Vec3(0,0,0);
OrientationInChild = Vec3(0,0,0);

knee_l = FreeJoint('knee_r', femur_l, ...


LocationInParent, OrientationInParent, tibia_l, ...
LocationInChild, OrientationInChild);

knee_angle_l = knee_l.upd_coordinates(0);
knee_angle_l.setName('knee_angle_r');
knee_angle_l.setRange([-2.0943951, 0.17453293]);
knee_angle_l.setDefaultValue(0);
knee_angle_l.setDefaultSpeedValue(0);

tibia_l.attachGeometry(Mesh('tibia_l.vtp'));
tibia_l.attachGeometry(Mesh('l_fibula.vtp'));
myModel.addJoint(knee_l);

myModel.addBody(tibia_l);
% --------------------------------------------------------------------
% Adding Talus_Left
talus_l = Body();
talus_l.setName('talus_l');
talus_l.setMass(0.1);
talus_l.setMassCenter(Vec3(0,0,0));
talus_l.setInertia(Inertia(0.001,0.001,0.001,0,0,0));

LocationInParent = Vec3(0,-0.43,0);
OrientationInParent = Vec3(0,0,0);
LocationInChild = Vec3(0,0,0);
OrientationInChild = Vec3(0,0,0);

subtalar_l = FreeJoint('ankle_joint', tibia_l, ...


LocationInParent, OrientationInParent, ...
talus_l, LocationInChild, OrientationInChild);

Page | 20
subtalar_angle_l = subtalar_l.upd_coordinates(0);
subtalar_angle_l.setName('ankle_angle_l');
subtalar_angle_l.setRange([-1.57079633, 1.57079633]);
subtalar_angle_l.setDefaultValue(0);
subtalar_angle_l.setDefaultSpeedValue(0);

talus_l.attachGeometry(Mesh('l_talus.vtp'));
myModel.addJoint(subtalar_l);

myModel.addBody(talus_l);
% --------------------------------------------------------------------
% Adding Calcn_Left
calcn_l = Body();
calcn_l.setName('calcn_l');
calcn_l.setMass(1.25);
calcn_l.setMassCenter(Vec3(0.1,0.03,0));
calcn_l.setInertia(Inertia(0.0014,0.0039,0.0041,0,0,0));

LocationInParent = Vec3(-0.04877, -0.04195, -0.00792);


OrientationInParent = Vec3(0,0,0);
LocationInChild = Vec3(0,0,0);
OrientationInChild = Vec3(0,0,0);

subtalar_l = FreeJoint('subtalar_l', talus_l, ...


LocationInParent, OrientationInParent, ...
calcn_l, LocationInChild, OrientationInChild);

subtalar_angle_l = subtalar_l.upd_coordinates(0);
subtalar_angle_l.setName('subtalar_angle_l');
subtalar_angle_l.setRange([-1.57079633, 1.57079633]);
subtalar_angle_l.setDefaultValue(0);
subtalar_angle_l.setDefaultSpeedValue(0);

calcn_l.attachGeometry(Mesh('l_foot.vtp'));
myModel.addJoint(subtalar_l);

myModel.addBody(calcn_l);
% --------------------------------------------------------------------
% Adding Toes_Left
toes_l = Body();
toes_l.setName('toes_l');
toes_l.setMass(0.2166);
toes_l.setMassCenter(Vec3(0.0346,0.006,0.0175));
toes_l.setInertia(Inertia(0.0001,0.0002,0.0001,0,0,0));

LocationInParent = Vec3(0.1788,-0.002,-0.00108);
OrientationInParent = Vec3(0,0,0);
LocationInChild = Vec3(0,0,0);
OrientationInChild = Vec3(0,0,0);

mtp_l = FreeJoint('mtp_l', calcn_l, ...


LocationInParent, OrientationInParent, ...
toes_l, LocationInChild, OrientationInChild);

mtp_angle_l = mtp_l.upd_coordinates(0);
mtp_angle_l.setName('mtp_angle_l');
mtp_angle_l.setRange([-1.57079633, 1.57079633]);
mtp_angle_l.setDefaultValue(0);

Page | 21
mtp_angle_l.setDefaultSpeedValue(0);

toes_l.attachGeometry(Mesh('l_bofoot.vtp'));
myModel.addJoint(mtp_l);

myModel.addBody(toes_l);

ground = Body();
ground.setName('ground');
ground.attachGeometry(Mesh('treadmill.vtp'));

% --------------------------------------------------------------------
% Adding Torso
torso = Body();
torso.setName('torso');
torso.setMass(34.2366);
torso.setMassCenter(Vec3(-0.03,0.32,0));
torso.setInertia(Inertia(1.47445,0.7555,1.4317,0,0,0));

LocationInParent = Vec3(-0.1007,0.0815,0);
OrientationInParent = Vec3(0,0,0);
LocationInChild = Vec3(0,0,0);
OrientationInChild = Vec3(0,0,0);

back = FreeJoint('back', pelvis, ...


LocationInParent, OrientationInParent, torso, ...
LocationInChild, OrientationInChild);

lumbar_extension = back.upd_coordinates(0);
lumbar_extension.setName('lumbar_extension');
lumbar_extension.setRange([-1.57079633, 1.57079633]);
lumbar_extension.setDefaultValue(0);
lumbar_extension.setDefaultSpeedValue(0);

lumbar_bending = back.upd_coordinates(1);
lumbar_bending.setName('lumbar_bending');
lumbar_bending.setRange([-1.57079633, 1.57079633]);
lumbar_bending.setDefaultValue(0);
lumbar_bending.setDefaultSpeedValue(0);

lumbar_rotation = back.upd_coordinates(2);
lumbar_rotation.setName('lumbar_rotation');
lumbar_rotation.setRange([-1.57079633, 1.57079633]);
lumbar_rotation.setDefaultValue(0);
lumbar_rotation.setDefaultSpeedValue(0);

torso.attachGeometry(Mesh('hat_spine.vtp'));
torso.attachGeometry(Mesh('hat_jaw.vtp'));
torso.attachGeometry(Mesh('hat_skull.vtp'));
torso.attachGeometry(Mesh('hat_ribs.vtp'));
myModel.addJoint(back);

myModel.addBody(torso);
% --------------------------------------------------------------------
% Final Print of the Model
myModel.finalizeConnections();
myModel.finalizeConnections();
myModel.print('modelfixed.osim');

Page | 22
---THE END---

Page | 23

You might also like