Add Physical Offset frame to Joint API

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Bryce Killen
Posts: 104
Joined: Mon Nov 24, 2014 7:12 pm

Add Physical Offset frame to Joint API

Post by Bryce Killen » Thu May 05, 2022 7:36 am

HI all,

I am trying to programatically add a physiscal offset frame to an existing model which currently does not have any frame. My primary problem is that I cannot edit/update the " socket_parent " is the Physical Offset Frame - and the " socket_parent_frame " of the joint which I suspect is becuase of a related issue. The lines which " do not work" are markerd with # % DOES NOT UPDATE

My code is below

Code: Select all

import opensim as osim

model = osim.Model('lenhart2015_updMuscPath.osim')

# make a copy of an exist physcial offset frame
pfo = model.getJointSet().get('femur_femur_distal_r').get_frames(0).clone()
# rename the frame
pfo.setName('knee_align_r')
# set orientation
pfo.set_orientation(osim.Vec3(1.5,0,0))
# set translation
pfo.set_translation(osim.Vec3(0,0,0))
# update the socket_parent of the frame

# % DOES NOT UPDATE pfo.setParentFrame(model.getBodySet().get('femur_distal_r'))

# ATEMPT 2 to update the socket_parent of the frame
# % DOES NOT UPDATE pfo.connectSocket_parent(model.getBodySet().get('femur_distal_r'))

# add the Physcial offset frame to the joint
model.getJointSet().get('knee_r').set_frames(0,pfo)

# Try and change the socket_parent_frame of the joint 
# % DOES NOT UPDATEmodel.getJointSet().get('knee_r').connectSocket_parent_frame(model.getJointSet().get('knee_r').get_frames(0))

model.updJointSet()
model.printToXML('testModel.osim')
Using this code - the physcial frame is added to the joint BUT the socket_frame , and socket_parent_frame are still from the "cloned" physical frame.

Thanks in advance for any tips/advice

Bryce

Tags:

User avatar
Pavlos Silvestros
Posts: 13
Joined: Tue Apr 12, 2022 9:57 am

Re: Add Physical Offset frame to Joint API

Post by Pavlos Silvestros » Fri May 06, 2022 11:17 am

Hey Bryce,

How's it going?

Have you tried downcasting the Body frame to a PhysicalFrame? It worked for me in Matlab as I was having a similar issue.

Here's my code:

Code: Select all

close all;
clear;
clc;

% Import OpenSim 4.3 libraries
import org.opensim.modeling.*

model_name='FullShoulderModel.osim';

osim_model=Model(['..\..\OpenSim\In\Models\' model_name]);
init_state=osim_model.initSystem();

% safeDownCast Body::<scapula> to PhysicalFrame
PF_scapula=PhysicalFrame.safeDownCast(osim_model.getBodySet.get('scapula'));

% Create Frame
POF_glenoid_centre = PhysicalOffsetFrame();
POF_glenoid_centre.setName('glenoid_centre');
POF_glenoid_centre.setParentFrame(PF_scapula);

% Centre of Glenoid fossa @ scapular in FullShoulderModel.osim
POF_glenoid_centre.set_translation(Vec3(-0.0300675, -0.0391136, -0.015)); 

% Rotate for x-axis as parallel as posible to glenoid surf
POF_glenoid_centre.set_orientation(Vec3(0, 0.55, 0)); % @ scapular in FullShoulderModel.osim

% Pass back to the Model
osim_model.updBodySet.get('scapula').addComponent(POF_glenoid_centre);

% Finalise Connections
osim_model.finalizeConnections;

osim_model.print(['..\..\OpenSim\In\Models\' model_name(1:end-5) 'glC.osim']);
Hope it helps!

Cheers,
Pavlos

User avatar
Bryce Killen
Posts: 104
Joined: Mon Nov 24, 2014 7:12 pm

Re: Add Physical Offset frame to Joint API

Post by Bryce Killen » Mon May 09, 2022 12:39 am

Hi Pavlos,

Thanks for the tips and the code

I'll give it a try !

Hope all is well mate

Cheers

POST REPLY