# Or use the specialized SearchBody().

my_shaft = my_system.SearchBody('Crankshaft-1')
if not my_shaft:
    sys.exit('Error: cannot find shaft  from its name in the C::E system!')

my_ground = my_system.SearchBody('ground')
if not my_ground:
    sys.exit('Error: cannot find ground from its name in the C::E system!')

# ***TRICK***
# Create an engine along the Z direction of the coordsystem specified by
# the marker, and acting between shaft and ground

revolute_frame = my_marker.GetAbsFrame()
link_motor = chrono.ChLinkMotorRotationSpeed()
link_motor.Initialize(my_shaft, my_ground, revolute_frame)
link_motor.SetSpindleConstraint(
    chrono.ChLinkMotorRotationSpeed.SpindleConstraint_CYLINDRICAL
)  # Set_shaft_mode(chrono.ChLinkEngine.ENG_SHAFT_PRISM)
link_motor.SetMotorFunction(chrono.ChFunction_Const(
    1.0 * chrono.CH_C_2PI))  # 1.0 Hz to rad/s
my_system.Add(link_motor)

if m_visualization == "pov":

    # ---------------------------------------------------------------------
    #
    #  Render a short animation by generating scripts
    #  to be used with POV-Ray
    #
Esempio n. 2
0
myjoint.Initialize(node_mid, mbodyflywheel)
my_system.Add(myjoint)

# Create the truss
truss = chrono.ChBody()
truss.SetBodyFixed(True)
my_system.Add(truss)

# Create the end bearing
bearing = chrono.ChLinkMateGeneric(False, True, True, False, True, True)
bearing.Initialize(builder.GetLastBeamNodes().back(), truss,
                   chrono.ChFrameD(builder.GetLastBeamNodes().back().GetPos()))
my_system.Add(bearing)

# Create the motor that rotates the beam
rotmotor1 = chrono.ChLinkMotorRotationSpeed()

# Connect the rotor and the stator and add the motor to the system:
rotmotor1.Initialize(
    builder.GetLastBeamNodes().front(),  # body A (slave)
    truss,  # body B (master)
    chrono.ChFrameD(
        builder.GetLastBeamNodes().front().GetPos(),
        chrono.Q_from_AngAxis(CH_C_PI / 2.0,
                              chrono.VECT_Y))  # motor frame, in abs. coords
)
my_system.Add(rotmotor1)


# use a custom function for setting the speed of the motor
class ChFunction_myf(chrono.ChFunction):
Esempio n. 3
0
## - a rotation of -90 degrees around x (z2y)
## - a rotation of +90 degrees around y (z2x)
z2y = chrono.ChQuaternionD()
z2x = chrono.ChQuaternionD()
z2y.Q_from_AngAxis(-chrono.CH_C_PI / 2, chrono.ChVectorD(1, 0, 0))
z2x.Q_from_AngAxis(chrono.CH_C_PI / 2, chrono.ChVectorD(0, 1, 0))

## Create a ChFunction object that always returns the constant value PI/2.
fun = chrono.ChFunction_Const()
fun.Set_yconst(chrono.CH_C_PI)

## Motor between ground and crank.
## Note that this also acts as a revolute joint (i.e. it enforces the same
## kinematic constraints as a revolute joint).  As before, we apply the 'z2y'
## rotation to align the rotation axis with the Y axis of the global frame.
engine_ground_crank = chrono.ChLinkMotorRotationSpeed()
engine_ground_crank.SetName("engine_ground_crank")
engine_ground_crank.Initialize(ground, crank,
                               chrono.ChFrameD(chrono.ChVectorD(0, 0, 0), z2y))
engine_ground_crank.SetSpeedFunction(fun)
system.AddLink(engine_ground_crank)

## Prismatic joint between ground and slider.
## The translational axis of a prismatic joint is along the Z axis of the
## specified joint coordinate system.  Here, we apply the 'z2x' rotation to
## align it with the X axis of the global reference frame.
prismatic_ground_slider = chrono.ChLinkLockPrismatic()
prismatic_ground_slider.SetName("prismatic_ground_slider")
prismatic_ground_slider.Initialize(
    ground, slider, chrono.ChCoordsysD(chrono.ChVectorD(2, 0, 0), z2x))
system.AddLink(prismatic_ground_slider)