Build Models with Your Own Modeling Elements

A block sliding in a translational joint is used to illustrate how classes you created can be used in simplifying modeling. Notice that the syntax for built-in classes is identical to the syntax for user-created classes.
################################################################################ 
# Model definition #
################################################################################
def sliding_block ():
 """Test case for the LuGre friction model
 Slide a block across a surface.
 The block is attached to ground with a translational joint that has LuGre friction
 """
model = Model ()
Units (mass="KILOGRAM", length="METER", time="SECOND", force="NEWTON")
Accgrav (jgrav=-9.800)
Integrator (error=1e-5)
Output (reqsave=True)

 # Location for Part cm and markers used for the joint markers
qp = Point (10,0,0)
xp = Point (10,1,0)
zp = Point (11,0,0)
ground = Part (ground=True)
ground.jm = Marker (part=ground, qp=qp, zp=zp, xp=xp, label="Joint Marker")
block = Part (mass=1, ip=[1e3,1e3,1e3], label="Block")
block.cm = Marker (part=block, qp=qp, zp=zp, xp=xp, label="Block CM")

 # Attach the block to ground
joint = Joint (type="TRANSLATIONAL", i=block.cm, j=ground.jm)

 # Apply the LuGre friction to the joint
model.lugre = LuGre (joint=joint)

 # Push the block
Sforce (type="TRANSLATION", actiononly=True, i=block.cm, j=ground.jm,
function="3*sin(2*pi*time)", label="Actuation Force")

 # Request the DISPLACEMENT, VELOCITY and FORCE of the Joint
model.r1 = Request (type="DISPLACEMENT", i=block.cm, j=ground.jm, rm=ground.jm,
comment="Joint displacement")
model.r2 = Request (type="VELOCITY", i=block.cm, j=ground.jm, rm=ground.jm,
comment="Joint velocity")
model.r3 = Request (type="FORCE", i=block.cm, j=ground.jm, rm= ground.jm,
comment ="Joint force")
return model

###############################################################################
## Entry Point ################################################################
###############################################################################
if __name__ == "__main__":
model = sliding_block()
model.simulate (type="DYNAMICS", end=4, dtout=.01)

 # Change the static friction coefficient and continue simulation
model.lugre.mus=0.5
model.simulate (type="DYNAMICS", end=8, dtout=.01)