How do I properly import and scale a CAD file?

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Chongyuan Feng
Posts: 4
Joined: Fri Mar 01, 2019 8:16 pm

How do I properly import and scale a CAD file?

Post by Chongyuan Feng » Fri Feb 19, 2021 9:14 am

Hello, I was trying to import a cuff(.obj) file to the Dynamic_Walker model via Matlab API. I changed the origional Add_CustomFeet matlab script to add a cuff to the shank (similar to the cuff in AFO tutorial). However, the model was sized wrong in the GUI. I have no idea what to do to scale the object. Should I change the size in Matlab or Solidworks? and if so, how would I achieve that?

Code: Select all

%% Import OpenSim Libraries
import org.opensim.modeling.*

%% Define the Model File Path.
model_path = 'DynamicWalkerModel.osim';

%% Instantiate the Model
newModel = Model(model_path);
newModel.setName('WalkerModel_cuff');

%% Define the Cuff mesh name
meshPath = 'Cuff1.obj';

%% Add Bodies, joints and forces for the cuff
% Make Cuff Bodies
mass = 0.0001;
massCenter = Vec3(0);
inertia = Inertia(1,1,.0001,0,0,0);
leftCuff = Body('LeftCuff', mass , massCenter, inertia);

% Add visual objects of the Cuff
leftCuff.attachGeometry( Mesh(meshPath) );

% Get a reference to the shank bodies
leftShank= newModel.getBodySet().get('LeftShank');

% Make Weld Joints for the Cuff
locationInParent = Vec3(0.075,-0.2,0);
orientationInParent = Vec3(0);
locationInChild = Vec3(0);
orientationInChild = Vec3(0);
cuff_l = WeldJoint('cuff_l',leftShank, locationInParent, orientationInParent, leftCuff, locationInChild, orientationInChild);

% Add the body and joint to the model
newModel.addBody(leftCuff);
newModel.addJoint(cuff_l);

% Define Coordinate Limit Force Parameters
upperStiffness = 0.5;
lowerStiffness = 0.5;
kneeUpperLimit = 0;
kneeLowerLimit = -140;
hipUpperLimit = 100;
hipLowerLimit = -100;
damping = 0.025;
transition = 5;

% Make a Left Cuff Coordinate Limit Force
LCuffForce = CoordinateLimitForce();
LCuffForce.setName('LCuffForce')
LCuffForce.set_coordinate('RHip_rz');
LCuffForce.setUpperStiffness(upperStiffness);
LCuffForce.setLowerStiffness(lowerStiffness);
LCuffForce.setUpperLimit(hipUpperLimit);
LCuffForce.setLowerLimit(hipLowerLimit);
LCuffForce.setDamping(damping);
LCuffForce.setTransition(transition)

% Add forces.
newModel.addForce(LCuffForce);

%% finalize connections
newModel.finalizeConnections()

%% Print the model to file.
newFilename = strrep(model_path, '.osim', '_CustomCuff.osim');
isSuccessful = newModel.print(newFilename);
if (~isSuccessful), error('Model printed to file failed'); end
fprintf('Model printed to file successfully\n');
Attachments
capture.PNG
capture.PNG (643.27 KiB) Viewed 405 times

Tags:

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

Re: How do I properly import and scale a CAD file?

Post by Thomas Uchida » Fri Feb 19, 2021 8:12 pm

The Mesh class has a property called scale_factors (https://simtk.org/api_docs/opensim/api_ ... 427f15c5f2). You should be able to adjust this property in Matlab and/or using the Properties panel in the GUI.

POST REPLY