Info |
---|
This problem was contributed by Thomas Uchida at the University of Ottawa. |
In this problem, we will use the OpenSim API to check the solution to problem 7.3 Introduction to transformation matrices. (If you haven't completed that problem yet, please start there.)
...
(b) Read the Common Scripting Commands and Scripting in the GUI pages in the OpenSim documentation. You may also wish to refer to the API documentation for more information about the OpenSim classes that are used below.
(c) Define frame A and point p in a model. You can do this by writing a script that creates a new model, or you could add components to an existing model. For simplicity, the instructions here will add components to the arm26 model. First, open arm26.osim. Next, type the following in the ScriptingShell Window, filling in the missing information as indicated:
Code Block |
---|
language | py |
---|
theme | Midnight |
---|
linenumbers | true |
---|
|
model = getCurrentModel()
sphere = modeling.Sphere(0.02)
transA = modeling.Transform( modeling.Vec3(a,b,c) ) #fill in a,b,c
frameA = modeling.PhysicalOffsetFrame(model.getGround(), transA)
frameA.setName('frameA')
model.addComponent(frameA)
frameA.attachGeometry(sphere)
m = modeling.Marker('p', frameA, modeling.Vec3(a,b,c) ) #fill in a,b,c
model.addMarker(m)
model.finalizeConnections()
model.print('step1.osim') |
(d) Close the arm26 old model and open step1.osim. You will see a sphere at the origin of frame A and a marker at point p. Next, we will add frame B. Type the following in the ScriptingShell Window, filling in the missing information as indicated:
Code Block |
---|
language | py |
---|
theme | Midnight |
---|
linenumbers | true |
---|
|
model = getCurrentModel()
angle = 0 #fill in the angle
rot = modeling.Rotation(angle, modeling.CoordinateAxis(2)) #Note: CoordinateAxis(2) refers to the Z-axis
transB = modeling.Transform(rot, modeling.Vec3(a,b,c)) #fill in a,b,c
frameA = model.getComponent('frameA')
frameA = modeling.PhysicalOffsetFrame.safeDownCast(frameA)
frameB = modeling.PhysicalOffsetFrame(frameA, transB)
frameB.setName('frameB')
model.addComponent(frameB)
model.finalizeConnections()
model.print('step2.osim') |
(e) Close the old model and open step2.osim. We will now calculate the coordinates of point p with respect to frame B. Type the following in the ScriptingShell Window and confirm that the result matches the coordinates you calculated in problem 7.3 Introduction to transformation matrices.
Code Block |
---|
language | py |
---|
theme | Midnight |
---|
linenumbers | true |
---|
|
model = getCurrentModel()
state = model.getWorkingState()
m = model.getMarkerSet().get('p')
frameB = model.getComponent('frameB')
frameB = modeling.PhysicalOffsetFrame.safeDownCast(frameB)
m.findLocationInFrame(state, frameB) |
Expand |
---|
title | Solution (only visible by instructors; please contact us to request access) |
---|
|
Include Page |
---|
| S7.3 Introduction to transformation matrices5 Transformations in OpenSim |
---|
| S7.3 Introduction to transformation matrices5 Transformations in OpenSim |
---|
|
|