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
def GetVisualization(self): level = chrono.ChAssetLevel() cyl = chrono.ChCylinderShape() cyl.GetCylinderGeometry().rad = self.radius cyl.GetCylinderGeometry().p1 = self.center + chrono.ChVectorD(0, 0, 0) cyl.GetCylinderGeometry().p2 = self.center + chrono.ChVectorD( 0, 1.1, 0) level.AddAsset(cyl) level.AddAsset(chrono.ChColorAsset(0.6, 0.3, 0.0)) return level
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
shaft_1.SetPos(chrono.ChVectorD(0, 0, -hl)) shaft_1.SetRot(chrono.ChQuaternionD(1, 0, 0, 0)) # Add visualization assets to represent the shaft (a box) and the arm of the # universal joint's cross associated with this shaft (a cylinder) box_1 = chrono.ChBoxShape() box_1.GetBoxGeometry().Size = chrono.ChVectorD(0.15, 0.15, 0.9 * hl) shaft_1.AddAsset(box_1) cyl_2 = chrono.ChCylinderShape() cyl_2.GetCylinderGeometry().p1 = chrono.ChVectorD(-0.2, 0, hl) cyl_2.GetCylinderGeometry().p2 = chrono.ChVectorD(0.2, 0, hl) cyl_2.GetCylinderGeometry().rad = 0.05 shaft_1.AddAsset(cyl_2) col = chrono.ChColorAsset() col.SetColor(chrono.ChColor(0.9, 0.4, 0.1)) shaft_1.AddAsset(col) # Create the second shaft body # ---------------------------- # The second shaft is identical to the first one, but initialized at an angle # equal to the specified bend angle. shaft_2 = chrono.ChBody() mysystem.AddBody(shaft_2) shaft_2.SetIdentifier(1) shaft_2.SetBodyFixed(False) shaft_2.SetCollide(False) shaft_2.SetMass(1)
def LoadFromObj(filename, density=1000, color=[1,0.1,0.1]): body = chrono.ChBodyEasyMesh(filename, density, True, True) body.AddAsset(chrono.ChColorAsset(chrono.ChColor(color[0], color[1], color[2]))) return body
# 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)) myapplication.AddTypicalSky(chrono.GetChronoDataPath() + 'skybox/') myapplication.AddTypicalLogo(chrono.GetChronoDataPath() + 'logo_pychrono_alpha.png') myapplication.AddTypicalCamera(chronoirr.vector3df(0.2, 0.2, -0.2)) myapplication.AddTypicalLights()
body = chrono.ChBody() mysystem.Add(body) body.SetMass(500) body.SetInertiaXX(chrono.ChVectorD(20, 20, 20)) body.SetPos(tire_center + chrono.ChVectorD(0, 0.3, 0)) # Load mesh mesh = chrono.ChTriangleMeshConnected() mesh.LoadWavefrontMesh( chrono.GetChronoDataFile('models/tractor_wheel/tractor_wheel.obj')) # Set visualization assets vis_shape = chrono.ChTriangleMeshShape() vis_shape.SetMesh(mesh) body.AddAsset(vis_shape) body.AddAsset(chrono.ChColorAsset(0.3, 0.3, 0.3)) # Set collision shape material = chrono.ChMaterialSurfaceSMC() body.GetCollisionModel().ClearModel() body.GetCollisionModel().AddTriangleMesh( material, # contact material mesh, # the mesh False, # is it static? False, # is it convex? chrono.ChVectorD(0, 0, 0), # position on body chrono.ChMatrix33D(1), # orientation on body 0.01) # "thickness" for increased robustness body.GetCollisionModel().BuildModel() body.SetCollide(True)
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)) myapplication.AddTypicalSky() myapplication.AddTypicalLogo(chrono.GetChronoDataPath() + 'logo_pychrono_alpha.png') myapplication.AddTypicalCamera(chronoirr.vector3df(0.2, 0.2, -0.2)) myapplication.AddTypicalLights()
system.AddBody(pend_1) pend_1.SetIdentifier(1) pend_1.SetBodyFixed(False) pend_1.SetCollide(False) pend_1.SetMass(1) pend_1.SetInertiaXX(chrono.ChVectorD(0.2, 1, 1)) # Attach a visualization asset. Note that the cylinder is defined with # respect to the centroidal reference frame (which is the body reference # frame for a ChBody) cyl_1 = chrono.ChCylinderShape() cyl_1.GetCylinderGeometry().p1 = chrono.ChVectorD(-1, 0, 0) cyl_1.GetCylinderGeometry().p2 = chrono.ChVectorD(1, 0, 0) cyl_1.GetCylinderGeometry().rad = 0.2 pend_1.AddAsset(cyl_1) col_1 = chrono.ChColorAsset(0.6, 0, 0) pend_1.AddAsset(col_1) # Specify the intial position of the pendulum (horizontal, pointing towards # positive X). In this case, we set the absolute position of its center of # mass pend_1.SetPos(chrono.ChVectorD(1, 0, 1)) # Create a revolute joint to connect pendulum to ground. We specify the link # coordinate frame in the absolute frame. rev_1 = chrono.ChLinkLockRevolute() rev_1.Initialize(ground, pend_1, chrono.ChCoordsysD(chrono.ChVectorD(0, 0, 1), chrono.ChQuaternionD(1, 0, 0, 0))) system.AddLink(rev_1) # Create a pendulum modeled using ChBodyAuxRef
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) # Create the plane-plane constraint # Constrain the sliding body to move and rotate in the x-y plane # (i.e. the plane whose normal is the z-axis of the specified coord sys) plane_plane = chrono.ChLinkLockPlanePlane() plane_plane.Initialize(ground, body, chrono.ChCoordsysD(chrono.ChVectorD(-1.25, -0.75, 0), chrono.ChQuaternionD(1, 0, 0, 0))) mysystem.AddLink(plane_plane) # Create a linear spring (with default sprint & damping coefficients) spring = chrono.ChLinkTSDA() spring.SetSpringCoefficient(100)