Exemplo n.º 1
0
def createScene(root):
    root.createObject('RequiredPlugin', pluginName = 'Compliant')
    root.createObject('VisualStyle', displayFlags="showBehavior" )
    
    root.dt = 0.001
    root.gravity = [0, -9.8, 0]
    
    ode = root.createObject('AssembledSolver')
    ode.stabilization = True
    
    num = root.createObject('MinresSolver')
    num.iterations = 500
    
    scene = root.createChild('scene')
    
    base = Rigid.Body('base')
    moving = Rigid.Body('moving')

    moving.inertia_forces = True

    moving.dofs.translation = [0, 2, 0]

    base_node = base.insert( scene );
    base_node.createObject('FixedConstraint', indices = '0')

    moving_node = moving.insert( scene );

    base_offset = Rigid.Frame()
    base_offset.translation = [0, 1, 0]
    
    moving_offset = Rigid.Frame()
    moving_offset.translation = [0, -1, 0]
    
    joint = Rigid.SphericalJoint()
    
    # only rotation dofs
    joint.append(base_node, base_offset)
    joint.append(moving_node, moving_offset)

    node = joint.insert(scene)
    
    node.createObject('UniformCompliance',
                      template = 'Vec6d',
                      compliance = 1e-3 )
Exemplo n.º 2
0
def createScene(root):

    # root node setup
    root.createObject('RequiredPlugin', pluginName='Compliant')
    root.createObject('VisualStyle', displayFlags="showBehavior")

    # simuation parameters
    root.dt = 1e-2
    root.gravity = [0, -9.8, 0]

    # ode solver
    ode = root.createObject('CompliantImplicitSolver')
    ode.stabilization = "pre-stabilization"

    # numerical solver
    num = root.createObject('MinresSolver')
    num.iterations = 500

    # scene node
    scene = root.createChild('scene')

    # script variables
    n = 10
    length = 2

    # objects creation
    obj = []

    for i in xrange(n):
        # rigid bodies
        body = Rigid.Body()
        body.name = 'link-' + str(i)
        body.dofs.translation = [0, length * i, 0]

        body.inertia_forces = 'true'

        obj.append(body)
        # insert the object into the scene node, saves the created
        # node in body_node
        body.node = body.insert(scene)
        body.node.getObject("dofs").showObject = True

    # joints creation
    for i in xrange(n - 1):
        # the joint
        j = Rigid.SphericalJoint()

        # joint offset definitions
        up = Rigid.Frame.Frame()
        up.translation = [0, length / 2, 0]

        down = Rigid.Frame.Frame()
        down.translation = [0, -length / 2, 0]

        # append node/offset to the joint
        j.append(obj[i].node, up)  # parent
        j.append(obj[i + 1].node, down)  # child

        j.insert(scene)

    # attach first node
    obj[0].node.createObject('FixedConstraint', indices='0')