In this example, you will add a body and an actuator to an existing OpenSim model by editing its xml file. You can find the model file (arm26.osim) in the models folder under your OpenSim installation directory.
You will need to download an XML editor to work through this example. Some free options include:
- notepad++ (http://notepad-plus.sourceforge.net/uk/site.htm)
You can also download a pdf of this page by clicking on the Tools link in the top right corner and selecting "Export to PDF".
Connecting an Additional Segment to the Model
- Open Model File in XML. Use an XML editor (e.g., Notepad++) to open the OpenSim model file (e.g., arm26.osim). When collapsed to the 3rd level (e.g., Alt+3 in Notepad++), your model file should look like the figure below.
- In Notepad ++ if the model file does not have the markup or ability to collapse levels, you may need to set the Language to XML (Menu Bar > Language > XML)
- Explore the Model. The Model tag has eight main sets named: BodySet, ConstraintSet, ForceSet, MarkerSet, ContactGeometrySet, ControllerSet, ProbeSet, and ComponentSet.
- Explore the Body Set. The BodySet tag has three Body objects named ground, r_humerus, and r_ulna_radius_hand.
- Save a copy of the Model File. From the XML editor, save a copy of the OpenSim model file (arm26_with_bucket.osim).
- Add New Body. Add a new Body named bucket immediately below the Body named r_ulna_radius_hand.
- Specify Mass Properties. Add tags and enter values for the mass, mass_center, inertia_xx, inertia_yy, inertia_zz, interia_xy, inertia_xz, and inertia_yz for the bucket as seen below:
- Specify Joint. Add tags and names for the PinJoint and parent_body, and tags and values for location_in_parent, orientation_in_parent, location, and orientation as seen below:
The location_in_parent and orientation_in_parent tags define the position and orientation of the joint with respect to the parent body origin. In the above example, the vector from the parent body r_ulna_radius_hand to the joint r_handle is [0.031 -0.031 0.07] and the orientation of the joint (in a zero pose) is exactly the same as the orientation of the parent body (in a zero pose). The location_in_parent and orientation_in_parent vectors should be given in the coordinate frame of the parent body. In most cases, the location_in_parent and orientation_in_parent tags are all that's required to specify the new joint (in which case, the child body origin, e.g., bucket, would be located at the joint center of r_handle). Additionally, the local location and orientation offset of the joint center with respect to the child body origin can be specified using the location and orientation tags. The above description of joints in OpenSim is illustrated here: JointReferenceFrames.jpg
- Specify Generalized Coordinate. Add a tag and name for the Coordinate, and add tags and values for motion type, default_value, default_speed_value, initial_value, range, clamped, and locked as seen below:
- Place the code within the PinJoint tags, immediately following the orientation tag
- Specify Geometry File. Add a tag for VisibleObject and add the appropriate tags for GeometrySet and other properties as seen below:
- Place code after the Joint definition, but still within the body tags
- Specify DisplayGeometry including Geometry_File in the GeometrySet
- Save Model File. From the XML editor, save the OpenSim model file (e.g., arm26_with_bucket.osim). Now open your new model in OpenSim to see the bucket!
Adding an Additional Actuator
- Explore the ForceSet. The ForceSet tag has six Thelen2003Muscle objects named TRIlong, TRIlat, TRImed, BIClong, BICshort, and BRA.
- Add New Actuator. Add a CoordinateActuator object named r_handle_rot_force immediately below the Thelen2003Muscle named BRA. Associate this CoordinateActuator with the r_handle_rot coordinate and specify an optimal_force of 1000.
- Save Model File. From the XML editor, save the OpenSim model file (e.g., arm26_with_bucket.osim).