Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Below are some useful (and necessary) resources that you should read before you begin and keep handy while you build your model;

...

Section
bordertrue


Column
width60%


Code Block
languagecpp
%% Import OpenSim Libraries into Matlab
import org.opensim.modeling.*

%% Define key model variables
pelvisWidth = 0.20; 
thighLength = 0.40; 
shankLength = 0.435;

%% Instantiate an (empty) OpenSim Model
osimModel = Model();
osimModel.setName('DynamicWalkerModel');

% Get a reference to the ground object
ground = osimModel.getGroundBodygetGround();

% Define the acceleration of gravity
osimModel.setGravity(Vec3(0, -9.80665, 0));

% TODO: Construct Bodies and Joints Here
% ********** BEGIN CODE **********


% **********  END CODE  **********

% TODO: Construct ContactGeometry and HuntCrossleyForces Here
% ********** BEGIN CODE **********


% **********  END CODE  **********

% TODO: Construct CoordinateLimitForces Here
% ********** BEGIN CODE **********


% **********  END CODE  **********

%% Initialize the System (checks model consistency). 
osimModel.initSystem();

% Save the model to a file
osimModel.print('DynamicWalkerModel.osim');
display(['DynamicWalkerModel.osim printed!']);



Column
width40%

One of the advantages of building Models with API functions vs with XML is the ability to store model parameters in variables. Here, we create variables for the pelvis width and the lengths of the thighs and shanks. These three variables are used throughout the exercise, such as when defining the joints, the display geometry, and the contact elements.

A Model object called "osimModel" is created and the name of the model is set to "DynamicWalkerModel." In the final model file, this has the effect of creating a Model XML element and setting the "name" attribute to DynamicWalkerModel (i.e., <Model name="DynamicWalkerModel"> ... </Model>).

The setGravity function sets the direction and magnitude of the acceleration due to gravity using a SimTK::Vec3, and adds the XML element <gravity> 0 -9.80665 0 </gravity> to the model.

The print command creates the resulting OpenSim model file. The print command is called after all of the Model Components (bodies, constraints, contact geometry, controllers, etc.) are added to the Model.


...

  • Right Thigh: Name: RightThigh, CoM Location: (0,0,0) m, Mass: 1 kg, BodyInertia: (2,2,0.02,0,0,0) kg-m2
    • Right Thigh Geometry: Ellipsoid where X & Z radii = thighLength/10, Y radii = thighLength/2
  • Right Hip Joint: JointName: RightThighToPelvis, CoordinateName: RHip_rz, DefaultValue: 30 deg, Range: -100 deg to 100 deg
  • Left Thigh: Name: LeftThigh, CoM Location: (0,0,0) m, Mass: 1 kg, BodyInertia: (2,2,0.02,0,0,0) kg-m2
    • Left Thigh Geometry: Ellipsoid where X & Z radii = thighLength/10, Y radii = thighLength/2
  • Left Hip Joint: JointName: LeftThighToPelvis, CoordinateName: LHip_rz, DefaultValue: -10 deg, Range: -100 deg to 100 deg
  • Right Shank: Name: RightShank, CoM Location: (0,0,0) m, Mass: 0.1 kg, BodyInertia: (12,12,10.002,0,0,0) kg-m2
    • Right Shank Geometry: Ellipsoid where X & Z radii = thighLengthshankLength/10, Y radii = thighLengthshankLength/2
  • Right Knee Joint: JointName: RightShankToThigh, CoordinateName: RKnee_rz, DefaultValue: -30 deg, Range: -100 deg to 0 deg
  • Left Shank: Name: LeftShank, CoM Location: (0,0,0) m, Mass: 0.1 kg, BodyInertia: (12,12,10.002,0,0,0) kg-m2
    • Left Shank Geometry: Ellipsoid where X & Z radii = thighLengthshankLength/10, Y radii = thighLengthshankLength/2
  • Left Knee Joint: JointName: LeftShankToThigh, CoordinateName: LKnee_rz, DefaultValue: -30 deg, Range: -100 deg to 0 deg

...

The model will simulate forward, but will likely fall immediately. Passive Dynamic walkers are sensitive to initial conditions; you can change the initial pose in the GUI and re-run the forward simulation. In the next example, we will augment the model to improve its stability.

...