io.add_primitive_shape('Sphere', 'Sphere', (2,),
                           insideMargin=0.2, outsideMargin=0.0)

    # Definition of the ground shape
    io.add_primitive_shape('Ground', 'Box', (10, 10, 0.1),
                           insideMargin=0.05, outsideMargin=0.0)

    # Definition of a non smooth law. As no group ids are specified it
    # is between contactors of group id 0.
    io.add_Newton_impact_friction_nsl('contact', mu=0.1, e=0.0)

    # The sphere object made with an unique Contactor : the sphere shape.
    # As a mass is given, it is a dynamic system involved in contact
    # detection and in the simulation.  With no group id specified the
    # Contactor belongs to group 0
    sphere=io.add_object('sphere', [Contactor('Sphere')],
                  translation=[0, 0, 2.5],
                  velocity=[0, 0, 0, 0, 0, 0],
                  mass=1)
    
    io.add_object('sphere2', [Contactor('Sphere')],
                  translation=[-2.5, 0., 5.5],
                  velocity=[0, 0, 0, 0, 0, 0],
                  mass=1)
    
    # io.add_object('sphere3', [Contactor('Sphere')],
    #               translation=[1.5, 0., 7.5],
    #               velocity=[0, 0, 0, 0, 0, 0],
    #               time_of_birth=0.02,
    #               time_of_death=1.5,
    #               mass=1)
    #
    io.addOccShape('Mass1', sphere1)
    io.addOccShape('Mass2', sphere2)
    io.addOccShape('Arm1', cylinder1)
    io.addOccShape('Arm2', cylinder2)
    io.addOccShape('Ground', ground)
    io.addOccShape('Brick', sphere1)

    # Definition of a non smooth law. As no group ids are specified it
    # is between contactors of group id 0.
    io.addNewtonImpactFrictionNSL('contact', mu=0.1)

    # first branch + first mass the center of gravity is at the center of the
    # Mass1
    io.addObject('arm1', [
        Contactor(shape_data='Mass1', contact_type='Face', contact_index=0),
        Contactor('Arm1',
                  contact_type='Face',
                  contact_index=0,
                  relative_translation=[0, r1 + l1, 0],
                  relative_orientation=[(1, 0, 0), pi / 2])
    ],
                 translation=[0, 0, r2 + gap + r2 + l2 + r1 + hgap],
                 orientation=((1, 0, 0), pi / 2),
                 mass=m1)

    # second branch + second mass
    io.addObject('arm2', [
        Contactor(shape_data='Mass2',
                  instance_name='Mass2Contact',
                  contact_type='Face',
def create_chute(io,
                 box_height=box_height,
                 box_length=box_length,
                 box_width=box_width,
                 plane_thickness=plane_thickness,
                 scale=1.0,
                 trans=[0, 0, 0]):

    box_height *= scale
    box_length *= scale
    box_width *= scale
    plane_thickness *= scale

    ######### left_up
    v1 = numpy.array([0, 0, box_height])
    v2 = numpy.array([
        4.370 * scale - 4.370 * 1.200 * scale * scale / box_height, 0.0,
        1.200 * scale
    ])
    v3 = numpy.array([box_length, 0, 1.200 * scale])
    left_up_normal = normal_plane(v1, v2, v3)
    v1_extruded = v1 + numpy.dot(plane_thickness, left_up_normal)
    v2_extruded = v2 + numpy.dot(plane_thickness, left_up_normal)
    v3_extruded = v3 + numpy.dot(plane_thickness, left_up_normal)

    left_up_vertices = numpy.array(
        [v1, v2, v3, v1_extruded, v2_extruded, v3_extruded])
    # print left_up_vertices

    io.addConvexShape('Left_up',
                      left_up_vertices,
                      insideMargin=0.1 * plane_thickness)
    io.addObject('left_up', [Contactor('Left_up', collision_group=1)],
                 translation=trans)

    ######### left_middle
    v4 = numpy.array([4.370 * scale, 1.280 * scale, 0.0])
    v5 = numpy.array([(6.900 - 1.770) * scale, 1.280 * scale, 0.0])

    left_middle_normal = normal_plane(v2, v4, v3)
    # print('left_middle_normal=', left_middle_normal)

    v4_extruded = v4 + numpy.dot(plane_thickness, left_middle_normal)
    v5_extruded = v5 + numpy.dot(plane_thickness, left_middle_normal)

    left_middle_vertices = numpy.array(
        [v2, v3, v4, v5, v2_extruded, v3_extruded, v4_extruded, v5_extruded])
    # print left_middle_vertices

    io.addConvexShape('Left_middle',
                      left_middle_vertices,
                      insideMargin=0.1 * plane_thickness)
    io.addObject('left_middle', [Contactor('Left_middle', collision_group=1)],
                 translation=trans)

    ######### left_down
    v6 = numpy.array([4.370 * scale, box_width, -.6 * scale])
    v7 = numpy.array([(6.900 - 1.770) * scale, box_width, -.6 * scale])

    left_down_normal = normal_plane(v4, v6, v5)
    # print('left_down_normal=', left_down_normal)

    v6_extruded = v6 - [plane_thickness, 0.0, 0.] + numpy.dot(
        plane_thickness, left_down_normal)
    v7_extruded = v7 + [plane_thickness, 0.0, 0.] + numpy.dot(
        plane_thickness, left_down_normal)

    left_down_vertices = numpy.array([
        v4 - [plane_thickness, 0.0, 0.], v5 + [plane_thickness, 0.0, 0.],
        v6 - [plane_thickness, 0.0, 0.], v7 + [plane_thickness, 0.0, 0.],
        v4_extruded - [plane_thickness, 0.0, 0.],
        v5_extruded + [plane_thickness, 0.0, 0.], v6_extruded, v7_extruded
    ])
    # print left_down_vertices

    io.addConvexShape('Left_down',
                      left_down_vertices,
                      insideMargin=0.1 * plane_thickness)
    io.addObject('left_udown', [Contactor('Left_down', collision_group=1)],
                 translation=trans)

    ######### right_up
    v8 = numpy.array([0, box_width, box_height])
    v9 = numpy.array([box_length, box_width, 1.200 * scale])

    v10 = numpy.array([(6.900 - 1.770) * scale, box_width, 0.0])
    v11 = numpy.array([4.370 * scale, box_width, 0.0])

    right_up_normal = normal_plane(v8, v9, v10)
    # print('right_up_normal=', right_up_normal)

    v8_extruded = v8 + numpy.dot(plane_thickness, right_up_normal)
    v9_extruded = v9 + numpy.dot(plane_thickness, right_up_normal)
    v10_extruded = v10 + numpy.dot(plane_thickness, right_up_normal)
    v11_extruded = v11 + numpy.dot(plane_thickness, right_up_normal)

    right_up_vertices = numpy.array([
        v8, v9, v10, v11, v8_extruded, v9_extruded, v10_extruded, v11_extruded
    ])
    # print right_up_vertices

    io.addConvexShape('Right_up',
                      right_up_vertices,
                      insideMargin=0.1 * plane_thickness)
    io.addObject('right_up', [Contactor('Right_up', collision_group=1)],
                 translation=trans)

    ######### rear_up
    rear_up_normal = normal_plane(v1, v8, v4)
    # print('rear_up_normal=', rear_up_normal)

    v1_extruded = v1 + numpy.dot(plane_thickness, rear_up_normal)
    v2_extruded = v2 + numpy.dot(plane_thickness, rear_up_normal)
    v8_extruded = v8 + numpy.dot(plane_thickness, rear_up_normal)
    v4_extruded = v4 + numpy.dot(plane_thickness, rear_up_normal)
    v11_extruded = v11 + numpy.dot(plane_thickness, rear_up_normal)

    rear_up_vertices = numpy.array([
        v1 - [0.0, plane_thickness, 0.0], v2 - [0.0, plane_thickness, 0.0],
        v8 + [0.0, plane_thickness, 0.0], v4 - [0.0, plane_thickness, 0.0],
        v11 + [0.0, plane_thickness, 0.0],
        v1_extruded - [0.0, plane_thickness, 0.0],
        v2_extruded - [0.0, plane_thickness, 0.0],
        v8_extruded + [0.0, plane_thickness, 0.0],
        v4_extruded - [0.0, plane_thickness, 0.0],
        v11_extruded + [0.0, plane_thickness, 0.0]
    ])
    # print rear_up_vertices

    io.addConvexShape('Rear_up',
                      rear_up_vertices,
                      insideMargin=0.1 * plane_thickness)
    io.addObject('rear_up', [Contactor('Rear_up', collision_group=2)],
                 translation=trans,
                 mass=1.0)

    frequency = 50
    amplitude = 3.3e-3 * scale
    io.addBoundaryCondition(
        'vibration',
        'rear_up',
        indices=[0, 1, 2, 3, 4, 5],
        bc_class='HarmonicBC',
        a=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
        b=[0.0, 0.0, amplitude * frequency * 2.0 * math.pi, 0.0, 0.0, 0.0],
        omega=[0.0, 0.0, frequency * 2.0 * math.pi, 0.0, 0.0, 0.0],
        phi=[0.0, 0.0, math.pi / 2.0, 0.0, 0.0, 0.0])

    ######### rear_down
    #v12 = numpy.array([(6.900-1.770)*scale, box_width,-.6*scale])
    #v13 = numpy.array([4.370*scale, box_width, -.6*scale])

    rear_down_normal = normal_plane(v4, v11, v6)
    # print('rear_down_normal=', rear_down_normal)

    v4_extruded = v4 + numpy.dot(plane_thickness, rear_down_normal)
    v11_extruded = v11 + numpy.dot(plane_thickness, rear_down_normal)
    v6_extruded = v6 + numpy.dot(plane_thickness, rear_down_normal)

    rear_down_vertices = numpy.array(
        [v4, v11, v6, v4_extruded, v11_extruded, v6_extruded])
    # print rear_down_vertices

    io.addConvexShape('Rear_down',
                      rear_down_vertices,
                      insideMargin=0.1 * plane_thickness)
    io.addObject('rear_down', [Contactor('Rear_down', collision_group=1)],
                 translation=trans)

    ######### front_up
    front_up_normal = normal_plane(v3, v5, v9)
    # print('front_up_normal=', front_up_normal)

    v3_extruded = v3 + numpy.dot(plane_thickness, front_up_normal)
    v5_extruded = v5 + numpy.dot(plane_thickness, front_up_normal)
    v9_extruded = v9 + numpy.dot(plane_thickness, front_up_normal)
    v10_extruded = v10 + numpy.dot(plane_thickness, front_up_normal)

    front_up_vertices = numpy.array([
        v3 - [0.0, plane_thickness, 0.0], v5 - [0.0, plane_thickness, 0.0],
        v9 + [0.0, plane_thickness, 0.0], v10 + [0.0, plane_thickness, 0.0],
        v3_extruded - [0.0, plane_thickness, 0.0],
        v5_extruded - [0.0, plane_thickness, 0.0],
        v9_extruded + [0.0, plane_thickness, 0.0],
        v10_extruded + [0.0, plane_thickness, 0.0]
    ])
    # print front_up_vertices

    io.addConvexShape('Front_up',
                      front_up_vertices,
                      insideMargin=0.1 * plane_thickness)
    io.addObject('front_up', [Contactor('Front_up', collision_group=1)],
                 translation=trans)

    ######### front_down
    front_down_normal = normal_plane(v5, v7, v10)
    # print('front_down_normal=', front_down_normal)

    v7_extruded = v7 + numpy.dot(plane_thickness, front_down_normal)
    v5_extruded = v5 + numpy.dot(plane_thickness, front_down_normal)
    v10_extruded = v10 + numpy.dot(plane_thickness, front_down_normal)

    front_down_vertices = numpy.array(
        [v5, v7, v10, v5_extruded, v7_extruded, v10_extruded])
    # print front_down_vertices

    io.addConvexShape('Front_down',
                      front_down_vertices,
                      insideMargin=0.1 * plane_thickness)
    io.addObject('front_down', [Contactor('Front_down', collision_group=1)],
                 translation=trans)
Exemple #4
0
    # is between contactors of group id 0.
    io.add_Newton_impact_friction_nsl('contact', mu=0.1, e=0.9)

    # The sphere object made with an unique Contactor : the sphere shape.
    # As a mass is given, it is a dynamic system involved in contact
    # detection and in the simulation.  With no group id specified the
    # Contactor belongs to group 0
    mass_test = 1.0
    inertia_test = np.eye(3)

    inertia_test[0, 0] = 0.25 * mass_test * R * R + 1 / 3.0 * mass_test * L * L
    inertia_test[1, 1] = 0.5 * mass_test * R * R
    inertia_test[2, 2] = 0.25 * mass_test * R * R + 1 / 3.0 * mass_test * L * L
    print(inertia_test)
    orientation_test = [0.14, 0.7, 0.7, 0]
    io.add_object('cap', [Contactor('Cap')],
                  translation=[0, 0, 4],
                  orientation=orientation_test,
                  velocity=[0, 0, 0, 0, 0, 0],
                  mass=1,
                  inertia=inertia_test)

    # the ground object made with the ground shape. As the mass is
    # not given, it is a static object only involved in contact
    # detection.
    io.add_object('ground', [Contactor('Ground')], translation=[0, 0, -0.1])

# Run the simulation from the inputs previously defined and add
# results to the hdf5 file. The visualisation of the output may be done
# with the vview command.
options = sk.solver_options_create(sn.SICONOS_FRICTION_3D_NSGS)
Exemple #5
0
# the same axis.

# Note: This example is to demonstrate external measurement of joint
# positions and application of forces to dynamical systems attached to
# joints.  In practice it is better to use internal forces (fInt,
# mInt) to model joint spring-dampers, see folder
# JointsTestsWithInternalForces, and extra Relations with associated
# Non-Smooth Laws to model non-linearities such as joint stops and
# friction, see JointsTestsWithContactDetection.

# Creation of the hdf5 file for input/output
with MechanicsHdf5Runner() as io:

    # Definition of two bars connected by a prismatic joint
    io.add_primitive_shape('Bar', 'Box', (1, 0.1, 0.1))
    io.add_object('bar1', [Contactor('Bar')], [0, 0, 2],
                  orientation=[(0, 0, 1), np.pi / 2],
                  mass=1.0,
                  velocity=[0, 0, 0, 0, 0, 1])
    io.add_object('bar2', [
        Contactor('Bar', relative_translation=[0, 0.1, 0]),
        Contactor('Bar', relative_translation=[0, -0.1, 0])
    ], [0, 0, 2],
                  orientation=[(0, 0, 1), np.pi / 2],
                  mass=1.0)
    io.add_joint('joint1',
                 'bar1',
                 'bar2', [[0, 0, 0]], [[0, 1, 0]],
                 'PivotJointR',
                 absolute=False)
                        outsideMargin=diameter * margin_ratio)

    test = True
    if test == True:
        n_disks = 10
    else:
        n_disks = 250

    delta_tob = math.sqrt(2.0 * diameter / 9.81)
    print('delta_tob', delta_tob)
    T = (n_disks * delta_tob) * 1.1
    print('T', T)
    for s in range(n_disks):
        tob = s * delta_tob
        trans = [0.5 * diameter * random.random(), 12 * diameter]
        io.add_object('disk_' + str(s), [Contactor('Disk')],
                      translation=trans,
                      velocity=[0, 0, 0],
                      mass=mass,
                      inertia=inertia,
                      time_of_birth=tob)

    # the ground object made with the ground shape. As the mass is
    # not given, it is a static object only involved in contact
    # detection.
    io.add_object('ground', [Contactor('ConvexHull')],
                  translation=[-box_x_scale / 2.0, -box_y_scale / 2.0])

    # Definition of a non smooth law. As no group ids are specified it
    # is between contactors of group id 0.
    #io.add_Newton_impact_friction_nsl('contact', mu=0.3)
Exemple #7
0
# the same axis.

# Note: This example is to demonstrate external measurement of joint
# positions and application of forces to dynamical systems attached to
# joints.  In practice it is better to use internal forces (fInt,
# mInt) to model joint spring-dampers, see folder
# JointsTestsWithInternalForces, and extra Relations with associated
# Non-Smooth Laws to model non-linearities such as joint stops and
# friction, see JointsTestsWithContactDetection.

# Creation of the hdf5 file for input/output
with MechanicsHdf5Runner() as io:

    # Definition of two bars connected by a prismatic joint
    io.add_primitive_shape('Bar', 'Box', (1, 0.1, 0.1))
    io.add_object('bar1', [Contactor('Bar')], [0.05,0,2],
                 orientation=[(0,0,1),np.pi/2], mass=1.0, velocity=[0,0,0,0,0,1])
    io.add_object('bar2', [Contactor('Bar')], [-0.05,0,2],
                 orientation=[(0,0,1),np.pi/2], mass=1.0)
    io.add_joint('joint1', 'bar1', 'bar2', None, [[0,1,0]], 'PrismaticJointR', True)

    # Definition of the ground
    io.add_primitive_shape('Ground', 'Box', (5, 5, 0.1))
    io.add_object('ground', [Contactor('Ground')], [0,0,-0.05])

class Ctrl(object):
    def initialize(self, io):
        self.count = 0
        self.topo = io._nsds.topology()
        self.ds1 = Kernel.cast_NewtonEulerDS(self.topo.getDynamicalSystem('bar1'))
        self.ds2 = Kernel.cast_NewtonEulerDS(self.topo.getDynamicalSystem('bar2'))
Exemple #8
0
  left_up_vertices=numpy.array([v1,v2,v3,v1_extruded,v2_extruded,v3_extruded])
  print('left_up_vertices',left_up_vertices)

  v1 = numpy.array([0, 0 , box_height])
  v2 = numpy.array([4.370-4.370*1.200/box_height,0.0, 1.200])
  v3 = numpy.array([ box_length, 0,1.200])
  v1_extruded = v1 + numpy.dot(plan_thickness,left_up_normal)
  v2_extruded = v2 + numpy.dot(plan_thickness,left_up_normal)
  v3_extruded = v3 + numpy.dot(plan_thickness,left_up_normal)

  left_up_vertices=numpy.array([v1,v2,v3,v1_extruded,v2_extruded,v3_extruded])
  print('left_up_vertices', left_up_vertices)

  io.add_convex_shape('Left_up',left_up_vertices )
  io.add_object('left_up', [Contactor('Left_up')],
               translation=[0, 0, 0])


  ######### left_middle
  id_plan=id_plan+1
  body_collection['plan_id']["left_middle"]=id_plan

  v4 = numpy.array([4.370,1.280, 0.0])
  v5 = numpy.array([ 6.900-1.770, 1.280,0.0])

  left_middle_normal = normal_plane(v2,v4,v3)
  print('left_middle_normal=', left_middle_normal)

  v4_extruded = v4 + numpy.dot(plan_thickness,left_middle_normal)
  v5_extruded = v5 + numpy.dot(plan_thickness,left_middle_normal)
Exemple #9
0
      (bowl_com.Coord(1), bowl_com.Coord(2), bowl_com.Coord(3)))
print('bowl moment of inertia:', (bowl_I1, bowl_I2, bowl_I3))

# Creation of the hdf5 file for input/output
with MechanicsHdf5Runner() as io:

    io.add_occ_shape('Contact', bowl)

    io.add_occ_shape('Ground', ground)

    io.add_occ_shape('Ball', ball)

    io.add_object('bowl', [
        Contactor(
            'Contact',
            contact_type='Face',
            contact_index=0,
        ),
        Contactor(
            'Contact',
            contact_type='Face',
            contact_index=3,
        ),
        Contactor(
            'Contact',
            contact_type='Edge',
            contact_index=0,
        )
    ],
                  mass=bowl_mass,
                  orientation=([1, 0, 0], -pi / 2),
    io.add_Newton_impact_friction_nsl('contact2',
                                      mu=0.7,
                                      collision_group1=1,
                                      collision_group2=1)

    # Definition of a non smooth law between groups 0 and 0
    io.add_Newton_impact_friction_nsl('contact3',
                                      mu=0.1,
                                      collision_group1=0,
                                      collision_group2=0)

    # A 'two boxes object made with two Contactors.
    # As a mass is given, it is a dynamic system involved in contact
    # detection and in the simulation.
    io.add_object('twoboxes', [
        Contactor('BigBox', collision_group=0, relative_translation=[0, 0, 0]),
        Contactor('LongBox', collision_group=1, relative_translation=[0, 0, 0])
    ],
                  translation=[0, 0, 3],
                  velocity=[10, 0, 0, 1, 1, 1],
                  mass=1)

    # the ground object made with the ground shape. As the mass is
    # not given, it is a static object only involved for contact
    # detection.
    io.add_object('ground', [Contactor('Ground', collision_group=1)],
                  translation=[0, 0, 0])

# Run the simulation from the inputs previously defined and add
# results to the hdf5 file. The visualisation of the output may be done
# with the vview command.
Exemple #11
0
            #print(len(vertices))
            v.append(vertices[vertices_array[vb]]['coord'])
        #print('v',v)
        name = 'brick%03d' % k
        cname= 'brick_shp%03d' % k
        one_brick(io, name, cname  , v, 1.0, density=2300,
                  trans=[0.0,0.0,0.0],
                  velo=[0.0,0.0,0.0, 0.0, 0.0, 0.0],tob=0.0)
        k=k+1
        # if (k > 20):
        #     break
        #input()
    
    # Definition of the ground
    io.add_primitive_shape('Ground', 'Box', (10, 1, 0.1))
    io.add_object('ground', [Contactor('Ground')], [2.5, 0, -0.5])

    # # Enable to smash the wall
    # io.add_primitive_shape('Ball', 'Sphere', [1,])
    # io.add_object('WreckingBall', [Contactor('Ball')],
    #              translation=[25,0,3], velocity=[-30,0,2,0,0,0],
    #              mass=10)

    # Definition of a non smooth law. As no group ids are specified it
    # is between contactors of group id 0.
    io.add_Newton_impact_friction_nsl('contact', mu=0.6, e=0.0)

T = 3.0
#T = 3e-2
h_step = 5e-3
Exemple #12
0
    # Alternative to the previous convex shape definition.
    io.add_primitive_shape('CubePrim', 'Box', (2, 2, 2))

    # Definition of the ground shape
    io.add_primitive_shape('Ground', 'Box', (100, 100, .5))

    # Definition of a non smooth law. As no group ids are specified it
    # is between contactors of group id 0.
    io.add_Newton_impact_friction_nsl('contact', mu=0.3)

    # The cube object made with an unique Contactor : the cube shape.
    # As a mass is given, it is a dynamic system involved in contact
    # detection and in the simulation.  With no group id specified the
    # Contactor belongs to group 0
    io.add_object('cube1', [Contactor('CubeCS')],
                  translation=[0, 0, 2],
                  velocity=[10, 0, 0, 1, 1, 1],
                  mass=1)

    io.add_object('cube2', [Contactor('CubePrim')],
                  translation=[0, 3, 2],
                  velocity=[10, 0, 0, 1, 1, 1],
                  mass=1)

    # the ground object made with the ground shape. As the mass is
    # not given, it is a static object only involved in contact
    # detection.
    io.add_object('ground', [Contactor('Ground')], translation=[0, 0, 0])

# Run the simulation from the inputs previously defined and add
    # Definition of the front shape
    #io.add_primitive_shape('Front', 'Box', (100, 0.5, 50.))

    # Definition of a non smooth law. As no group ids are specified it
    # is between contactors of group id 0.
    io.add_Newton_impact_friction_nsl('contact', mu=0.3)

    # The cube object made with an unique Contactor : the cube shape.
    # As a mass is given, it is a dynamic system involved in contact
    # detection and in the simulation.  With no group id specified the
    # Contactor belongs to group 0
    for i in range(n_row):
        for j in range(n_col):
            for n in range(n_cube):
                io.add_object('cubeCS'+str(n)+'_'+str(i)+'_'+str(j), [Contactor('CubeCS'+str(n)+'_'+str(i)+'_'+str(j))],
                             translation=[3.0*i, 3.0*j, 2.05*(n+1)],
                             velocity=[10*(1.0+2.0*(random.random()-1.0)/2.0), 10*(1.0+2.0*(random.random()-1.0)/2.0), 0, 1, 1, 1],
                             mass=1)

    # io.add_object('cube2', [Contactor('CubePrim')], translation=[0, 3, 2],
    #              velocity=[10, 0, 0, 1, 1, 1],
    #              mass=1)

    # the ground object made with the ground shape. As the mass is
    # not given, it is a static object only involved in contact
    # detection.
    # io.add_object('ground', [Contactor('Ground')],
    #              translation=[50, 50, 0])
    
    io.add_object('movingground', [Contactor('MovingGround')],
Exemple #14
0
#!/usr/bin/env python

from siconos.mechanics.collision.tools import Contactor
from siconos.io.mechanics_run import MechanicsHdf5Runner
import siconos.numerics as Numerics
import siconos.kernel as Kernel
from siconos.mechanics.collision.bullet import SiconosBulletOptions
import numpy as np

with MechanicsHdf5Runner() as io:
    io.add_primitive_shape('BigBox', 'Box', (1, 1, 1))
    io.add_primitive_shape('SmallBox', 'Box', (0.3, 0.3, 0.3))
    io.add_Newton_impact_friction_nsl('contact', e=0.0, mu=0.0)

    io.add_object('heavy1', [Contactor('SmallBox')],
                  translation=[0, 0, 4],
                  mass=1.0,
                  velocity=[0, 0, 15, 0, 0, 0])
    io.add_object('heavy2', [Contactor('SmallBox')],
                  translation=[0, 0, -4],
                  mass=1.0,
                  velocity=[0, 0, 15, 0, 0, 0])

    io.add_object('big', [Contactor('BigBox')],
                  translation=[0, 0, 0],
                  mass=0.1,
                  velocity=[0, 0, 0, 0, 0, 0])

    # We create a prismatic joint with friction on its axis.  In fact
    # as there is no "normal force" in a 1-D friction, it is expressed
    # as a lower- and upper-bound of permissible velocity by means of
    io.add_primitive_shape('Mass1', 'Sphere', (r1,))
    io.add_primitive_shape('Mass2', 'Sphere', (r2,))

    # Definition of the ground shape
    io.add_primitive_shape('Ground', 'Box', (100, 100, .5))

    # the brick shape
    io.add_primitive_shape('Brick', 'Box', (bx, by, bz))

    # Definition of a non smooth law. As no group ids are specified it
    # is between contactors of group id 0.
    io.add_Newton_impact_friction_nsl('contact', mu=0.1)

    # first branch + first mass the center of gravity is at the center of the
    # Mass1
    io.add_object('arm1', [Contactor('Mass1'),
                           Contactor('Arm1',
                                     relative_translation=[0, r1+l1/2., 0])],
                  translation=[0, 0, r2 + gap + r2 + l2 + r1 + hgap],
                  orientation=((1, 0, 0), pi/2),
                  mass=m1)

    # second branch + second mass
    io.add_object('arm2', [Contactor('Mass2'),
                           Contactor('Arm2',
                                    relative_translation=[0, r2+l2/2., 0])],
                  translation=[0, 0, r2 + gap],
                  orientation=((1, 0, 0), pi/2),
                  velocity=[0, 20, 0, 0, 0, 0],
                  mass=m2)
    # Definition of a cube as a primitive shape
    io.add_primitive_shape('CubeP', 'Box', (0.002, 0.002, 0.002))

    # Definition of the ground shape
    io.add_primitive_shape('Ground', 'Box', (0.1, 0.1, .01))

    # Definition of a non smooth law. As no group ids are specified it
    # is between contactors of group id 0.
    io.add_Newton_impact_friction_nsl('contact', mu=0.1)

    # The cube object made with an unique Contactor : the cube shape.
    # As a mass is given, it is a dynamic system involved in contact
    # detection and in the simulation.  With no group id specified the
    # Contactor belongs to group 0
    io.add_object('cubeCH', [Contactor('CubeCH')],
                  translation=[0, 0.003, 0.005],
                  velocity=[0.1, 0, 0, 1, 1, 1],
                  mass=0.1)

    # The primitive cube geometry object
    io.add_object('cubeP', [Contactor('CubeP')],
                  translation=[0, -0.003, 0.005],
                  velocity=[0.1, 0, 0, 1, 1, 1],
                  mass=0.1)

    # the ground object made with the ground shape. As the mass is
    # not given, it is a static object only involved in contact
    # detection.
    io.add_object('ground', [Contactor('Ground')], translation=[0, 0, -0.005])
Exemple #17
0
    io.add_primitive_shape('Mass2', 'Sphere', (r2, ))

    # Definition of the ground shape
    io.add_primitive_shape('Ground', 'Box', (100, 100, .5))

    # the brick shape
    io.add_primitive_shape('Brick', 'Box', (bx, by, bz))

    # Definition of a non smooth law. As no group ids are specified it
    # is between contactors of group id 0.
    io.add_Newton_impact_friction_nsl('contact', mu=0.1)

    # first branch + first mass the center of gravity is at the center of the
    # Mass1
    io.add_object('arm1', [
        Contactor('Mass1'),
        Contactor('Arm1', relative_translation=[0, r1 + l1 / 2., 0])
    ],
                  translation=[0, 0, r2 + gap + r2 + l2 + r1 + hgap],
                  orientation=((1, 0, 0), pi / 2),
                  mass=m1)

    # second branch + second mass
    io.add_object('arm2', [
        Contactor('Mass2'),
        Contactor('Arm2', relative_translation=[0, r2 + l2 / 2., 0])
    ],
                  translation=[0, 0, r2 + gap],
                  orientation=((1, 0, 0), pi / 2),
                  velocity=[0, 20, 0, 0, 0, 0],
                  mass=m2)
with MechanicsHdf5Runner() as io:

    # Definition of a sphere
    io.add_primitive_shape('Disk',
                           'Disk', (disk_radius, ),
                           insideMargin=0.0,
                           outsideMargin=0.0)

    # The sphere object made with an unique Contactor : the sphere shape.
    # As a mass is given, it is a dynamic system involved in contact
    # detection and in the simulation.  With no group id specified the
    # Contactor belongs to group 0

    mass = density * disk_radius**2 * math.pi
    inertia = 1 / 2. * mass * disk_radius**2
    io.add_object('disk', [Contactor('Disk')],
                  translation=[0, 5.],
                  velocity=[0, 0, 0.5],
                  mass=mass,
                  inertia=inertia)

    # Definition of a box
    io.add_primitive_shape('Box',
                           'Box2d', (box_height, box_width),
                           insideMargin=0.0,
                           outsideMargin=0.0)

    mass = density * box_height * box_width
    inertia = 1 / 12. * mass * (box_height**2 + box_width**2)
    io.add_object('box', [Contactor('Box')],
                  translation=[0, 7.],
#!/usr/bin/env python
from siconos.mechanics.collision.tools import Contactor
from siconos.io.mechanics_run import MechanicsHdf5Runner
import siconos.numerics as sn
import siconos.kernel as sk

with MechanicsHdf5Runner() as io:
    io.add_primitive_shape('Cube', 'Box', (1, 1, 1))
    io.add_primitive_shape('Ground', 'Box', (10, 10, .5))
    io.add_Newton_impact_friction_nsl('contact', e=0.0, mu=0.2)
    io.add_object('ground', [Contactor('Ground')], translation=[0, 0, -0.25])

    io.add_object('cube1', [Contactor('Cube')],
                  translation=[-1, 0, 0.5],
                  mass=0.1)
    io.add_object('cube2', [Contactor('Cube')],
                  translation=[1, 0, 0.5],
                  mass=0.1,
                  velocity=[5, 0, 5, 0, 0, 0])

    io.add_joint('joint1', 'cube1', 'cube2', None, [[0, 0, 1]],
                 'PrismaticJointR')

test = True
if test:
    T = 0.1
else:
    T = 3.

options = sk.solver_options_create(sn.SICONOS_GENERIC_MECHANICAL_NSGS)
options.iparam[sn.SICONOS_IPARAM_MAX_ITER] = 10000
Exemple #20
0
from siconos.io.mechanics_run import MechanicsHdf5Runner
import siconos.kernel as Kernel

# A demonstration of how to couple the two free axes of a
# CylindricalJointR in order to construct a screw relation. (Coupled
# rotational and translational motion.)

# Creation of the hdf5 file for input/output
with MechanicsHdf5Runner() as io:

    # Bouncy contact with the ground
    io.add_Newton_impact_friction_nsl('contact', mu=0.3, e=0.6)

    # Definition of a bar
    io.add_primitive_shape('Bar', 'Box', (0.2, 0.2, 1))
    io.add_object('bar', [Contactor('Bar')], [0,0,1], mass=1)

    # Definition of the ground
    io.add_primitive_shape('Ground', 'Box', (2, 3, 0.1))
    io.add_object('ground', [Contactor('Ground')], [0,0,-0.05])

    # Add a cylindrical joint with a coupling between its two degrees
    # of freedom with a ratio of 5.0 (rotation of 5 radians for every
    # translation of 1.0 units)
    io.add_joint('joint1', 'bar', None, [[0,0,0]], [[0,0,1]], 'CylindricalJointR',
                coupled=[(0,1,5.0)], absolute=True)

# Load and run the simulation
with MechanicsHdf5Runner(mode='r+') as io:
    io.run(t0=0,
           T=3,
Exemple #21
0
    io.add_primitive_shape('Sphere', 'Sphere', (2,),
                           insideMargin=0.2, outsideMargin=0.0)

    # Definition of the ground shape
    io.add_primitive_shape('Ground', 'Box', (10, 10, 0.1),
                           insideMargin=0.05, outsideMargin=0.0)

    # Definition of a non smooth law. As no group ids are specified it
    # is between contactors of group id 0.
    io.add_Newton_impact_friction_nsl('contact', mu=0.1, e=0.9)

    # The sphere object made with an unique Contactor : the sphere shape.
    # As a mass is given, it is a dynamic system involved in contact
    # detection and in the simulation.  With no group id specified the
    # Contactor belongs to group 0
    io.add_object('sphere', [Contactor('Sphere')],
                  translation=[0, 0, 4],
                  velocity=[0, 0, 0, 0, 0, 0],
                  mass=1)

    # the ground object made with the ground shape. As the mass is
    # not given, it is a static object only involved in contact
    # detection.
    io.add_object('ground', [Contactor('Ground')],
                  translation=[0, 0, -0.1])

# Run the simulation from the inputs previously defined and add
# results to the hdf5 file. The visualisation of the output may be done
# with the vview command.

from siconos.mechanics.collision.bullet import SiconosBulletOptions
Exemple #22
0
    io.add_object('part2', [Volume(shape_name='body2',
                                   instance_name='Body2',
                                   relative_translation=[-0.5 * l2, 0., 0.])],
                  translation=[l1 + 0.5*l2, 0., 0.],
                  orientation=[0., 0., 1., 0.],
                  velocity=[0., 0., -0.5 * w10 * l1, 0., w20, 0.],
                  mass=0.038,
                  inertia=[1., 5.9e-4,  1.])

    io.add_object('slider', [
        Shape(shape_name='Slider',
              instance_name='cslid',
              relative_translation=[-a, 0., 0.]),
        Contactor(
            instance_name='Contact_b_f1',
            shape_name='Contact_b_cyl',
            contact_type='Face',
            contact_index=1,
            relative_translation=[-a, 0., 0.]),
        Contactor(
            instance_name='Contact_h_f1',
            shape_name='Contact_h_cyl',
            contact_type='Face',
            contact_index=1,
            relative_translation=[-a, 0., 0.]),
        Contactor(
            instance_name='Contact_b_f0',
            shape_name='Contact_b_cyl',
            contact_type='Face',
            contact_index=0,
            relative_translation=[-a, 0., 0.]),
        Contactor(
Exemple #23
0
from OCC.gp import gp_Pnt

siconos.io.mechanics_run.set_backend('occ')

sphere = BRepPrimAPI_MakeSphere(1.).Shape()
ground = BRepPrimAPI_MakeBox(gp_Pnt(-50, -50, 0), 100., 100., .5).Shape()

# Creation of the hdf5 file for input/output
with MechanicsHdf5Runner() as io:

    io.add_occ_shape('Sphere', sphere)
    io.add_occ_shape('Ground', ground)

    io.add_object('sphere', [
        Volume('Sphere'),
        Contactor('Sphere', contact_type='Face', contact_index=0)
    ],
                  mass=1,
                  translation=[0, 0, 10],
                  velocity=[0, 0, 0, 0, 0, 0])

    io.add_object('ground',
                  [Contactor('Ground', contact_type='Face', contact_index=5)],
                  mass=0,
                  translation=[0, 0, 0])

    io.add_interaction('sphere-ground',
                       'sphere',
                       'Sphere-1',
                       'ground',
                       'Ground-0',
Exemple #24
0
motor_id = None

# Creation of the hdf5 file for input/output
with Hdf5() as io:

    # Only touch the ground, ignore contacts between links of the robot
    io.addNewtonImpactFrictionNSL('contact',
                                  collision_group1=0,
                                  collision_group2=1,
                                  mu=0.3,
                                  e=0.0)

    # Definition of the ground shape
    io.addPrimitiveShape('Ground', 'Box', (100, 100, 2))
    io.addObject('ground', [Contactor('Ground', collision_group=1)],
                 translation=[0, 0, -1])

    # Define shape of a bar-shaped link
    io.addPrimitiveShape('Bar1', 'Box', (10, 1, 1))
    io.addPrimitiveShape('Bar2', 'Box', (12.67, 1, 1))

    ## Core
    bar1 = \
    io.addObject('bar1', [Contactor('Bar1'),
                          Contactor('Bar1',
                                    relative_translation=[5.5, 0, 0],
                                    relative_orientation=[(0,0,1), pi/2]),
                          Contactor('Bar1',
                                    relative_translation=[-5.5, 0, 0],
                                    relative_orientation=[(0,0,1), pi/2])],
    # io.add_object('Ball' % k, [Contactor('Ball')],
    #               translation=[0., 0., 0.],
    #               mass=1.0)
    

    # a big rock
    one_rock(io, 'rock', 'rock_shape', rock_size = rock_size,
             density=2300,
             trans = [30.,0. ,35.],
             velo=rock_velocity, tob=rock_tob)

    
    
    # Definition of the ground
    io.add_primitive_shape('Ground', 'Box', (50, 50, 0.1))
    io.add_object('ground', [Contactor('Ground')], [0, 0, -0.05])
    # Definition of the slope
    angle_slope= -math.pi/4.0
    io.add_object('slope', [Contactor('Ground',
                                      relative_translation=[30.0, 0.0, -25.0* math.sin(angle_slope)],
                                      relative_orientation=[math.cos(angle_slope/2.0),
                                                            0.0,
                                                            math.sin(angle_slope/2.0),
                                                            0.0]) ],
                  [0, 0, -0.05])

    # # Enable to smash the wall
    # io.add_primitive_shape('Ball', 'Sphere', [1,])
    # io.add_object('WreckingBall', [Contactor('Ball')],
    #              translation=[25,0,3], velocity=[-30,0,2,0,0,0],
    #              mass=10)
    v3 = numpy.array([5.00, 0.9354, 0.3535])

    amont_normal = normal_plane(v1, v2, v3)
    print('amont_normal=', amont_normal)

    v0_extruded = v0 + numpy.dot(plan_thickness, amont_normal)
    v1_extruded = v1 + numpy.dot(plan_thickness, amont_normal)
    v2_extruded = v2 + numpy.dot(plan_thickness, amont_normal)
    v3_extruded = v3 + numpy.dot(plan_thickness, amont_normal)

    amont_vertices = numpy.array(
        [v0, v1, v2, v3, v0_extruded, v1_extruded, v2_extruded, v3_extruded])
    print amont_vertices

    io.addConvexShape('amont', amont_vertices)
    io.addObject('amont', [Contactor('amont')],
                 translation=[1.50, -1.45, -1.5331])

    ######### aval
    v4 = numpy.array([-2.50, 0, 0])
    v5 = numpy.array([5.00, 0, 0])

    aval_normal = normal_plane(v2, v4, v3)
    print('aval_normal=', aval_normal)

    v4_extruded = v4 + numpy.dot(plan_thickness, aval_normal)
    v5_extruded = v5 + numpy.dot(plan_thickness, aval_normal)

    aval_vertices = numpy.array(
        [v2, v3, v4, v5, v2_extruded, v3_extruded, v4_extruded, v5_extruded])
    print aval_vertices
            M = M - 1 if M > 1 else M
            W = W - 1
            z += height + sep

    # A column
    make_stack(0, -10, 1, 1, size_stack)

    # A pyramid
    make_stack(0, 0, size_stack, size_stack, size_stack)

    # A wall
    make_stack(0, 10, 1, size_stack, size_stack)

    # Definition of the ground
    io.add_primitive_shape('Ground', 'Box', (50, 50, 0.1))
    io.add_object('ground', [Contactor('Ground')], [0, 0, -0.05])

    # Enable to smash the wall
    # io.add_primitive_shape('Ball', 'Sphere', [1,])
    # io.add_object('WreckingBall', [Contactor('Ball')],
    #              translation=[30,0,3], velocity=[-30,0,2,0,0,0],
    #              mass=10)

    # Definition of a non smooth law. As no group ids are specified it
    # is between contactors of group id 0.
    io.add_Newton_impact_friction_nsl('contact', mu=0.3)

solver = sn.SICONOS_GLOBAL_FRICTION_3D_ADMM

dump_probability = .02
theta = 0.50
Exemple #28
0
    # raw_input()
    # Definition of a cube as a convex shape
    io.add_convex_shape('Bar', [(-bar_length, bar_width, -bar_height),
                                (-bar_length, -bar_width, -bar_height),
                                (-bar_length, -bar_width, bar_height),
                                (-bar_length, bar_width, bar_height),
                                (bar_length, bar_width, bar_height),
                                (bar_length, bar_width, -bar_height),
                                (bar_length, -bar_width, -bar_height),
                                (bar_length, -bar_width, bar_height)])

    angle = math.pi / 8.0
    trans = [0, 0, 4.0 * scale]
    ori = [math.cos(angle / 2.0), 0.0, math.sin(angle / 2.0), 0]
    print('ori initial', ori)
    io.add_object('bar', [Contactor('Bar')],
                  translation=trans,
                  orientation=ori,
                  velocity=[0, 0, 0, 0, 0.0, 0],
                  mass=mass)

    # Definition of the ground shape
    io.add_primitive_shape('Ground', 'Box',
                           (5 * scale, 5 * scale, 0.1 * scale))
    angleground = -math.pi / 4.0
    axis = [1.0, 0.0, 0.0]
    origround = [
        math.cos(angleground / 2.0), axis[0] * math.sin(angleground / 2.0),
        axis[1] * math.sin(angleground / 2.0),
        axis[2] * math.sin(angleground / 2.0)
    ]
Exemple #29
0
    # Alternative to the previous convex shape definition.
    # io.add_primitive_shape('Cube1', 'Box', (2, 2, 2))

    # Definition of the ground shape
    io.add_primitive_shape('Ground', 'Box', (100, 100, .5))

    # Definition of a non smooth law. As no group ids are specified it
    # is between contactors of group id 0.
    io.add_Newton_impact_friction_nsl('contact', mu=0.3)

    # The cube object made with an unique Contactor : the cube shape.
    # As a mass is given, it is a dynamic system involved in contact
    # detection and in the simulation.  With no group id specified the
    # Contactor belongs to group 0
    io.add_object('cube', [Contactor('Cube')], translation=[0, 0, 2],
                  velocity=[10, 0, 0, 1, 1, 1],
                  mass=1)

    # the ground object made with the ground shape. As the mass is
    # not given, it is a static object only involved in contact
    # detection.
    io.add_object('ground', [Contactor('Ground')],
                  translation=[0, 0, 0])


# Run the simulation from the inputs previously defined and add
# results to the hdf5 file. The visualisation of the output may be done
# with the vview command.
with MechanicsHdf5Runner(mode='r+') as io:
Exemple #30
0
    io.add_primitive_shape('CubePrim2', 'Box', (2*edge_length, 2*edge_length,
                                                2*edge_length))

    # Definition of the ground shape
    io.add_primitive_shape('Ground', 'Box',
                           (plane_length, plane_length, plane_length/10.0))

    # Definition of a non smooth law. As no group ids are specified it
    # is between contactors of group id 0.
    io.add_Newton_impact_friction_nsl('contact', mu=0.3, e=0.5)

    # The cube object made with an unique Contactor : the cube shape.
    # As a mass is given, it is a dynamic system involved in contact
    # detection and in the simulation.  With no group id specified the
    # Contactor belongs to group 0
    io.add_object('cube1', [Contactor('CubeCS1')], translation=[0, 0, 2],
                  velocity=[velocity_init, 0, 0,  angular_velocity_init,
                            angular_velocity_init, angular_velocity_init],
                  mass=1)

    io.add_object('cube2', [Contactor('CubeCS2')],
                  translation=[0, 0, 2+3*edge_length],
                  velocity=[velocity_init, 0, 0,
                            angular_velocity_init,
                            angular_velocity_init,
                            angular_velocity_init],
                  mass=1)

    io.add_object('cubeP1', [Contactor('CubePrim1')],
                  translation=[0, 3*edge_length, 2],
                  velocity=[velocity_init, 0, 0,