def createScene(node):
    scene = Tools.scene(node)

    ode = node.getObject('ode')

    ode.stabilization = True
    ode.warm_start = False
    ode.propagate_lambdas = True

    # ode.debug = True

    node.gravity = '0 -1 0'

    num = node.createObject('SequentialSolver',
                            name='num',
                            iterations=200,
                            precision=0)

    resp = node.createObject('DiagonalResponse')

    manager = node.getObject('manager')
    manager.response = 'CompliantContact'

    script = node.createObject('PythonScriptController',
                               filename=__file__,
                               classname='Controller')

    style = node.getObject('style')

    style.displayFlags = 'showBehaviorModels showCollisionModels'

    proximity = node.getObject('proximity')
    proximity.contactDistance = 0.01

    # dofs
    p1 = insert_point(scene, 'p1', [-1, 1, 0])
    p2 = insert_point(scene, 'p2', [1, 1, 0])

    rigid = Rigid.Body('rigid')
    rigid.collision = path + '/examples/mesh/ground.obj'

    rigid.node = rigid.insert(scene)

    ground = Rigid.Body('ground')
    ground.node = ground.insert(scene)
    ground.node.createObject('FixedConstraint', indices='0')

    # blocked joint between ground/rigid
    joint = Rigid.Joint('joint')
    joint.absolute(Rigid.Frame(), ground.node, rigid.node)

    joint.node = joint.insert(scene)

    shared.joint = joint
    shared.body = rigid

    return node
Ejemplo n.º 2
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 )
Ejemplo n.º 3
0
def createScene(node):
    scene = Tools.scene(node)

    style = node.getObject('style')
    style.findData('displayFlags').showMappings = True

    manager = node.getObject('manager')
    manager.response = 'FrictionCompliantContact'
    manager.responseParams = 'mu=0'  # per object friction coefficient (the friction coef between 2 objects is approximated as the product of both coefs)

    ode = node.getObject('ode')
    ode.stabilization = True
    ode.debug = False

    num = node.createObject('SequentialSolver',
                            name='num',
                            iterations=100,
                            precision=1e-14)

    proximity = node.getObject('proximity')

    proximity.alarmDistance = 0.5
    proximity.contactDistance = 0.2

    # plane
    plane = Rigid.Body('plane')
    plane.visual = dir + '/../mesh/ground.obj'
    plane.collision = plane.visual
    plane.mass_from_mesh(plane.visual, 10)
    plane.mu = 0.8  # per object friction coefficient
    plane.node = plane.insert(scene)
    plane.node.createObject('FixedConstraint', indices='0')

    # box
    box = Rigid.Body('box')
    box.visual = dir + '/../mesh/cube.obj'
    box.collision = box.visual
    box.dofs.translation = [0, 3, 0]
    box.mass_from_mesh(box.visual, 50)
    box.mu = 1  # per object friction coefficient
    box.node = box.insert(scene)
Ejemplo n.º 4
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')
Ejemplo n.º 5
0
def createScene(node):
    node.createObject('RequiredPlugin', name='Compliant')
    node.createObject('CompliantAttachButtonSetting')

    node.createObject(
        'VisualStyle',
        displayFlags=
        'hideBehaviorModels hideCollisionModels hideMappings hideForceFields')
    node.findData('dt').value = 0.01

    node.findData('gravity').value = '0 -9.81 0'
    node.createObject('CompliantImplicitSolver',
                      name='odesolver',
                      stabilization="true")

    node.createObject('MinresSolver',
                      name='numsolver',
                      iterations='250',
                      precision='1e-14')

    scene = node.createChild('scene')

    rigid = []
    joint = []

    # create rigid bodies
    for p in parts:
        r = Rigid.Body()
        r.name = p[0]

        # r.collision = part_path + p[1]
        r.dofs.read(p[3])
        r.visual = mesh_path + '/' + p[15]
        r.collision = r.visual
        r.inertia_forces = True

        density = float(p[7])
        r.mass_from_mesh(r.visual, density)

        r.insert(scene)
        rigid.append(r)

    # create joints
    for i in links:
        j = i[2]
        j.compliance = 0

        p = offset[i[0]][0]
        off_p = offset[i[0]][1]

        c = offset[i[1]][0]
        off_c = offset[i[1]][1]

        j.append(rigid[p].user, off_p)
        j.append(rigid[c].user, off_c)

        joint.append(j.insert(scene))

    # fix first body
    rigid[0].node.createObject('FixedConstraint', indices='0')

    return node
Ejemplo n.º 6
0
def createScene(node):
    scene = Tools.scene(node)

    style = node.getObject('style')
    style.findData('displayFlags').showMappings = True

    manager = node.getObject('manager')
    manager.response = 'FrictionCompliantContact'

    # node.createObject('CompliantAttachButton')

    globalMu = 0.7  # per object friction coefficient (the friction coef between 2 objects is approximated as the product of both coefs)

    manager.responseParams = 'mu={0}&compliance={1}&horizontalConeProjection=1'.format(
        globalMu, 1e-8)

    ode = node.getObject('ode')
    ode.stabilization = "pre-stabilization"
    ode.debug = 2

    # (un)comment these to see anisotropy issues with sequential solver
    solver = 'ModulusSolver'
    solver = 'SequentialSolver'

    num = node.createObject(solver,
                            name='num',
                            iterations=100,
                            precision=1e-14,
                            anderson=4)
    num.printLog = True

    proximity = node.getObject('proximity')

    proximity.alarmDistance = 0.5
    proximity.contactDistance = 0.2
    proximity.useLineLine = True

    # plane
    plane = Rigid.Body('plane')
    plane.dofs.translation = [0, 5, -15]

    alpha = math.pi / 5
    mu = math.tan(alpha)

    print "plane mu:", mu,
    if mu < globalMu: print '(should stick)'
    else: print '(should slide)'

    q = Quaternion.exp([alpha, 0.0, 0.0])

    plane.dofs.rotation = q
    s = 6
    plane.scale = [s, s, s]

    plane.visual = path + '/../mesh/ground.obj'
    plane.collision = plane.visual
    plane.mass_from_mesh(plane.visual, 10)
    plane.mu = 0.5  # per object friction coefficient
    plane.node = plane.insert(scene)
    plane.node.createObject('FixedConstraint', indices='0')

    # box
    box = Rigid.Body('box')
    box.visual = path + '/../mesh/cube.obj'
    box.collision = box.visual
    box.dofs.translation = [0, 3, 0]
    box.mass_from_mesh(box.visual, 50)
    box.mu = 1  # per object friction coefficient

    box.dofs.rotation = q

    box.node = box.insert(scene)
Ejemplo n.º 7
0
def createScene(node):
    node.createObject('RequiredPlugin', pluginName='Compliant')

    node.animate = 'true'

    node.createObject(
        'VisualStyle',
        displayFlags=
        'hideBehaviorModels hideCollisionModels hideMappings hideForceFields')
    node.dt = 0.005

    node.gravity = '0 -9.81 0'

    ode = node.createObject('AssembledSolver', name='odesolver')

    ode.stabilization = 'true'
    # ode.debug = 'true'

    num = node.createObject('MinresSolver',
                            name='numsolver',
                            iterations='250',
                            precision='1e-14')

    node.createObject('PythonScriptController',
                      filename=__file__,
                      classname='Controller')

    scene = node.createChild('scene')

    inertia_forces = 'true'

    # dofs
    base = Rigid.Body('base')
    base.node = base.insert(scene)
    base.visual = 'mesh/box.obj'
    base.node.createObject('FixedConstraint', indices='0')

    link1 = Rigid.Body('link1')
    link1.dofs.translation = [0, 0, 0]
    link1.visual = 'mesh/cylinder.obj'
    link1.inertia_forces = inertia_forces
    link1.mass_from_mesh(link1.visual)
    link1.node = link1.insert(scene)

    link2 = Rigid.Body('link2')
    link2.dofs.translation = [0, 10, 0]
    link2.visual = 'mesh/cylinder.obj'
    link2.mass_from_mesh(link2.visual)
    link2.inertia_forces = inertia_forces
    link2.node = link2.insert(scene)

    # joints
    joint1 = Rigid.RevoluteJoint(2)
    joint1.append(base.node, Rigid.Frame().read('0 0 0 0 0 0 1'))
    joint1.append(link1.node, Rigid.Frame().read('0 0 0 0 0 0 1'))
    joint1.node = joint1.insert(scene)

    joint2 = Rigid.RevoluteJoint(2)
    joint2.append(link1.node, Rigid.Frame().read('0 10 0 0 0 0 1'))
    joint2.append(link2.node, Rigid.Frame().read('0 0 0 0 0 0 1'))
    joint2.node = joint2.insert(scene)

    # control
    control.joint1 = ControlledJoint(joint1.node.getObject('dofs'))

    control.joint2 = ControlledJoint(joint2.node.getObject('dofs'))

    # pid controller reference pos for joint2
    control.joint2.ref_pos = [0, 0, 0, 0, 0, math.pi / 2]

    return node
Ejemplo n.º 8
0
def createScene(node):
    # controller
    node.createObject('PythonScriptController',
                      filename=__file__,
                      classname='Controller')

    node.dt = 0.005

    # friction coefficient
    shared.mu = 0.5

    scene = Tools.scene(node)

    style = node.getObject('style')
    style.findData('displayFlags').showMappings = True

    manager = node.getObject('manager')
    manager.response = 'FrictionCompliantContact'
    manager.responseParams = 'mu=' + str(
        shared.mu) + "&horizontalConeProjection=1"

    ode = node.getObject('ode')
    ode.stabilization = "pre-stabilization"

    bench = node.createObject('Benchmark')

    num = node.createObject('SequentialSolver',
                            name='num',
                            iterations=100,
                            precision=1e-14)
    node.createObject('LDLTResponse')

    proximity = node.getObject('proximity')

    proximity.alarmDistance = 0.5
    proximity.contactDistance = 0.1

    # ground
    ground = Rigid.Body('ground')
    ground.node = ground.insert(scene)

    # plane
    plane = Rigid.Body('plane')
    plane.visual = dir + '/../mesh/ground.obj'
    plane.collision = plane.visual
    plane.mass_from_mesh(plane.visual, 10)
    plane.node = plane.insert(scene)

    ground.node.createObject('FixedConstraint', indices='0')

    # ground-plane joint
    frame = Rigid.Frame.Frame()
    frame.translation = [8, 0, 0]

    joint = Rigid.RevoluteJoint(2)
    joint.absolute(frame, ground.node, plane.node)
    joint.upper_limit = 0

    joint.node = joint.insert(scene)

    # box
    box = Rigid.Body('box')
    box.visual = dir + '/../mesh/cube.obj'
    box.collision = box.visual
    box.dofs.translation = [0, 3, 0]
    box.mass_from_mesh(box.visual, 50)
    box.node = box.insert(scene)

    shared.plane = plane.node.getObject('dofs')
    shared.box = box.node.getObject('dofs')
    shared.joint = joint.node.getObject('dofs')

    # pid
    shared.pid = Control.PID(shared.joint)
    shared.pid.pos = -math.atan(shared.mu)  # target should trigger slide
    shared.pid.basis = [0, 0, 0, 0, 0, 1]

    # shared.pid.dofs.externalForce = '-1e7'

    scale = 2e5

    shared.pid.kp = -5 * scale
    shared.pid.kd = -100 * scale
    shared.pid.ki = -1e-1 * scale
Ejemplo n.º 9
0
def createScene(node):

    # controller
    node.createObject('PythonScriptController', 
                      filename = __file__,
                      classname = 'Controller' )

    # time step
    node.dt = 0.005

    # scene node
    scene = Tools.scene( node )

    # display flags
    style = node.getObject('style')
    style.findData('displayFlags').showMappings = True

    # collision detection
    proximity = node.getObject('proximity')
    proximity.alarmDistance = 0.5
    proximity.contactDistance = 0.1

    # contat manager
    manager = node.getObject('manager')
    manager.response = 'CompliantContact'
    manager.responseParams = 'compliance=0'
    
    # integrator
    ode = node.getObject('ode',)
    ode.stabilization = True
    ode.stabilization_damping = 0

    # main solver
    num = node.createObject('BenchmarkSolver', name = 'num')

    response = node.createObject('LDLTResponse', name = 'response')
    
    iterations = 300
    precision = 1e-8

    
    # we need compliantdev for qpsolver
    node.createObject('RequiredPlugin', 
                      pluginName = 'CompliantDev')

    # benchmarks
    shared.pgs = node.createObject('Benchmark', name = 'bench-pgs')
    shared.qp = node.createObject('Benchmark', name = 'bench-qp')

    # solvers
    pgs = node.createObject('SequentialSolver',
                            name = 'pgs',
                            iterations = iterations,
                            precision = precision,
                            bench = '@./bench-pgs')

    qp = node.createObject('QPSolver',
                           name = 'qp',
                           iterations = iterations,
                           precision = precision,
                           bench = '@./bench-qp',
                           schur = True)


    # plane
    plane = Rigid.Body('plane')
    plane.visual = dir + '/mesh/ground.obj'
    plane.collision = plane.visual
    plane.mass_from_mesh( plane.visual, 10 )
    plane.node = plane.insert( scene )
    
    plane.node.createObject('FixedConstraint', 
                             indices = '0')

    # boxes
    n_boxes = 10

    for i in xrange(n_boxes):
        box = Rigid.Body('box-{0}'.format(i))
        box.visual = dir + '/mesh/cube.obj'
        box.collision = box.visual
        box.dofs.translation = [0, 2.5 * (i + 1), 0]
        box.mass_from_mesh( box.visual, 50 )
        box.node = box.insert( scene )