body = osim.Body('body', 2.0, osim.Vec3(0), osim.Inertia(0)) model.addComponent(body) # Allows translation along x. joint = osim.SliderJoint('slider', model.getGround(), body) coord = joint.updCoordinate() coord.setName('position') model.addComponent(joint) actu = osim.CoordinateActuator() actu.setCoordinate(coord) actu.setName('actuator') actu.setOptimalForce(1) model.addComponent(actu) body.attachGeometry(osim.Sphere(0.05)) model.finalizeConnections() # Create MucoTool. # ================ muco = osim.MucoTool() muco.setName('sliding_mass') # Define the optimal control problem. # =================================== problem = muco.updProblem() # Model (dynamics). # ----------------- problem.setModel(model)
rodTrsfrm = osim.Transform(osim.Vec3(0)) rodCenter = osim.PhysicalOffsetFrame("rodCenter", rodBdy, rodTrsfrm) rodBdy.addComponent(rodCenter) rodGeom.setColor(rodColor) #//set the color of the first block so they are different rodCenter.attachGeometry(rodGeom.clone()) pendulumDF.addBody(rodBdy) # Connect the bodies with pin joints. Assume each body is 1 m long. groundTrodJnt = osim.PinJoint("groundTrodJnt", pendulumDF.getGround(), osim.Vec3(0), osim.Vec3(0), rodBdy, rodPos, rodOrient) pendulumDF.addJoint(groundTrodJnt) sphBdy = osim.Body("sph", sphMass, sphCoM, sphInertia) sphGeom = osim.Sphere(sphRd) sphTrsfrm = osim.Transform(osim.Vec3(0)) sphCenter = osim.PhysicalOffsetFrame("sphCenter", sphBdy, sphTrsfrm) sphBdy.addComponent(sphCenter) sphGeom.setColor(sphColor) #//set the color of the first block so they are different sphCenter.attachGeometry(sphGeom.clone()) pendulumDF.addBody(sphBdy) #rodTsphJnt = osim.PinJoint ("rodTsphJnt",rodBdy, osim.Vec3(sphX-rodHeight,sphY,0), rodOrient, sphBdy, sphPos, sphOrient); rodTsphJnt = osim.PinJoint("rodTsphJnt", rodBdy, rodPos, rodOrient, sphBdy, sphPos, sphOrient) pendulumDF.addJoint(rodTsphJnt) jntCord = rodTsphJnt.updCoordinate() jntCord.setDefaultLocked(True)
def test_attachGeometry_memory_management(self): model = osim.Model() model.getGround().attachGeometry(osim.Sphere(1.5))
def createHangingMuscleModel(ignore_activation_dynamics, ignore_tendon_compliance): model = osim.Model() model.setName("hanging_muscle") model.set_gravity(osim.Vec3(9.81, 0, 0)) body = osim.Body("body", 0.5, osim.Vec3(0), osim.Inertia(1)) model.addComponent(body) # Allows translation along x. joint = osim.SliderJoint("joint", model.getGround(), body) coord = joint.updCoordinate() coord.setName("height") model.addComponent(joint) # The point mass is supported by a muscle. # The DeGrooteFregly2016Muscle is the only muscle model in OpenSim that # has been tested with Moco. actu = osim.DeGrooteFregly2016Muscle() actu.setName("muscle") actu.set_max_isometric_force(30.0) actu.set_optimal_fiber_length(0.10) actu.set_tendon_slack_length(0.05) actu.set_tendon_strain_at_one_norm_force(0.10) actu.set_ignore_activation_dynamics(ignore_activation_dynamics) actu.set_ignore_tendon_compliance(ignore_tendon_compliance) actu.set_fiber_damping(0.01) # The DeGrooteFregly2016Muscle is the only muscle model in OpenSim that # can express its tendon compliance dynamics using an implicit # differential equation. actu.set_tendon_compliance_dynamics_mode("implicit") actu.set_max_contraction_velocity(10) actu.set_pennation_angle_at_optimal(0.10) actu.addNewPathPoint("origin", model.updGround(), osim.Vec3(0)) actu.addNewPathPoint("insertion", body, osim.Vec3(0)) model.addForce(actu) # Add metabolics probes: one for the total metabolic rate, # and one for each term in the metabolics model. probe = osim.Umberger2010MuscleMetabolicsProbe() probe.setName("metabolics") probe.addMuscle("muscle", 0.5) model.addProbe(probe) probe = osim.Umberger2010MuscleMetabolicsProbe() probe.setName("activation_maintenance_rate") probe.set_activation_maintenance_rate_on(True) probe.set_shortening_rate_on(False) probe.set_basal_rate_on(False) probe.set_mechanical_work_rate_on(False) probe.addMuscle("muscle", 0.5) model.addProbe(probe) probe = osim.Umberger2010MuscleMetabolicsProbe() probe.setName("shortening_rate") probe.set_activation_maintenance_rate_on(False) probe.set_shortening_rate_on(True) probe.set_basal_rate_on(False) probe.set_mechanical_work_rate_on(False) probe.addMuscle("muscle", 0.5) model.addProbe(probe) probe = osim.Umberger2010MuscleMetabolicsProbe() probe.setName("basal_rate") probe.set_activation_maintenance_rate_on(False) probe.set_shortening_rate_on(False) probe.set_basal_rate_on(True) probe.set_mechanical_work_rate_on(False) probe.addMuscle("muscle", 0.5) model.addProbe(probe) probe = osim.Umberger2010MuscleMetabolicsProbe() probe.setName("mechanical_work_rate") probe.set_activation_maintenance_rate_on(False) probe.set_shortening_rate_on(False) probe.set_basal_rate_on(False) probe.set_mechanical_work_rate_on(True) probe.addMuscle("muscle", 0.5) model.addProbe(probe) body.attachGeometry(osim.Sphere(0.05)) model.finalizeConnections() return model
linkageMassCenter2 = osim.Vec3(0., linkageLength2 - 0.18647538, 0.) linkageMassCenter3 = osim.Vec3(0., linkageLength3 - 0.17055675, 0.) linkageMassCenter4 = osim.Vec3(0., linkageLength4 - 0.4237, 0.) exothick = 0.025 exocenter = osim.Vec3(0., exothick / 2, 0.) linkage1 = osim.Body("foot", linkageMass1, linkageMassCenter1, osim.Inertia(0.1, 0.1, 0.00662, 0., 0., 0.)) linkage2 = osim.Body("shank", linkageMass2, linkageMassCenter2, osim.Inertia(0.1, 0.1, 0.1057, 0., 0., 0.)) linkage3 = osim.Body("thigh", linkageMass3, linkageMassCenter3, osim.Inertia(0.2, 0.1, 0.217584, 0., 0., 0.)) linkage4 = osim.Body("HAT", linkageMass4, linkageMassCenter4, osim.Inertia(1.1, 1.1, 1.48, 0., 0., 0.)) ZAxis = osim.CoordinateAxis(2) R = osim.Rotation(-pi / 2, ZAxis) sphere = osim.Sphere(0.04) exo = osim.Cylinder(.05, exothick) linkage1.attachGeometry(sphere.clone()) cyl1 = osim.Cylinder(linkageDiameter / 2, linkageLength1 / 2) cyl1Frame = osim.PhysicalOffsetFrame( linkage1, osim.Transform(osim.Vec3(0.0, linkageLength1 / 2, 0.0))) cyl1Frame.setName("Cyl1_frame") cyl1Frame.attachGeometry(cyl1.clone()) osimModel.addComponent(cyl1Frame) linkage2.attachGeometry(sphere.clone()) cyl2 = osim.Cylinder(linkageDiameter / 2, linkageLength2 / 2) cyl2Frame = osim.PhysicalOffsetFrame( linkage2, osim.Transform(osim.Vec3(0.0, linkageLength2 / 2, 0.0))) cyl2Frame.setName("Cyl2_frame") cyl2Frame.attachGeometry(cyl2.clone())