chrono.ChCoordsysD(chrono.ChVectorD(0, 0, -1), chrono.Q_from_AngY(chrono.CH_C_PI_2))) system.AddLink(prismatic1) prismatic2 = chrono.ChLinkLockPrismatic() prismatic2.Initialize( slider2, ground, chrono.ChCoordsysD(chrono.ChVectorD(0, 0, 1), chrono.Q_from_AngY(chrono.CH_C_PI_2))) system.AddLink(prismatic2) # Sine function parameters freq = 1 ampl = 4 omg = 2 * chrono.CH_C_PI * freq mod = chrono.ChFunction_Sine(0, freq, ampl) # Actuate first slider using a link force prismatic1.GetForce_Z().SetActive(True) prismatic1.GetForce_Z().SetF(1) prismatic1.GetForce_Z().SetModulationF(mod) # Actuate second slider using a body force frc2 = chrono.ChForce() frc2.SetF_x(mod) slider2.AddForce(frc2) # Create the Irrlicht application application = irr.ChIrrApp(system, "Actuated prismatic joint", irr.dimension2du(800, 600), False, True) application.AddTypicalLogo()
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)
if not my_floor : sys.exit('Error: cannot find floor from its name in the C::E system!') my_floor.AddAsset(floor_povmat) my_ground = my_system.SearchBody('ground') if not my_ground : sys.exit('Error: cannot find ground from its name in the C::E system!') # make the shaking motion my_floor.SetBodyFixed(False) link_shaker = chrono.ChLinkLockLock() link_shaker.Initialize(my_floor, my_ground, chrono.CSYSNORM) my_system.Add(link_shaker) my_functA = chrono.ChFunction_Sine(0,1.4,0.06) my_functA.thisown = 0 my_functB = chrono.ChFunction_Sine(0,0.1,1) my_functB.thisown = 0 my_funct = chrono.ChFunction_Operation() my_funct.Set_fa(my_functA) my_funct.Set_fb(my_functB) my_funct.Set_optype(chrono.ChOP_MUL) my_funct.thisown = 0 link_shaker.SetMotion_X(my_funct) if m_visualization == "pov": # --------------------------------------------------------------------- # # Render a short animation by generating scripts
# Ramp function # ------------- f_ramp = chrono.ChFunction_Ramp() f_ramp.Set_ang(0.1) # angular coefficient f_ramp.Set_y0(0.1) # y value at x = 0 # Evaluate the function and its first derivative at a given value y = f_ramp.Get_y(10) yd = f_ramp.Get_y_dx(10) print(' Ramp function f(10) = ', y, ', 1st derivative df/dx(10) = ', yd) # Sine function # ------------- f_sine = chrono.ChFunction_Sine() f_sine.Set_amp(2) # amplitude f_sine.Set_freq(1.5) # frequency # Evaluate the function and its derivatives at 101 points in [0,2] and write to file sine_file = open(out_dir + "/f_sine.out","w+") for i in range(101): x = i / 50.0 y = f_sine.Get_y(x) yd = f_sine.Get_y_dx(x) ydd = f_sine.Get_y_dxdx(x) sine_file.write("%f %f %f %f\n" % (x, y, yd, ydd)) sine_file.close() # Custom function # ---------------
# In this example we impose position and rotation of a body shape respect to absolute reference, # using the following methods: # # position: use a triplet of X,Y,Z ChFunction objects # rotation: use a fixed axis of rotation and an angle(time) function defined via a ChFunction # Create the object to move mmoved_1 = chrono.ChBodyEasyMesh( chrono.GetChronoDataFile("models/support.obj"), 1000, True, True, False) system.Add(mmoved_1) mmoved_1.SetPos(chrono.ChVectorD(-0.5, 0, 0)) # Create a position function p(t) from three x,y,z distinct ChFunction objects, # in this case two sine functions on y and z, whereas x remains constant 0 by default. f_xyz = chrono.ChFunctionPosition_XYZfunctions() f_xyz.SetFunctionY(chrono.ChFunction_Sine(0, 0.5, 0.5)) f_xyz.SetFunctionZ(chrono.ChFunction_Sine(0, 0.5, 0.5)) # Create a rotation function q(t) from a angle(time) rotation with fixed axis: f_rot_axis = chrono.ChFunctionRotation_axis() f_rot_axis.SetFunctionAngle(chrono.ChFunction_Sine(0, 0.15, chrono.CH_C_PI)) f_rot_axis.SetAxis(chrono.ChVectorD(1, 1, 1).GetNormalized()) # Create the constraint to impose motion and rotation. # Note that the constraint acts by imposing the motion and rotation between # frame1 of Body1 (the impose_1 body in this case) and frame2 of Body2 (the floor # fixed reference in this case, but it could also be another moving object). # We initially set both frame1 and frame2 in the same absolute position, btw in the # main reference of the moved mesh, by setting it during the Initialize() method. impose_1 = chrono.ChLinkMotionImposed() system.Add(impose_1)