...
Below are some useful (and necessary) resources that you should read before you begin and keep handy while you build your model;
...
Section |
---|
|
Column |
---|
|
Code Block |
---|
| %% 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 |
---|
| 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
...
Section |
---|
|
Column |
---|
|
Code Block |
---|
| //% Section: Add HuntCrossleyForces
stiffness = 1000000;
dissipation = 2.0;
staticFriction = 0.8;
dynamicFriction = 0.4;
viscousFriction = 0.4;
transitionVelocity = 0.2;
% Make a Hunt Crossley Force for Right Hip and update parameters
HuntCrossleyRightHip = HuntCrossleyForce();
HuntCrossleyRightHip.setName('RHipForce');
HuntCrossleyRightHip.addGeometry('RHipContact');
HuntCrossleyRightHip.addGeometry('PlatformContact');
HuntCrossleyRightHip.setStiffness(stiffness);
HuntCrossleyRightHip.setDissipation(dissipation);
HuntCrossleyRightHip.setStaticFriction(staticFriction);
HuntCrossleyRightHip.setDynamicFriction(dynamicFriction);
HuntCrossleyRightHip.setViscousFriction(viscousFriction);
HuntCrossleyRightHip.setTransitionVelocity(transitionVelocity);
osimModel.addForce(HuntCrossleyRightHip); |
|
Column |
---|
| A common bug is misspelling the name of the contact element in the call to addGeometry(). Matlab does not know if you have named the correct element, so the program will execute without an error in Matlab, but the resulting model will generate an error when it is loaded into OpenSim. |
|
...
Section |
---|
|
Column |
---|
|
Code Block |
---|
| % TODO: Construct CoordinateLimitForces Here
% ********** BEGIN CODE **********
% 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 Right Hip Coordinate Limit Force
RHipLimitTorque = CoordinateLimitForce();
RHipLimitTorque.setName('RHipLimitTorque')
RHipLimitTorque.set_coordinate('RHip_rz');
RHipLimitTorque.setUpperStiffness(upperStiffness);
RHipLimitTorque.setLowerStiffness(lowerStiffness);
RHipLimitTorque.setUpperLimit(hipUpperLimit);
RHipLimitTorque.setLowerLimit(hipLowerLimit);
RHipLimitTorque.setDamping(damping);
RHipLimitTorque.setTransition(transition)
osimModel.addForce(RHipLimitTorque); |
|
|
...
Search for CoordinateLimitForce in the OpenSim API documentation and find the method for constructing the CoordinateLimitForce with parameters. For the remaining three Leg coordinates, create a new set of CoordinateLimitForce objects (using the same parameter values as above) and add them to the model.
...
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.
...