Esempio n. 1
0
    def test_set_iterator(self):
        fs = osim.FunctionSet()
        f1 = osim.Constant()
        f1.setName("myfunc1")
        fs.adoptAndAppend(f1)
        f2 = osim.Constant()
        f2.setName("myfunc2")
        fs.adoptAndAppend(f2)
        f3 = osim.Constant()
        f3.setName("myfunc3")
        fs.adoptAndAppend(f3)

        names = ['myfunc1', 'myfunc2', 'myfunc3']
        i = 0
        for func in fs:
            assert func.getName() == names[i]
            i += 1

        # Test key-value iterator.
        j = 0
        for k, v in fs.items():
            assert k == names[j]
            assert k == v.getName()
            j += 1
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. 3
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. 4
0
    def _populate_references(self):
        # Initialize objects needed to populate the references.
        coord_functions = opensim.FunctionSet()
        marker_weights = opensim.SetMarkerWeights()

        # Load coordinate data, if available.
        if self.coordinate_file and (self.coordinate_file != ""
                                     and self.coordinate_file != "Unassigned"):
            coordinate_values = opensim.Storage(self.coordinate_file)
            # Convert to radians, if in degrees.
            if not coordinate_values.isInDegrees():
                self.model.getSimbodyEngine().convertDegreesToRadians(
                    coordinate_values)
            coord_functions = opensim.GCVSplineSet(5, coordinate_values)

        index = 0
        for i in range(0, self.ik_task_set.getSize()):
            if not self.ik_task_set.get(i).getApply():
                continue
            if opensim.IKCoordinateTask.safeDownCast(self.ik_task_set.get(i)):
                # NOTE: Opposed to C++, a variable cannot be declared in the above if statement, so do it now.
                coord_task = opensim.IKCoordinateTask.safeDownCast(
                    self.ik_task_set.get(i))
                coord_ref = opensim.CoordinateReference()
                if coord_task.getValueType(
                ) == opensim.IKCoordinateTask.FromFile:
                    if not coord_functions:
                        raise Exception(
                            "InverseKinematicsTool: value for coordinate " +
                            coord_task.getName() + " not found.")

                    index = coord_functions.getIndex(coord_task.getName(),
                                                     index)
                    if index >= 0:
                        coord_ref = opensim.CoordinateReference(
                            coord_task.getName(), coord_functions.get(index))
                elif coord_task.getValueType(
                ) == opensim.IKCoordinateTask.ManualValue:
                    reference = opensim.Constant(
                        opensim.Constant(coord_task.getValue()))
                    coord_ref = opensim.CoordinateReference(
                        coord_task.getName(), reference)
                else:  # Assume it should be held at its default value
                    value = self.model.getCoordinateSet().get(
                        coord_task.getName()).getDefaultValue()
                    reference = opensim.Constant(value)
                    coord_ref = opensim.CoordinateReference(
                        coord_task.getName(), reference)

                if not coord_ref:
                    raise Exception(
                        "InverseKinematicsTool: value for coordinate " +
                        coord_task.getName() + " not found.")
                else:
                    coord_ref.setWeight(coord_task.getWeight())

                self.coordinate_references.push_back(coord_ref)

            elif opensim.IKMarkerTask.safeDownCast(self.ik_task_set.get(i)):
                # NOTE: Opposed to C++, a variable cannot be declared in the above if statement, so do it now.
                marker_task = opensim.IKMarkerTask.safeDownCast(
                    self.ik_task_set.get(i))
                if marker_task.getApply():
                    # Only track markers that have a task and it is "applied"
                    marker_weights.cloneAndAppend(
                        opensim.MarkerWeight(marker_task.getName(),
                                             marker_task.getWeight()))

        self.markers_reference.initializeFromMarkersFile(
            self.marker_file, marker_weights)