Пример #1
0
my_shbodyA.SetMass(20)
my_shbodyA.SetName('BodyA')
my_shbodyA.SetInertiaXX( chrono.ChVectorD(10,10,10) )
print (my_shbodyA.GetInertia() )
my_shbodyA.SetPos(chrono.ChVectorD(1,-1,0))
my_shbodyA.GetCollisionModel().AddBox(10,1,10)
my_shbodyA.SetBodyFixed(True)
my_shbodyA.SetCollide(True)

my_shbodyB = chrono.ChBody()
my_shbodyB.SetName('BodyB')
my_shbodyB.SetPos(chrono.ChVectorD(0,2,0))
my_shbodyB.GetCollisionModel().AddBox(1,1,1)
my_shbodyB.SetCollide(True)

my_shmarker = chrono.ChMarker()
my_funct = chrono.ChFunction_Sine(0,0.5,3)
my_shmarker.SetMotion_X(my_funct)
my_shmarker.SetPos(chrono.ChVectorD(1,2,3))
my_shbodyB.AddMarker(my_shmarker)

my_system.Add(my_shbodyA)
my_system.Add(my_shbodyB)

# Define surface material(s)
my_shmaterial = chrono.ChMaterialSurfaceNSC()
my_shmaterial.SetFriction(0.3)
my_shmaterial.SetCompliance(0)
my_shbodyA.SetMaterialSurface(my_shmaterial)
my_shbodyB.SetMaterialSurface(my_shmaterial)
Пример #2
0
    def reset(self):
        #print("reset")
        self.isdone = False
        self.rev_pend_sys.Clear()
        # create it
        self.body_rod = chrono.ChBody()
        # set initial position
        self.body_rod.SetPos(chrono.ChVectorD(0, self.size_rod_y / 2, 0))
        # set mass properties
        self.body_rod.SetMass(self.mass_rod)

        self.body_rod.SetInertiaXX(
            chrono.ChVectorD(self.inertia_rod_x, self.inertia_rod_y,
                             self.inertia_rod_x))
        # set collision surface properties
        self.body_rod.SetMaterialSurface(self.rod_material)

        # Visualization shape, for rendering animation

        self.cyl_base1 = chrono.ChVectorD(0, -self.size_rod_y / 2, 0)
        self.cyl_base2 = chrono.ChVectorD(0, self.size_rod_y / 2, 0)

        self.body_rod_shape = chrono.ChCylinderShape()
        self.body_rod_shape.GetCylinderGeometry().p1 = self.cyl_base1
        self.body_rod_shape.GetCylinderGeometry().p2 = self.cyl_base2
        self.body_rod_shape.GetCylinderGeometry().rad = self.radius_rod

        self.body_rod.AddAsset(self.body_rod_shape)
        self.rev_pend_sys.Add(self.body_rod)

        self.body_floor = chrono.ChBody()
        self.body_floor.SetBodyFixed(True)
        self.body_floor.SetPos(chrono.ChVectorD(0, -5, 0))
        self.body_floor.SetMaterialSurface(self.rod_material)

        if self.render:
            self.body_floor_shape = chrono.ChBoxShape()
            self.body_floor_shape.GetBoxGeometry().Size = chrono.ChVectorD(
                3, 1, 3)
            self.body_floor.GetAssets().push_back(self.body_floor_shape)
            self.body_floor_texture = chrono.ChTexture()
            self.body_floor_texture.SetTextureFilename(
                '../../../data/concrete.jpg')
            self.body_floor.GetAssets().push_back(self.body_floor_texture)

        self.rev_pend_sys.Add(self.body_floor)

        self.body_table = chrono.ChBody()
        self.body_table.SetPos(chrono.ChVectorD(0, -self.size_table_y / 2, 0))
        self.body_table.SetMaterialSurface(self.rod_material)

        if self.render:
            self.body_table_shape = chrono.ChBoxShape()
            self.body_table_shape.GetBoxGeometry().Size = chrono.ChVectorD(
                self.size_table_x / 2, self.size_table_y / 2,
                self.size_table_z / 2)
            self.body_table_shape.SetColor(chrono.ChColor(0.4, 0.4, 0.5))
            self.body_table.GetAssets().push_back(self.body_table_shape)

            self.body_table_texture = chrono.ChTexture()
            self.body_table_texture.SetTextureFilename(
                '../../../data/concrete.jpg')
            self.body_table.GetAssets().push_back(self.body_table_texture)
        self.body_table.SetMass(0.1)
        self.rev_pend_sys.Add(self.body_table)

        self.link_slider = chrono.ChLinkLockPrismatic()
        z2x = chrono.ChQuaternionD()
        z2x.Q_from_AngAxis(-chrono.CH_C_PI / 2, chrono.ChVectorD(0, 1, 0))

        self.link_slider.Initialize(
            self.body_table, self.body_floor,
            chrono.ChCoordsysD(chrono.ChVectorD(0, 0, 0), z2x))
        self.rev_pend_sys.Add(self.link_slider)

        self.act_initpos = chrono.ChVectorD(0, 0, 0)
        self.actuator = chrono.ChLinkMotorLinearForce()
        self.actuator.Initialize(self.body_table, self.body_floor,
                                 chrono.ChFrameD(self.act_initpos))
        self.rev_pend_sys.Add(self.actuator)

        self.rod_pin = chrono.ChMarker()
        self.body_rod.AddMarker(self.rod_pin)
        self.rod_pin.Impose_Abs_Coord(
            chrono.ChCoordsysD(chrono.ChVectorD(0, 0, 0)))

        self.table_pin = chrono.ChMarker()
        self.body_table.AddMarker(self.table_pin)
        self.table_pin.Impose_Abs_Coord(
            chrono.ChCoordsysD(chrono.ChVectorD(0, 0, 0)))

        self.pin_joint = chrono.ChLinkLockRevolute()
        self.pin_joint.Initialize(self.rod_pin, self.table_pin)
        self.rev_pend_sys.Add(self.pin_joint)

        if self.render:

            # ---------------------------------------------------------------------
            #
            #  Create an Irrlicht application to visualize the system
            #
            # ==IMPORTANT!== Use this function for adding a ChIrrNodeAsset to all items
            # in the system. These ChIrrNodeAsset assets are 'proxies' to the Irrlicht meshes.
            # If you need a finer control on which item really needs a visualization proxy
            # Irrlicht, just use application.AssetBind(myitem); on a per-item basis.

            self.myapplication.AssetBindAll()

            # ==IMPORTANT!== Use this function for 'converting' into Irrlicht meshes the assets
            # that you added to the bodies into 3D shapes, they can be visualized by Irrlicht!

            self.myapplication.AssetUpdateAll()

        self.isdone = False
        self.steps = 0
        self.step(np.array([[0]]))
        return self.get_ob()
Пример #3
0
bodyA.SetMass(20)
bodyA.SetName('BodyA')
bodyA.SetInertiaXX(chrono.ChVectorD(10, 10, 10))
print(bodyA.GetInertia())
bodyA.SetPos(chrono.ChVectorD(1, -1, 0))
bodyA.GetCollisionModel().AddBox(material, 10, 1, 10)
bodyA.SetBodyFixed(True)
bodyA.SetCollide(True)

bodyB = chrono.ChBody()
bodyB.SetName('BodyB')
bodyB.SetPos(chrono.ChVectorD(0, 2, 0))
bodyB.GetCollisionModel().AddBox(material, 1, 1, 1)
bodyB.SetCollide(True)

markerB = chrono.ChMarker()
my_funct = chrono.ChFunction_Sine(0, 0.5, 3)
markerB.SetMotion_X(my_funct)
markerB.SetPos(chrono.ChVectorD(1, 2, 3))
bodyB.AddMarker(markerB)

my_system.Add(bodyA)
my_system.Add(bodyB)


# Report Contact callback
class MyReportContactCallback(chrono.ReportContactCallback):
    def __init__(self):
        chrono.ReportContactCallback.__init__(self)

    def OnReportContact(self, vA, vB, cA, dist, rad, force, torque, modA,
Пример #4
0
    def reset(self):
        #print("reset")
        self.isdone = False
        self.rev_pend_sys.Clear()
        # create it
        self.body_rod = chrono.ChBody()
        # set initial position
        self.body_rod.SetPos(chrono.ChVectorD(0, self.size_rod_y / 2, 0))
        # set mass properties
        self.body_rod.SetMass(self.mass_rod)

        self.body_rod.SetInertiaXX(
            chrono.ChVectorD(self.inertia_rod_x, self.inertia_rod_y,
                             self.inertia_rod_x))
        # set collision surface properties
        self.body_rod.SetMaterialSurface(self.rod_material)

        self.cyl_base1 = chrono.ChVectorD(0, -self.size_rod_y / 2, 0)
        self.cyl_base2 = chrono.ChVectorD(0, self.size_rod_y / 2, 0)

        self.body_rod_shape = chrono.ChCylinderShape()
        self.body_rod_shape.GetCylinderGeometry().p1 = self.cyl_base1
        self.body_rod_shape.GetCylinderGeometry().p2 = self.cyl_base2
        self.body_rod_shape.GetCylinderGeometry().rad = self.radius_rod

        self.body_rod.AddAsset(self.body_rod_shape)
        self.rev_pend_sys.Add(self.body_rod)

        self.body_floor = chrono.ChBody()
        self.body_floor.SetBodyFixed(True)
        self.body_floor.SetPos(chrono.ChVectorD(0, -5, 0))
        self.body_floor.SetMaterialSurface(self.rod_material)
        self.body_floor_shape = chrono.ChBoxShape()
        self.body_floor_shape.GetBoxGeometry().Size = chrono.ChVectorD(3, 1, 3)
        self.body_floor.GetAssets().push_back(self.body_floor_shape)
        self.body_floor_texture = chrono.ChTexture()
        self.body_floor_texture.SetTextureFilename(chrono.GetChronoDataPath() +
                                                   '/concrete.jpg')
        self.body_floor.GetAssets().push_back(self.body_floor_texture)

        self.rev_pend_sys.Add(self.body_floor)

        self.body_table = chrono.ChBody()
        self.body_table.SetPos(chrono.ChVectorD(0, -self.size_table_y / 2, 0))
        self.body_table.SetMaterialSurface(self.rod_material)

        self.body_table.SetMass(0.1)
        self.body_table_shape = chrono.ChBoxShape()
        self.body_table_shape.GetBoxGeometry().Size = chrono.ChVectorD(
            self.size_table_x / 2, self.size_table_y / 2,
            self.size_table_z / 2)
        self.body_table_shape.SetColor(chrono.ChColor(0.4, 0.4, 0.5))
        self.body_table.GetAssets().push_back(self.body_table_shape)
        self.body_table_texture = chrono.ChTexture()
        self.body_table_texture.SetTextureFilename(chrono.GetChronoDataPath() +
                                                   '/concrete.jpg')
        self.body_table.GetAssets().push_back(self.body_table_texture)
        self.rev_pend_sys.Add(self.body_table)

        self.link_slider = chrono.ChLinkLockPrismatic()
        z2x = chrono.ChQuaternionD()
        z2x.Q_from_AngAxis(-chrono.CH_C_PI / 2, chrono.ChVectorD(0, 1, 0))

        self.link_slider.Initialize(
            self.body_table, self.body_floor,
            chrono.ChCoordsysD(chrono.ChVectorD(0, 0, 0), z2x))
        self.rev_pend_sys.Add(self.link_slider)

        self.act_initpos = chrono.ChVectorD(0, 0, 0)
        self.actuator = chrono.ChLinkMotorLinearForce()
        self.actuator.Initialize(self.body_table, self.body_floor,
                                 chrono.ChFrameD(self.act_initpos))
        self.rev_pend_sys.Add(self.actuator)

        self.rod_pin = chrono.ChMarker()
        self.body_rod.AddMarker(self.rod_pin)
        self.rod_pin.Impose_Abs_Coord(
            chrono.ChCoordsysD(chrono.ChVectorD(0, 0, 0)))

        self.table_pin = chrono.ChMarker()
        self.body_table.AddMarker(self.table_pin)
        self.table_pin.Impose_Abs_Coord(
            chrono.ChCoordsysD(chrono.ChVectorD(0, 0, 0)))

        self.pin_joint = chrono.ChLinkLockRevolute()
        self.pin_joint.Initialize(self.rod_pin, self.table_pin)
        self.rev_pend_sys.Add(self.pin_joint)

        if self.render_setup:
            self.myapplication.AssetBindAll()
            self.myapplication.AssetUpdateAll()

        self.isdone = False
        self.steps = 0
        self.step(np.array([[0]]))
        return self.get_ob()
Пример #5
0
    def reset(self):
        #print("reset")
        self.isdone = False
        self.rev_pend_sys.Clear()
        # create it
        self.body_rod = chrono.ChBody()
        # set initial position
        self.body_rod.SetPos(chrono.ChVectorD(0, self.size_rod_y / 2, 0))
        # set mass properties
        self.body_rod.SetMass(self.mass_rod)
        # una volta che le hao calcolate inserisci inerzie diverse
        self.body_rod.SetInertiaXX(
            chrono.ChVectorD(self.inertia_rod_x, self.inertia_rod_y,
                             self.inertia_rod_x))
        # set collision surface properties
        self.body_rod.SetMaterialSurface(self.rod_material)

        # Visualization shape, for rendering animation
        # vettori visual cilindro
        self.cyl_base1 = chrono.ChVectorD(0, -self.size_rod_y / 2, 0)
        self.cyl_base2 = chrono.ChVectorD(0, self.size_rod_y / 2, 0)
        #body_rod_shape = chrono.ChCylinder(cyl_base1, cyl_base2, radius_rod)
        self.body_rod_shape = chrono.ChCylinderShape()
        self.body_rod_shape.GetCylinderGeometry().p1 = self.cyl_base1
        self.body_rod_shape.GetCylinderGeometry().p2 = self.cyl_base2
        self.body_rod_shape.GetCylinderGeometry().rad = self.radius_rod
        #body_rod.GetAssets().push_back(body_rod_shape)
        self.body_rod.AddAsset(self.body_rod_shape)
        self.rev_pend_sys.Add(self.body_rod)

        self.body_floor = chrono.ChBody()
        self.body_floor.SetBodyFixed(True)
        self.body_floor.SetPos(chrono.ChVectorD(0, -5, 0))
        self.body_floor.SetMaterialSurface(self.rod_material)

        # Visualization shape
        if self.render:
            self.body_floor_shape = chrono.ChBoxShape()
            self.body_floor_shape.GetBoxGeometry().Size = chrono.ChVectorD(
                3, 1, 3)
            self.body_floor.GetAssets().push_back(self.body_floor_shape)
            self.body_floor_texture = chrono.ChTexture()
            self.body_floor_texture.SetTextureFilename(
                '../../../data/concrete.jpg')
            self.body_floor.GetAssets().push_back(self.body_floor_texture)

        self.rev_pend_sys.Add(self.body_floor)

        self.body_table = chrono.ChBody()
        self.body_table.SetPos(chrono.ChVectorD(0, -self.size_table_y / 2, 0))
        self.body_table.SetMaterialSurface(self.rod_material)

        # Visualization shape
        if self.render:
            self.body_table_shape = chrono.ChBoxShape()
            self.body_table_shape.GetBoxGeometry().Size = chrono.ChVectorD(
                self.size_table_x / 2, self.size_table_y / 2,
                self.size_table_z / 2)
            self.body_table_shape.SetColor(chrono.ChColor(0.4, 0.4, 0.5))
            self.body_table.GetAssets().push_back(self.body_table_shape)

            self.body_table_texture = chrono.ChTexture()
            self.body_table_texture.SetTextureFilename(
                '../../../data/concrete.jpg')
        self.body_table.GetAssets().push_back(self.body_table_texture)
        self.body_table.SetMass(0.1)
        self.rev_pend_sys.Add(self.body_table)

        # Create a constraint that blocks free 3 x y z translations and 3 rx ry rz rotations
        # of the table respect to the floor, and impose that the relative imposed position
        # depends on a specified motion law.

        self.link_slider = chrono.ChLinkLockPrismatic()
        z2x = chrono.ChQuaternionD()
        z2x.Q_from_AngAxis(-chrono.CH_C_PI / 2, chrono.ChVectorD(0, 1, 0))

        self.link_slider.Initialize(
            self.body_table, self.body_floor,
            chrono.ChCoordsysD(chrono.ChVectorD(0, 0, 0), z2x))
        self.rev_pend_sys.Add(self.link_slider)
        self.link_slider.SetMotion_axis(chrono.ChVectorD(1, 0, 0))
        #attuatore lineare
        self.act_initpos = chrono.ChVectorD(0, 0, 0)
        self.actuator = chrono.ChLinkMotorLinearForce()
        self.actuator.Initialize(self.body_table, self.body_floor,
                                 chrono.ChFrameD(self.act_initpos))
        self.rev_pend_sys.Add(self.actuator)

        # ..create the function for imposed y vertical motion, etc.
        # tolta: solo traslazione asse z
        #mfunY = chrono.ChFunction_Sine(0,1.5,0.001)  # phase, frequency, amplitude
        #link_slider.SetMotion_Y(mfunY)

        # ..create the function for imposed z horizontal motion, etc.
        #self.mfunX = chrono.ChFunction_Sine(0,1.5,0.4)  # phase, frequency, amplitude
        #self.link_slider.SetMotion_X(self.action)

        # Note that you could use other types of ChFunction_ objects, or create
        # your custom function by class inheritance (see demo_python.py), or also
        # set a function for table rotation , etc.

        # REVLOLUTE JOINT:
        # create frames for the joint
        self.rod_pin = chrono.ChMarker()
        self.body_rod.AddMarker(self.rod_pin)
        self.rod_pin.Impose_Abs_Coord(
            chrono.ChCoordsysD(chrono.ChVectorD(0, 0, 0)))

        self.table_pin = chrono.ChMarker()
        self.body_table.AddMarker(self.table_pin)
        self.table_pin.Impose_Abs_Coord(
            chrono.ChCoordsysD(chrono.ChVectorD(0, 0, 0)))

        self.pin_joint = chrono.ChLinkLockRevolute()
        self.pin_joint.Initialize(self.rod_pin, self.table_pin)
        self.rev_pend_sys.Add(self.pin_joint)

        if self.render:

            # ---------------------------------------------------------------------
            #
            #  Create an Irrlicht application to visualize the system
            #
            # ==IMPORTANT!== Use this function for adding a ChIrrNodeAsset to all items
            # in the system. These ChIrrNodeAsset assets are 'proxies' to the Irrlicht meshes.
            # If you need a finer control on which item really needs a visualization proxy
            # Irrlicht, just use application.AssetBind(myitem); on a per-item basis.

            self.myapplication.AssetBindAll()

            # ==IMPORTANT!== Use this function for 'converting' into Irrlicht meshes the assets
            # that you added to the bodies into 3D shapes, they can be visualized by Irrlicht!

            self.myapplication.AssetUpdateAll()

            # If you want to show shadows because you used "AddLightWithShadow()'
            # you must remember this:

        self.isdone = False
        self.steps = 0
        self.step(np.array([[0]]))
        return self.get_ob()