Esempio n. 1
0
    def test_markAdopted2(self):
        a = osim.Model()

        # We just need the following not to cause a segfault.

        # Model add*
        pa = osim.PathActuator()
        pa.setName('pa')
        a.addForce(pa)

        probe = osim.Umberger2010MuscleMetabolicsProbe()
        probe.setName('probe')
        a.addProbe(probe)

        ma = osim.MuscleAnalysis()
        ma.setName('ma')
        a.addAnalysis(ma)

        pc = osim.PrescribedController()
        pc.setName('pc')
        a.addController(pc)

        body = osim.Body('body1', 1.0, osim.Vec3(0, 0, 0),
                         osim.Inertia(0, 0, 0))

        loc_in_parent = osim.Vec3(0, 0, 0)
        orient_in_parent = osim.Vec3(0, 0, 0)
        loc_in_body = osim.Vec3(0, 0, 0)
        orient_in_body = osim.Vec3(0, 0, 0)
        print "creating Weld Joint.."
        joint = osim.WeldJoint("weld_joint", a.getGround(), loc_in_parent,
                               orient_in_parent, body, loc_in_body,
                               orient_in_parent)
        print "adding a body .."
        a.addBody(body)
        print "adding a joint .."
        a.addJoint(joint)
        print "Creating a ConstantDistanceConstraint.."
        constr = osim.ConstantDistanceConstraint()
        constr.setBody1ByName("ground")
        constr.setBody1PointLocation(osim.Vec3(0, 0, 0))
        constr.setBody2ByName("body")
        constr.setBody2PointLocation(osim.Vec3(1, 0, 0))
        constr.setConstantDistance(1)
        a.addConstraint(constr)

        f = osim.BushingForce("bushing", "ground", "body", osim.Vec3(2, 2, 2),
                              osim.Vec3(1, 1, 1), osim.Vec3(0, 0, 0),
                              osim.Vec3(0, 0, 0))
        a.addForce(f)

        f2 = osim.BushingForce()
        a.addForce(f2)

        f3 = osim.SpringGeneralizedForce()
        a.addForce(f3)

        model = osim.Model(os.path.join(test_dir, "arm26.osim"))
        g = osim.CoordinateActuator('r_shoulder_elev')
        model.addForce(g)
Esempio n. 2
0
    def test_Joint(self):
        a = osim.Model()

        body = osim.Body('body', 1.0, osim.Vec3(0, 0, 0),
                         osim.Inertia(0, 0, 0))

        loc_in_parent = osim.Vec3(0, -0, 0)
        orient_in_parent = osim.Vec3(0, 0, 0)
        loc_in_body = osim.Vec3(0, 0, 0)
        orient_in_body = osim.Vec3(0, 0, 0)

        joint = osim.FreeJoint("joint", a.getGround(), loc_in_parent,
                               orient_in_parent, body, loc_in_body,
                               orient_in_parent)
        del joint
        spatialTransform = osim.SpatialTransform()
        joint = osim.CustomJoint("joint", a.getGround(), loc_in_parent,
                                 orient_in_parent, body, loc_in_body,
                                 orient_in_parent, spatialTransform)
        del joint
        joint = osim.EllipsoidJoint("joint", a.getGround(), loc_in_parent,
                                    orient_in_parent, body, loc_in_body,
                                    orient_in_parent, osim.Vec3(1, 1, 1))
        del joint
        joint = osim.BallJoint("joint", a.getGround(), loc_in_parent,
                               orient_in_parent, body, loc_in_body,
                               orient_in_parent)
        del joint
        joint = osim.PinJoint("joint", a.getGround(), loc_in_parent,
                              orient_in_parent, body, loc_in_body,
                              orient_in_parent)
        del joint
        joint = osim.SliderJoint("joint", a.getGround(), loc_in_parent,
                                 orient_in_parent, body, loc_in_body,
                                 orient_in_parent)
        del joint
        joint = osim.WeldJoint("joint", a.getGround(), loc_in_parent,
                               orient_in_parent, body, loc_in_body,
                               orient_in_parent)
        del joint
        joint = osim.GimbalJoint("joint", a.getGround(), loc_in_parent,
                                 orient_in_parent, body, loc_in_body,
                                 orient_in_parent)
        del joint
        joint = osim.UniversalJoint("joint", a.getGround(), loc_in_parent,
                                    orient_in_parent, body, loc_in_body,
                                    orient_in_parent)
        del joint
        joint = osim.PlanarJoint("joint", a.getGround(), loc_in_parent,
                                 orient_in_parent, body, loc_in_body,
                                 orient_in_parent)
        del joint
Esempio n. 3
0
def test_markAdopted():
    a = osim.Model()

    # We just need the following not to not cause a segfault.

    # Model add*
    a.addComponent(osim.PathActuator())
    a.addProbe(osim.Umberger2010MuscleMetabolicsProbe())
    a.addAnalysis(osim.MuscleAnalysis())
    a.addController(osim.PrescribedController())

    body = osim.Body('body', 1.0, osim.Vec3(0, 0, 0), osim.Inertia(0, 0, 0))

    loc_in_parent = osim.Vec3(0, -0, 0)
    orient_in_parent = osim.Vec3(0, 0, 0)
    loc_in_body = osim.Vec3(0, 0, 0)
    orient_in_body = osim.Vec3(0, 0, 0)
    joint = osim.WeldJoint("weld_joint", a.getGroundBody(), loc_in_parent,
                           orient_in_parent, body, loc_in_body,
                           orient_in_parent)

    a.addBody(body)

    constr = osim.ConstantDistanceConstraint()
    constr.setBody1ByName("ground")
    constr.setBody1PointLocation(osim.Vec3(0, 0, 0))
    constr.setBody2ByName("body")
    constr.setBody2PointLocation(osim.Vec3(1, 0, 0))
    constr.setConstantDistance(1)
    a.addConstraint(constr)

    # Force requires body names. If not provided, you get a segfault.
    f = osim.BushingForce()
    f.setBody1ByName("ground")
    f.setBody2ByName("body")
    a.addForce(f)

    model = osim.Model(os.environ['OPENSIM_HOME'] + "/Models/Arm26/arm26.osim")
    g = osim.CoordinateActuator('r_shoulder_elev')
    model.addForce(g)
def test_markAdoptedSets():

    # Set's.
    fus = osim.FunctionSet()
    fu1 = osim.Constant()
    fus.adoptAndAppend(fu1)
    del fus
    del fu1

    s = osim.ScaleSet()
    o = osim.Scale()
    s.adoptAndAppend(o)
    del s
    del o

    s = osim.ControlSet()
    o = osim.ControlLinear()
    s.adoptAndAppend(o)
    del s
    del o

    s = osim.BodyScaleSet()
    o = osim.BodyScale()
    s.adoptAndAppend(o)
    del s
    del o

    s = osim.PathPointSet()
    o = osim.PathPoint()
    s.adoptAndAppend(o)
    del s
    del o

    s = osim.IKTaskSet()
    o = osim.IKMarkerTask()
    s.adoptAndAppend(o)
    del s
    del o

    s = osim.MarkerPairSet()
    o = osim.MarkerPair()
    s.adoptAndAppend(o)
    del s
    del o

    s = osim.MeasurementSet()
    o = osim.Measurement()
    s.adoptAndAppend(o)
    del s
    del o

    s = osim.FrameSet()
    o = osim.Body()
    s.adoptAndAppend(o)
    del s
    del o

    s = osim.ForceSet()
    o = osim.CoordinateLimitForce()
    s.adoptAndAppend(o)
    del s
    del o
     
    s = osim.ForceSet()
    o = osim.SpringGeneralizedForce()
    s.append(o)
 
    s = osim.ProbeSet()
    o = osim.Umberger2010MuscleMetabolicsProbe()
    s.adoptAndAppend(o)
    del s
    del o

    a = osim.Model()
    body = osim.Body('body',
            1.0,
            osim.Vec3(0, 0, 0),
            osim.Inertia(0, 0, 0)
            )

    loc_in_parent = osim.Vec3(0, -0, 0)
    orient_in_parent = osim.Vec3(0, 0, 0)
    loc_in_body = osim.Vec3(0, 0, 0)
    orient_in_body = osim.Vec3(0, 0, 0)
    joint = osim.WeldJoint("weld_joint",
            a.getGround(),
            loc_in_parent, orient_in_parent,
            body,
            loc_in_body, orient_in_parent)
    a.addBody(body)


    constr = osim.ConstantDistanceConstraint()
    constr.setBody1ByName("ground")
    constr.setBody1PointLocation(osim.Vec3(0, 0, 0))
    constr.setBody2ByName("body")
    constr.setBody2PointLocation(osim.Vec3(1, 0, 0))
    constr.setConstantDistance(1)
    a.addConstraint(constr)
Esempio n. 5
0
def test_markAdoptedSets():

    # Set's.
    fus = osim.FunctionSet()
    fu1 = osim.Constant()
    fus.adoptAndAppend(fu1)
    del fus
    del fu1

    gs = osim.GeometrySet()
    dg = osim.DisplayGeometry()
    gs.adoptAndAppend(dg)
    del gs
    del dg

    s = osim.ScaleSet()
    o = osim.Scale()
    s.adoptAndAppend(o)
    del s
    del o

    s = osim.ForceSet()
    o = osim.BushingForce()
    s.adoptAndAppend(o)
    del s
    del o

    cs = osim.ControllerSet()
    csc = osim.PrescribedController()
    cs.adoptAndAppend(csc)
    del cs
    del csc

    s = osim.ContactGeometrySet()
    o = osim.ContactHalfSpace()
    s.adoptAndAppend(o)
    del s
    del o

    s = osim.AnalysisSet()
    o = osim.MuscleAnalysis()
    s.adoptAndAppend(o)
    del s
    del o

    s = osim.ControlSet()
    o = osim.ControlLinear()
    s.adoptAndAppend(o)
    del s
    del o

    s = osim.MarkerSet()
    o = osim.Marker()
    s.adoptAndAppend(o)
    del s
    del o

    s = osim.BodySet()
    o = osim.Body()
    s.adoptAndAppend(o)
    del s
    del o

    s = osim.BodyScaleSet()
    o = osim.BodyScale()
    s.adoptAndAppend(o)
    del s
    del o

    s = osim.CoordinateSet()
    o = osim.Coordinate()
    s.adoptAndAppend(o)
    del s
    del o

    s = osim.JointSet()
    o = osim.BallJoint()
    s.adoptAndAppend(o)
    del s
    del o

    s = osim.PathPointSet()
    o = osim.PathPoint()
    s.adoptAndAppend(o)
    del s
    del o

    s = osim.IKTaskSet()
    o = osim.IKMarkerTask()
    s.adoptAndAppend(o)
    del s
    del o

    s = osim.MarkerPairSet()
    o = osim.MarkerPair()
    s.adoptAndAppend(o)
    del s
    del o

    s = osim.MeasurementSet()
    o = osim.Measurement()
    s.adoptAndAppend(o)
    del s
    del o

    # TODO
    # s = osim.ProbeSet()
    # o = osim.Umberger2010MuscleMetabolicsProbe()
    # s.adoptAndAppend(o)
    # del s
    # del o

    s = osim.ConstraintSet()
    a = osim.Model()
    body = osim.Body('body', 1.0, osim.Vec3(0, 0, 0), osim.Inertia(0, 0, 0))

    loc_in_parent = osim.Vec3(0, -0, 0)
    orient_in_parent = osim.Vec3(0, 0, 0)
    loc_in_body = osim.Vec3(0, 0, 0)
    orient_in_body = osim.Vec3(0, 0, 0)
    joint = osim.WeldJoint("weld_joint", a.getGroundBody(), loc_in_parent,
                           orient_in_parent, body, loc_in_body,
                           orient_in_parent)
    a.addBody(body)

    constr = osim.ConstantDistanceConstraint()
    constr.setBody1ByName("ground")
    constr.setBody1PointLocation(osim.Vec3(0, 0, 0))
    constr.setBody2ByName("body")
    constr.setBody2PointLocation(osim.Vec3(1, 0, 0))
    constr.setConstantDistance(1)

    s.adoptAndAppend(constr)
Esempio n. 6
0
myModel.addJoint(crankToGround)

# === Cleats
cleat_r = osim.Body("cleat_r",cleat_mass,cleat_orParent,cleat_inertia)
cleat_l = osim.Body("cleat_l",cleat_mass,cleat_orParent,cleat_inertia)

cleat_geometry = osim.Mesh("cleat_simple.stl")
cleat_geometry.setColor(osim.Red)
cleat_r.attachGeometry(cleat_geometry.clone())
cleat_l.attachGeometry(cleat_geometry.clone())

myModel.addBody(cleat_r)
myModel.addBody(cleat_l)

cleat_r = osim.WeldJoint("cleat_rToCalc",calcn_r,cleat_locParent,cleat_orParent,cleat_r,cleat_locChild,cleat_orChild)
cleat_l = osim.WeldJoint("cleat_lToCalc",calcn_l,cleat_locParent,cleat_orParent,cleat_l,cleat_locChild,cleat_orChild)
myModel.addJoint(cleat_r)
myModel.addJoint(cleat_l)

# ==== Pedals
cleat_r_body = find_body(myModel,"cleat_r")
cleat_l_body = find_body(myModel,"cleat_l")
pedal_r = osim.Body("pedal_r",pedal_mass,pedal_orParent,pedal_inertia)
pedal_l = osim.Body("pedal_l",pedal_mass,pedal_orParent,pedal_inertia)

pedal_geometry = osim.Mesh("pedal_simple.stl")
pedal_geometry.setColor(osim.Orange)
pedal_r.attachGeometry(pedal_geometry.clone())
pedal_l.attachGeometry(pedal_geometry.clone())
Esempio n. 7
0
 #TODO: check order these should be in
 distalMedialSensorBody.attachGeometry(osim.Brick(osim.Vec3(sensorWidth/2, sensorLength/2, sensorDepth/2)))
 distalMedialSensorBody.get_attached_geometry(0).setColor(osim.Vec3(0/255,102/255,255/255)) #blue
 adjustedModel.addBody(distalMedialSensorBody)
 
 #Join the distal medial tibia sensor to the model
 #Get the marker location for the parent location
 locationInParent = adjustedModel.getMarkerSet().get('R.Tibia.Distal.Medial').get_location()
 orientationInParent = osim.Vec3(0,0,0) #Align to same axis as tibia
 #Set child details
 locationInChild = osim.Vec3(0,0,0)
 orientationInChild = osim.Vec3(0,0,0)
 #Create the joint
 distalMedialSensorJoint = osim.WeldJoint('distalMedialTibia_joint_r', #joint name
                                          adjustedModel.getBodySet().get('tibia_r'), #parent body
                                          locationInParent, orientationInParent,
                                          distalMedialSensorBody, #new body
                                          locationInChild, orientationInChild)
 
 #Add joint to the model
 adjustedModel.addJoint(distalMedialSensorJoint)
 
 #Edit color
 adjustedModel.getBodySet().get('distalMedialTibia_sensor_r').get_attached_geometry(0).getColor().get(2)
 
 #Finalise connections
 adjustedModel.finalizeConnections()
 
 # #Initialize the system (checks model consistency).
 # adjustedModel.initSystem()
 
Esempio n. 8
0
pullymass = .001
resting_length = 0.4
stiffness = 4454.76 * 4.
dissipation = 0.01
pulleyBody = osim.Body("PulleyBody", pullymass, Vec3(0),
                       osim.Inertia(0.1, 0.1, 0.1, 0.1, 0.1, 0.1))
#brick.inertia??
pulley = osim.WrapCylinder()
pulley.set_radius(0.05)
pulley.set_length(0.05)
pulley.set_quadrant("-y")

pulleyBody.addWrapObject(pulley)
osimModel.addBody(pulleyBody)
weld = osim.WeldJoint("weld", linkage3, Vec3(0), Vec3(0), pulleyBody, Vec3(0),
                      Vec3(0))
osimModel.addJoint(weld)

spring = osim.PathSpring("path_spring", resting_length, stiffness, dissipation)
spring.updGeometryPath().appendNewPathPoint("origin", linkage3,
                                            Vec3(0.05, 0.2, 0))
spring.updGeometryPath().appendNewPathPoint("insert", linkage2,
                                            Vec3(0.05, linkageLength2 - .2, 0))
spring.updGeometryPath().addPathWrap(pulley)

osimModel.addForce(spring)
osimModel.finalizeConnections()

osimModel.buildSystem()

si = osimModel.initializeState()