Пример #1
0
    def add_container(self):
        padding = 10

        # Create the five walls of the rectangular container, using fixed rigid bodies of 'box' type
        floor_body = chrono.ChBodyEasyBox(self.container_width + padding, 1,
                                          self.container_length + padding,
                                          1000, True, True, self.ground_mat)
        floor_body.SetPos(chrono.ChVectorD(0, 0, 0))
        floor_body.SetBodyFixed(True)
        self.system.Add(floor_body)

        if self.with_walls:
            wall_body_1 = chrono.ChBodyEasyBox(1, self.wall_height,
                                               self.container_length + padding,
                                               1000, True, True,
                                               self.ground_mat)
            wall_body_1.SetPos(
                chrono.ChVectorD(-self.container_width / 2,
                                 self.wall_height / 2, 0))
            wall_body_1.SetBodyFixed(True)
            self.system.Add(wall_body_1)

            wall_body_2 = chrono.ChBodyEasyBox(1, self.wall_height,
                                               self.container_length + padding,
                                               1000, True, True,
                                               self.ground_mat)
            wall_body_2.SetPos(
                chrono.ChVectorD(self.container_width / 2,
                                 self.wall_height / 2, 0))
            wall_body_2.SetBodyFixed(True)
            self.system.Add(wall_body_2)

            wall_body_3 = chrono.ChBodyEasyBox(self.container_width + padding,
                                               self.wall_height, 1, 1000,
                                               False, True, self.ground_mat)
            wall_body_3.SetPos(
                chrono.ChVectorD(0, self.wall_height / 2,
                                 -self.container_length / 2))
            wall_body_3.SetBodyFixed(True)
            self.system.Add(wall_body_3)

            wall_body_4 = chrono.ChBodyEasyBox(self.container_width + padding,
                                               self.wall_height, 1, 1000, True,
                                               True, self.ground_mat)
            wall_body_4.SetPos(
                chrono.ChVectorD(0, self.wall_height / 2,
                                 self.container_length / 2))
            wall_body_4.SetBodyFixed(True)
            self.system.Add(wall_body_4)
Пример #2
0
def CreateSliderGuide(material, msystem, mpos):
    mguide = chrono.ChBodyEasyBox(4, 0.3, 0.6, 1000, True, True, material)
    mguide.SetPos(mpos)
    mguide.SetBodyFixed(True)
    msystem.Add(mguide)

    mslider = chrono.ChBodyEasyBox(0.4, 0.2, 0.5, 1000, True, True, material)
    mslider.SetPos(mpos + chrono.ChVectorD(0, 0.3, 0))
    msystem.Add(mslider)

    mcolor = chrono.ChColorAsset(0.6, 0.6, 0.0)
    mslider.AddAsset(mcolor)

    obstacle = chrono.ChBodyEasyBox(0.4, 0.4, 0.4, 8000, True, True, material)
    obstacle.SetPos(mpos + chrono.ChVectorD(1.5, 0.4, 0))
    msystem.Add(obstacle)
    mcolorobstacle = chrono.ChColorAsset(0.2, 0.2, 0.2)
    mslider.AddAsset(mcolorobstacle)
    return mguide, mslider
Пример #3
0
def CreateStatorRotor(material, msystem, mpos):
    mstator = chrono.ChBodyEasyCylinder(0.5, 0.1, 1000, True, True, material)
    mstator.SetPos(mpos)
    mstator.SetRot(chrono.Q_from_AngAxis(chrono.CH_C_PI_2, chrono.VECT_X))
    mstator.SetBodyFixed(True)
    msystem.Add(mstator)

    mrotor = chrono.ChBodyEasyBox(1, 0.1, 0.1, 1000, True, True, material)
    mrotor.SetPos(mpos + chrono.ChVectorD(0.5, 0, -0.15))
    msystem.Add(mrotor)

    mcolor = chrono.ChColorAsset(0.6, 0.6, 0.0)
    mrotor.AddAsset(mcolor)
    return mstator, mrotor
Пример #4
0
def AddFallingItems(sys):
    # Shared contact materials for falling objects
    sph_mat = chrono.ChMaterialSurfaceNSC()
    sph_mat.SetFriction(0.2)
    box_mat = chrono.ChMaterialSurfaceNSC()
    cyl_mat = chrono.ChMaterialSurfaceNSC()

    # Create falling rigid bodies (spheres and boxes etc.)
    for bi in range(29):
        msphereBody = chrono.ChBodyEasySphere(1.1,      # radius size
                                              1000,     # density
                                              True,     # visualization?
                                              True,     # collision?
                                              sph_mat)  # contact material
        msphereBody.SetPos(chrono.ChVectorD(-5 + chrono.ChRandom() * 10, 4 + bi * 0.05, -5 + chrono.ChRandom() * 10))
        sys.Add(msphereBody)

        mtexture = chrono.ChTexture()
        mtexture.SetTextureFilename(chrono.GetChronoDataFile("textures/bluewhite.png"))
        msphereBody.AddAsset(mtexture)

        mboxBody = chrono.ChBodyEasyBox(1.5, 1.5, 1.5, # x,y,z size
                                        100,           # density
                                        True,          # visualization?
                                        True,          # collision?
                                        box_mat)       # contact material
        mboxBody.SetPos(chrono.ChVectorD(-5 + chrono.ChRandom() * 10, 4 + bi * 0.05, -5 + chrono.ChRandom() * 10))

        sys.Add(mboxBody)

        mtexturebox = chrono.ChTexture()
        mtexturebox.SetTextureFilename(chrono.GetChronoDataFile("textures/cubetexture_bluewhite.png"))
        mboxBody.AddAsset(mtexturebox)

        mcylBody = chrono.ChBodyEasyCylinder(0.75, 0.5, # radius, height
                                             100,       # density
                                             True,      # visualization?
                                             True,      # collision?
                                             cyl_mat)   # contact material
        mcylBody.SetPos(chrono.ChVectorD(-5 + chrono.ChRandom() * 10, 4 + bi * 0.05, -5 + chrono.ChRandom() * 10))

        sys.Add(mcylBody)

        # optional, attach a texture for better visualization
        mtexturecyl = chrono.ChTexture()
        mtexturecyl.SetTextureFilename(chrono.GetChronoDataFile("textures/pinkwhite.png"))
        mcylBody.AddAsset(mtexturecyl)
Пример #5
0
braking_time = 0.3   # time to go from 0 to +1
# driver.SetSteeringDelta(render_step_size / steering_time)
# driver.SetThrottleDelta(render_step_size / throttle_time)
# driver.SetBrakingDelta(render_step_size / braking_time)

driver.Initialize()

# ---------------
# Simulation loop
# ---------------

for points in (track.left.points,track.right.points):
    for i in range(len(points)-1):
        p1 = points[i]+chrono.ChVectorD(0,0,.5)
        p2 = points[i+1]
        box = chrono.ChBodyEasyBox((p2-p1).Length()/10, .2, .8, 1000, True, True)
        box.SetPos(p1)

        v1 = p2-p1
        v2 = chrono.ChVectorD(1,0,0)
        ang = math.atan2((v1%v2).Length(), v1^v2)
        if (chrono.ChVectorD(0,0,1)^(v1%v2) > 0.0): ang *= -1
        q = chrono.Q_from_AngZ(ang)
        box.SetRot(q)
        box.SetBodyFixed(True)
        box_asset = box.GetAssets()[0]
        visual_asset = chrono.CastToChVisualization(box_asset)

        vis_mat = chrono.ChVisualMaterial()
        vis_mat.SetAmbientColor(chrono.ChVectorF(0, 0, 0))
Пример #6
0
#

mysystem = chrono.ChSystemNSC()

# Set the global collision margins. This is expecially important for very large or
# very small objects. Set this before creating shapes. Not before creating mysystem.
chrono.ChCollisionModel.SetDefaultSuggestedEnvelope(0.001)
chrono.ChCollisionModel.SetDefaultSuggestedMargin(0.001)

# ---------------------------------------------------------------------
#
#  Create the simulation system and add items
#

# Create a floor
mfloor = chrono.ChBodyEasyBox(3, 0.2, 3, 1000, True, True)
mfloor.SetBodyFixed(True)
mysystem.Add(mfloor)

# Now we will create a falling object whose shape is defined by a .obj mesh.
#
# NOTE: collision detection with generic concave meshes is slower and less
# robust than any other options for collision shapes, so use it if defining
# collision shapes via primitives like spheres boxes cylinders or their
# clusters is too complex.
#
# NOTE: the mesh shape is a .obj file in Wavefront file format,
# you can generate it from 3D modelers such as Blender, Maya, etc.
#
# NOTE: for collision purposes, the .obj mesh must be "watertight", i.e. having
# no gaps in edges, no repeated vertexes, etc.
Пример #7
0
measured_joint_pos_mm = chrono.ChVectorD(0, 48, 120)

scale = 1. / 1000.  # because we use meters instead of mm

joint_pos = chrono.ChVectorD(
    root_frame.TransformPointLocalToParent(measured_joint_pos_mm * scale))
# transform because we rotated everything

if (mrigidBody1 and mrigidBody2):
    my_link = chrono.ChLinkLockRevolute()
    my_link.Initialize(mrigidBody1, mrigidBody2, chrono.ChCoordsysD(joint_pos))
    mysystem.Add(my_link)

# Create a large cube as a floor.

mfloor = chrono.ChBodyEasyBox(1, 0.2, 1, 1000)
mfloor.SetPos(chrono.ChVectorD(0, -0.3, 0))
mfloor.SetBodyFixed(True)
mysystem.Add(mfloor)

mcolor = chrono.ChColorAsset(0.3, 0.3, 0.8)
mfloor.AddAsset(mcolor)

# ---------------------------------------------------------------------
#
#  Create an Irrlicht application to visualize the system
#

myapplication = chronoirr.ChIrrApp(mysystem, 'Test',
                                   chronoirr.dimension2du(1024, 768))
Пример #8
0
def main():
    # -----------------
    # Create the system
    # -----------------
    mphysicalSystem = chrono.ChSystemNSC()
    mphysicalSystem.Set_G_acc(chrono.ChVectorD(0, 0, -9.81))

    # ----------------------------------------
    # add a floor, box and sphere to the scene
    # ----------------------------------------
    phys_mat = chrono.ChMaterialSurfaceNSC()
    phys_mat.SetFriction(0.5)
    phys_mat.SetDampingF(0.00000)
    phys_mat.SetCompliance(1e-9)
    phys_mat.SetComplianceT(1e-9)

    floor = chrono.ChBodyEasyBox(10, 10, 1, 1000, True, True, phys_mat)
    floor.SetPos(chrono.ChVectorD(0, 0, -1))
    floor.SetBodyFixed(True)
    mphysicalSystem.Add(floor)

    box = chrono.ChBodyEasyBox(1, 1, 1, 1000, True, True, phys_mat)
    box.SetPos(chrono.ChVectorD(0, 0, 5))
    box.SetRot(chrono.Q_from_AngAxis(.2, chrono.ChVectorD(1, 0, 0)))
    mphysicalSystem.Add(box)

    sphere = chrono.ChBodyEasySphere(.5, 1000, True, True, phys_mat)
    sphere.SetPos(chrono.ChVectorD(0, 0, 8))
    sphere.SetRot(chrono.Q_from_AngAxis(.2, chrono.ChVectorD(1, 0, 0)))
    mphysicalSystem.Add(sphere)

    sphere_asset = sphere.GetAssets()[0]
    visual_asset = chrono.CastToChVisualization(sphere_asset)

    vis_mat = chrono.ChVisualMaterial()
    vis_mat.SetAmbientColor(chrono.ChVectorF(0, 0, 0))
    vis_mat.SetDiffuseColor(chrono.ChVectorF(.2, .2, .9))
    vis_mat.SetSpecularColor(chrono.ChVectorF(.9, .9, .9))

    visual_asset.material_list.append(vis_mat)

    # -----------------------
    # Create a sensor manager
    # -----------------------
    manager = sens.ChSensorManager(mphysicalSystem)
    manager.scene.AddPointLight(chrono.ChVectorF(100, 100, 100),
                                chrono.ChVectorF(1, 1, 1), 1000.0)
    manager.scene.AddPointLight(chrono.ChVectorF(-100, -100, 100),
                                chrono.ChVectorF(1, 1, 1), 1000.0)

    # ------------------------------------------------
    # Create a camera and add it to the sensor manager
    # ------------------------------------------------
    offset_pose = chrono.ChFrameD(
        chrono.ChVectorD(-8, 0, 1),
        chrono.Q_from_AngAxis(0, chrono.ChVectorD(0, 1, 0)))
    cam = sens.ChCameraSensor(
        floor,  # body camera is attached to
        cam_update_rate,  # update rate in Hz
        offset_pose,  # offset pose
        image_width,  # number of horizontal samples
        image_height,  # number of vertical channels
        cam_fov  # vertical field of view
    )
    cam.SetName("Camera Sensor")
    cam.SetLag(cam_lag)
    cam.SetCollectionWindow(cam_collection_time)

    # ------------------------------------------------------------------
    # Create a filter graph for post-processing the data from the camera
    # ------------------------------------------------------------------
    # Visualizes the image
    if vis:
        cam.PushFilter(
            sens.ChFilterVisualize(image_width, image_height, "RGB Image"))

    # Save the current image to a png file at the specified path
    if (save):
        cam.PushFilter(sens.ChFilterSave(out_dir + "/rgb/"))

    # Provides the host access to this RGBA8 buffer
    cam.PushFilter(sens.ChFilterRGBA8Access())

    # Filter the sensor to grayscale
    cam.PushFilter(sens.ChFilterGrayscale())

    # Render the buffer again to see the new grayscaled image
    if (vis):
        cam.PushFilter(
            sens.ChFilterVisualize(int(image_width / 2), int(image_height / 2),
                                   "Grayscale Image"))

    # Save the grayscaled image at the specified path
    if (save):
        cam.PushFilter(sens.ChFilterSave(out_dir + "/gray/"))

    # Access the grayscaled buffer as R8 pixels
    cam.PushFilter(sens.ChFilterR8Access())

    # Add a camera to a sensor manager
    manager.AddSensor(cam)

    # ------------------------------------------------
    # Create a lidar and add it to the sensor manager
    # ------------------------------------------------
    offset_pose = chrono.ChFrameD(
        chrono.ChVectorD(-8, 0, 1),
        chrono.Q_from_AngAxis(0, chrono.ChVectorD(0, 1, 0)))
    lidar = sens.ChLidarSensor(
        floor,  # body lidar is attached to
        lidar_update_rate,  # scanning rate in Hz
        offset_pose,  # offset pose
        horizontal_samples,  # number of horizontal samples
        vertical_samples,  # number of vertical channels
        horizontal_fov,  # horizontal field of view
        max_vert_angle,
        min_vert_angle,  # vertical field of view
        100  #max lidar range
    )
    lidar.SetName("Lidar Sensor")
    lidar.SetLag(lidar_lag)
    lidar.SetCollectionWindow(lidar_collection_time)

    # -----------------------------------------------------------------
    # Create a filter graph for post-processing the data from the lidar
    # -----------------------------------------------------------------
    if vis:
        # Randers the raw lidar data
        lidar.PushFilter(
            sens.ChFilterVisualize(horizontal_samples, vertical_samples,
                                   "Raw Lidar Depth Data"))

    # Provides the host access to the Depth,Intensity data
    lidar.PushFilter(sens.ChFilterDIAccess())

    # Convert Depth,Intensity data to XYZI point cloud data
    lidar.PushFilter(sens.ChFilterPCfromDepth())

    if vis:
        # Visualize the point cloud
        lidar.PushFilter(
            sens.ChFilterVisualizePointCloud(640, 480, 1.0,
                                             "Lidar Point Cloud"))

    # Provides the host access to the XYZI data
    lidar.PushFilter(sens.ChFilterXYZIAccess())

    # Add the lidar to the sensor manager
    manager.AddSensor(lidar)

    # ----------------------------------------------
    # Create an IMU sensor and add it to the manager
    # ----------------------------------------------
    offset_pose = chrono.ChFrameD(
        chrono.ChVectorD(-8, 0, 1),
        chrono.Q_from_AngAxis(0, chrono.ChVectorD(0, 1, 0)))
    imu = sens.ChIMUSensor(
        box,  # body imu is attached to
        imu_update_rate,  # update rate in Hz
        offset_pose,  # offset pose
        imu_noise_none,  # noise model
    )
    imu.SetName("IMU Sensor")
    imu.SetLag(imu_lag)
    imu.SetCollectionWindow(imu_collection_time)

    # Provides the host access to the imu data
    imu.PushFilter(sens.ChFilterIMUAccess())

    # Add the imu to the sensor manager
    manager.AddSensor(imu)

    # ----------------------------------------------
    # Create an GPS sensor and add it to the manager
    # ----------------------------------------------
    offset_pose = chrono.ChFrameD(
        chrono.ChVectorD(-8, 0, 1),
        chrono.Q_from_AngAxis(0, chrono.ChVectorD(0, 1, 0)))
    gps = sens.ChGPSSensor(
        box,  # body imu is attached to
        gps_update_rate,  # update rate in Hz
        offset_pose,  # offset pose
        gps_reference,
        gps_noise_none  # noise model
    )
    gps.SetName("GPS Sensor")
    gps.SetLag(gps_lag)
    gps.SetCollectionWindow(gps_collection_time)

    # Provides the host access to the gps data
    gps.PushFilter(sens.ChFilterGPSAccess())

    # Add the gps to the sensor manager
    manager.AddSensor(gps)

    # ---------------
    # Simulate system
    # ---------------
    t1 = time.time()
    ch_time = 0
    while (ch_time < end_time):

        # Access the sensor data
        camera_data_RGBA8 = cam.GetMostRecentRGBA8Buffer()
        camera_data_R8 = cam.GetMostRecentR8Buffer()
        lidar_data_DI = lidar.GetMostRecentDIBuffer()
        lidar_data_XYZI = lidar.GetMostRecentXYZIBuffer()
        gps_data = gps.GetMostRecentGPSBuffer()
        imu_data = imu.GetMostRecentIMUBuffer()

        # Check data is present
        # If so, print out the max value
        if camera_data_RGBA8.HasData():
            print("Camera RGBA8:",
                  camera_data_RGBA8.GetRGBA8Data().shape, "max:",
                  np.max(camera_data_RGBA8.GetRGBA8Data()))
        if camera_data_R8.HasData():
            print("Camera R8:",
                  camera_data_R8.GetChar8Data().shape, "max:",
                  np.max(camera_data_R8.GetChar8Data()))
        if lidar_data_DI.HasData():
            print("Lidar DI:",
                  lidar_data_DI.GetDIData().shape, "max:",
                  np.max(lidar_data_DI.GetDIData()))
        if lidar_data_XYZI.HasData():
            print("Lidar XYZI:",
                  lidar_data_XYZI.GetXYZIData().shape, "max:",
                  np.max(lidar_data_XYZI.GetXYZIData()))
        if gps_data.HasData():
            print("GPS:",
                  gps_data.GetGPSData().shape, "max:",
                  np.max(gps_data.GetGPSData()))
        if imu_data.HasData():
            print("IMU:",
                  imu_data.GetIMUData().shape, "max:",
                  np.max(imu_data.GetIMUData()))

        # Update sensor manager
        # Will render/save/filter automatically
        manager.Update()

        # Perform step of dynamics
        mphysicalSystem.DoStepDynamics(step_size)

        # Get the current time of the simulation
        ch_time = mphysicalSystem.GetChTime()

    print("Sim time:", end_time, "Wall time:", time.time() - t1)
Пример #9
0
my_link7 = chrono.ChLinkLockRevolute()
my_link7.Initialize(mrigidBody_turret, mrigidBody_cylinder, frame_marker_turret_cylinder.GetCoord())
mysystem.Add(my_link7)

my_link8 = chrono.ChLinkLockRevolute()
my_link8.Initialize(mrigidBody_cylinder, mrigidBody_rod, frame_marker_cylinder_rod.GetCoord())
mysystem.Add(my_link8)
        
my_link9 = chrono.ChLinkLockRevolute()
my_link9.Initialize(mrigidBody_rod, mrigidBody_bicep, frame_marker_rod_bicep.GetCoord())
mysystem.Add(my_link9)

                         
# Create a large cube as a floor.

mfloor = chrono.ChBodyEasyBox(5, 1, 5, 1000, True, True)
mfloor.SetPos(chrono.ChVectorD(0,-0.5,0))
mfloor.SetBodyFixed(True)
mysystem.Add(mfloor)

mcolor = chrono.ChColorAsset(0.3, 0.3, 0.8)
mfloor.AddAsset(mcolor)


# We want to move the hand of the robot using a trajectory.
# Since in this demo all joints are 'off' (i.e just revolute joints),
# it follows that if we move the hand all the robot will automatically
# move as in inverse kinematics.

# Create a ChLinePath geometry, for the hand path, and insert arc/lines sub-paths:
mpath = chrono.ChLinePath()
Пример #10
0
print("Example: create a system and visualize it in realtime 3D")

# The path to the Chrono data directory containing various assets (meshes, textures, data files)
# is automatically set, relative to the default location of this demo.
# If running from a different directory, you must change the path to the data directory with:
#chrono.SetChronoDataPath('path/to/data')

# ---------------------------------------------------------------------
#
#  Create the simulation system and add items
#

mysystem = chrono.ChSystemNSC()

mfloor = chrono.ChBodyEasyBox(3, 0.2, 3, 1000)
mfloor.SetBodyFixed(True)
mysystem.Add(mfloor)

#
# EXAMPLE1
#

# Create a ChLinePath geometry, and insert sub-paths:
mpath = chrono.ChLinePath()
mseg1 = chrono.ChLineSegment(chrono.ChVectorD(1, 2, 0),
                             chrono.ChVectorD(2, 2, 0))
mpath.AddSubLine(mseg1)
marc1 = chrono.ChLineArc(chrono.ChCoordsysD(chrono.ChVectorD(2, 2.5, 0)), 0.5,
                         -chrono.CH_C_PI_2, chrono.CH_C_PI_2, True)
mpath.AddSubLine(marc1)
Пример #11
0
cut_off = 0.00001
run_visible = True

system = chrono.ChSystemNSC()
system.SetSolverType(chrono.ChSolver.Type_BARZILAIBORWEIN)

# Contact material for container
ground_mat = chrono.ChMaterialSurfaceNSC()
ground_mat.SetFriction(0.8)

# Shared contact materials for falling objects
dice_mat = chrono.ChMaterialSurfaceNSC()
dice_mat.SetFriction(0.5)

# Create the five walls of the rectangular container, using fixed rigid bodies of 'box' type
floor_body = chrono.ChBodyEasyBox(210, 1, 210, 1000, True, True, ground_mat)
floor_body.SetPos(chrono.ChVectorD(0, 0, 0))
floor_body.SetBodyFixed(True)
system.Add(floor_body)

die_file = dodeca.get_chrono_mesh()
die = chrono.ChBodyEasyMesh(
    die_file,  # obj filename
    10000,  # density
    True,  # compute mass?
    True,  # visualization?
    True,  # collision?
    dice_mat)  # material
system.Add(die)

dice_position = [0, 5, 0]
Пример #12
0
my_tolerance = cascade.ChCascadeTriangulateTolerances(0.1 ,True,0.5)


my_body = cascade.ChBodyEasyCascade(my_shape,# the CAD shape
                                  1000,             # the density
                                  my_tolerance,      # must visualize triangle mesh geometry?
                                  True,              # must collide?
                                  my_material)       # collision material
mysystem.Add(my_body)

    
# Create a large cube as a floor.

my_floor = chrono.ChBodyEasyBox(1, 0.2, 1, # x y z size
                                1000,       # density
                                True,       # must visualize?
                                True,       # must collide?
                                my_material) # collision material
my_floor.SetPos(chrono.ChVectorD(0,-0.3,0))
my_floor.SetBodyFixed(True)
mysystem.Add(my_floor)

my_color = chrono.ChColorAsset(0.2, 0.2, 0.5)
my_floor.AddAsset(my_color)



# ---------------------------------------------------------------------
#
#  Create an Irrlicht application to visualize the system
#
Пример #13
0
# Set the global collision margins. This is expecially important for very large or
# very small objects. Set this before creating shapes. Not before creating mysystem.
chrono.ChCollisionModel.SetDefaultSuggestedEnvelope(0.001);
chrono.ChCollisionModel.SetDefaultSuggestedMargin(0.001);

# ---------------------------------------------------------------------
#
#  Create the simulation system and add items
#

# Create a contact material (with default properties, shared by all collision shapes)
contact_material = chrono.ChMaterialSurfaceNSC()

# Create a floor
mfloor = chrono.ChBodyEasyBox(3, 0.2, 3, 1000,True,True, contact_material)
mfloor.SetBodyFixed(True)
mysystem.Add(mfloor)


# Now we will create a falling object whose shape is defined by a .obj mesh.
#
# NOTE: collision detection with generic concave meshes is slower and less
# robust than any other options for collision shapes, so use it if defining 
# collision shapes via primitives like spheres boxes cylinders or their
# clusters is too complex.
#
# NOTE: the mesh shape is a .obj file in Wavefront file format,
# you can generate it from 3D modelers such as Blender, Maya, etc. 
#
# NOTE: for collision purposes, the .obj mesh must be "watertight", i.e. having
Пример #14
0
    mcolor = chrono.ChColorAsset(0.6, 0.6, 0.0)
    mrotor.AddAsset(mcolor)
    return mstator, mrotor


print("Copyright (c) 2017 projectchrono.org")

# Create a ChronoENGINE physical system
mphysicalSystem = chrono.ChSystemNSC()

# Contact material shared among all objects
material = chrono.ChMaterialSurfaceNSC()

# Create a floor that is fixed (that is used also to represent the absolute reference)
floorBody = chrono.ChBodyEasyBox(20, 2, 20, 3000, True, True, material)
floorBody.SetPos(chrono.ChVectorD(0, -2, 0))
floorBody.SetBodyFixed(True)
mphysicalSystem.Add(floorBody)

mtexture = chrono.ChTexture()
mtexture.SetTextureFilename(chrono.GetChronoDataFile("textures/blue.png"))
floorBody.AddAsset(mtexture)

# In the following we will create different types of motors
# - rotational motors: examples A.1, A.2, etc.
# - linear motors, examples B.1, B.2 etc.

# EXAMPLE A.1
#
# - class:   ChLinkMotorRotationSpeed
Пример #15
0
my_torus = BRepPrimAPI.BRepPrimAPI_MakeTorus(0.1, 0.02).Shape()
my_cylinder = BRepPrimAPI.BRepPrimAPI_MakeCylinder(0.09, 0.1).Shape()
my_shape = BRepAlgoAPI.BRepAlgoAPI_Cut(my_torus, my_cylinder).Shape()

# use it to make a body with proper center of mass and inertia tensor,
# given the CAD shape. Also visualize it.
my_body = cascade.ChBodyEasyCascade(
    my_shape,  # the CAD shape
    1000,  # the density
    True,  # must collide using the triangle mesh geometry?
    True)  # must be visualized?
mysystem.Add(my_body)

# Create a large cube as a floor.

my_floor = chrono.ChBodyEasyBox(1, 0.2, 1, 1000, True)
my_floor.SetPos(chrono.ChVectorD(0, -0.3, 0))
my_floor.SetBodyFixed(True)
mysystem.Add(my_floor)

my_color = chrono.ChColorAsset(0.2, 0.2, 0.5)
my_floor.AddAsset(my_color)

# ---------------------------------------------------------------------
#
#  Create an Irrlicht application to visualize the system
#

myapplication = chronoirr.ChIrrApp(mysystem, 'Use OpenCascade shapes',
                                   chronoirr.dimension2du(1024, 768))
Пример #16
0
def AddContainer(sys):
    # Contact material for container
    ground_mat = chrono.ChMaterialSurfaceNSC()

    # Create the five walls of the rectangular container, using fixed rigid bodies of 'box' type
    floorBody = chrono.ChBodyEasyBox(20, 1, 20, 1000, True, True, ground_mat)
    floorBody.SetPos(chrono.ChVectorD(0, -5, 0))
    floorBody.SetBodyFixed(True)
    sys.Add(floorBody)

    wallBody1 = chrono.ChBodyEasyBox(1, 10, 20.99, 1000, True, True, ground_mat)
    wallBody1.SetPos(chrono.ChVectorD(-10, 0, 0))
    wallBody1.SetBodyFixed(True)
    sys.Add(wallBody1)

    wallBody2 = chrono.ChBodyEasyBox(1, 10, 20.99, 1000, True, True, ground_mat)
    wallBody2.SetPos(chrono.ChVectorD(10, 0, 0))
    wallBody2.SetBodyFixed(True)
    sys.Add(wallBody2)

    wallBody3 = chrono.ChBodyEasyBox(20.99, 10, 1, 1000, False, True, ground_mat)
    wallBody3.SetPos(chrono.ChVectorD(0, 0, -10))
    wallBody3.SetBodyFixed(True)
    sys.Add(wallBody3)

    wallBody4 = chrono.ChBodyEasyBox(20.99, 10, 1, 1000, True, True, ground_mat)
    wallBody4.SetPos(chrono.ChVectorD(0, 0, 10))
    wallBody4.SetBodyFixed(True)
    sys.Add(wallBody4)

    # optional, attach  textures for better visualization
    mtexturewall = chrono.ChTexture()
    mtexturewall.SetTextureFilename(chrono.GetChronoDataFile("textures/concrete.jpg"))
    wallBody1.AddAsset(mtexturewall)  # note: most assets can be shared
    wallBody2.AddAsset(mtexturewall)
    wallBody3.AddAsset(mtexturewall)
    wallBody4.AddAsset(mtexturewall)
    floorBody.AddAsset(mtexturewall)

    # Add the rotating mixer
    mixer_mat = chrono.ChMaterialSurfaceNSC()
    mixer_mat.SetFriction(0.4)

    rotatingBody = chrono.ChBodyEasyBox(10, 5, 1,  # x,y,z size
                                        4000,      # density
                                        True,      # visualization?
                                        True,      # collision?
                                        mixer_mat) # contact material
    rotatingBody.SetPos(chrono.ChVectorD(0, -1.6, 0))
    sys.Add(rotatingBody)

    # .. a motor between mixer and truss
    my_motor = chrono.ChLinkMotorRotationSpeed()
    my_motor.Initialize(rotatingBody,
                        floorBody, 
                        chrono.ChFrameD(chrono.ChVectorD(0, 0, 0), 
                            chrono.Q_from_AngAxis(chrono.CH_C_PI_2, chrono.VECT_X)))
    mfun = chrono.ChFunction_Const(chrono.CH_C_PI / 4.0)  # speed 45 deg/s 
    my_motor.SetSpeedFunction(mfun)
    sys.AddLink(my_motor)

    # NOTE: Instead of creating five separate 'box' bodies to make
    # the walls of the container, you could have used a single body
    # made of five box shapes, which build a single collision description,
    # as in the alternative approach:

    """
    # create a plain ChBody (no colliding shape nor visualization mesh is used yet)
    mrigidBody = chrono.ChBody()

    # set as fixed body, and turn collision ON, otherwise no collide by default
    mrigidBody.SetBodyFixed(True)
    mrigidBody.SetCollide(True)

    # Clear model. The colliding shape description MUST be between  ClearModel() .. BuildModel() pair.
    mrigidBody.GetCollisionModel().ClearModel()
    # Describe the (invisible) colliding shape by adding five boxes (the walls and floor)
    mrigidBody.GetCollisionModel().AddBox(ground_mat, 20, 1, 20, chrono.ChVectorD(0, -10, 0))
    mrigidBody.GetCollisionModel().AddBox(ground_mat, 1, 40, 20, chrono.ChVectorD(-11, 0, 0))
    mrigidBody.GetCollisionModel().AddBox(ground_mat, 1, 40, 20, chrono.ChVectorD(11, 0, 0))
    mrigidBody.GetCollisionModel().AddBox(ground_mat, 20, 40, 1, chrono.ChVectorD(0, 0, -11))
    mrigidBody.GetCollisionModel().AddBox(ground_mat, 20, 40, 1, chrono.ChVectorD(0, 0, 11))
    # Complete the description of collision shape.
    mrigidBody.GetCollisionModel().BuildModel()

    # Attach some visualization shapes if needed:
    vshape = chrono.ChBoxShape()
    vshape.GetBoxGeometry().SetLengths(chrono.ChVectorD(20, 1, 20))
    vshape.GetBoxGeometry().Pos = chrono.ChVectorD(0, -5, 0)
    this.AddAsset(vshape)
    # etc. for other 4 box shapes..
    """

    return rotatingBody
Пример #17
0
#
#  Create the simulation system and add items
#

mysystem = chrono.ChSystemNSC()

# Some data shared in the following
crank_center = chrono.ChVectorD(-1, 0.5, 0)
crank_rad = 0.4
crank_thick = 0.1
rod_length = 1.5

# Create four rigid bodies: the truss, the crank, the rod, the piston.

# Create the floor truss
mfloor = chrono.ChBodyEasyBox(3, 1, 3, 1000)
mfloor.SetPos(chrono.ChVectorD(0, -0.5, 0))
mfloor.SetBodyFixed(True)
mysystem.Add(mfloor)

# Create the flywheel crank
mcrank = chrono.ChBodyEasyCylinder(crank_rad, crank_thick, 1000)
mcrank.SetPos(crank_center + chrono.ChVectorD(0, 0, -0.1))
# Since ChBodyEasyCylinder creates a vertical (y up) cylinder, here rotate it:
mcrank.SetRot(chrono.Q_ROTATE_Y_TO_Z)
mysystem.Add(mcrank)

# Create a stylized rod
mrod = chrono.ChBodyEasyBox(rod_length, 0.1, 0.1, 1000)
mrod.SetPos(crank_center + chrono.ChVectorD(crank_rad + rod_length / 2, 0, 0))
mysystem.Add(mrod)
Пример #18
0
# The path to the Chrono data directory containing various assets (meshes, textures, data files)
# is automatically set, relative to the default location of this demo.
# If running from a different directory, you must change the path to the data directory with: 
#chrono.SetChronoDataPath('relative/path/to/data/directory/')

# ---------------------------------------------------------------------
#
#  Create the simulation system and add items
#

mysystem      = chrono.ChSystemNSC()
mysystem.Set_G_acc(chrono.ChVectorD(0, 0, 0))

# Create the ground body
ground = chrono.ChBodyEasyBox(3, 2, 0.1, 10, True, False)
ground.SetBodyFixed(True)
mysystem.Add(ground)

# Create the sliding body
# Give an initial angular velocity
body = chrono.ChBodyEasyBox(0.5, 0.5, 0.5, 10, True, False)
body.SetBodyFixed(False)
mysystem.Add(body)
body.SetPos(chrono.ChVectorD(-1.25, -0.75, 0.1))
body.SetWvel_loc(chrono.ChVectorD(0.1, 0.1, 0.1))

body_col = chrono.ChColorAsset()
body_col.SetColor(chrono.ChColor(0.9, 0.4, 0.1))
body.AddAsset(body_col)