Exemplo n.º 1
0
 def setup(self,
           useCompliant=1,
           compliance=1E-6,
           showOffset=False,
           showOffsetScale=0.1):
     # Variable
     _isLimited = False
     _compliance = 0 if useCompliant else compliance
     # Needs to be fixed and used late
     boneA_offset = self.boneA.body.addAbsoluteOffset(
         self.boneA.name + '_offset_joint_' + self.name, self.frame)
     boneB_offset = self.boneB.body.addAbsoluteOffset(
         self.boneB.name + '_offset_joint_' + self.name, self.frame)
     # joint creation between the offsets
     self.joint = StructuralAPI.GenericRigidJoint(self.name,
                                                  boneA_offset.node,
                                                  boneB_offset.node,
                                                  self.mask, _compliance)
     # add of the limits
     for l in self.limits:
         if l != 0:
             _isLimited = True
     if _isLimited:
         self.joint.addLimits(self.limits, _compliance)
     # visualization of offset: check that all frames are well placed
     boneA_offset.dofs.showObject = showOffset
     boneB_offset.dofs.showObject = showOffset
     boneA_offset.dofs.showObjectScale = showOffsetScale
     boneB_offset.dofs.showObjectScale = showOffsetScale
Exemplo n.º 2
0
def insertJoint(jointModel, rigids, param):
    """ create a StructuralAPI.GenericRigidJoint from the jointModel """

    frames = list()
    for i, offset in enumerate(jointModel.offsets):
        if not jointModel.solids[i].id in rigids:
            Sofa.msg_warning(
                "Compliant.sml", "insertJoint " + jointModel.name +
                " failed: " + jointModel.solids[i].id + " is not a rigid body")
            return None
        rigid = rigids[jointModel.solids[i].id]  # shortcut
        if rigid is None:
            Sofa.msg_warning(
                "Compliant.sml",
                "in joint {0}, solid {1} is missing, ignored".format(
                    jointModel.name, jointModel.solids[i].id))
            return
        if not offset is None:
            if offset.isAbsolute():
                frames.append(
                    rigid.addAbsoluteOffset(offset.name, offset.value))
            else:
                frames.append(rigid.addOffset(offset.name, offset.value))
            if not param is None:
                frames[-1].dofs.showObject = param.showOffset
                frames[
                    -1].dofs.showObjectScale = SofaPython.units.length_from_SI(
                        param.showOffsetScale)
        else:
            frames.append(rigid)

    if printLog:
        Sofa.msg_info("Compliant.sml", "insertJoint " + jointModel.name)

    mask = [1] * 6
    limits = []  # mask for limited dofs
    isLimited = True  # does the joint have valid limits?
    for d in jointModel.dofs:
        if isLimited:
            if d.min == None or d.max == None:
                isLimited = False  # as soon as a limit is not defined, the limits cannot work
            else:
                limits.append(d.min)
                limits.append(d.max)
        mask[d.index] = 0

    joint = StructuralAPI.GenericRigidJoint(
        jointModel.name,
        frames[0].node,
        frames[1].node,
        mask,
        compliance=SofaPython.sml.getValueByTag(param.jointComplianceByTag,
                                                jointModel.tags),
        isCompliance=SofaPython.sml.getValueByTag(param.jointIsComplianceByTag,
                                                  jointModel.tags))
    if isLimited:
        joint.addLimits(limits)
    return joint