示例#1
0
    def create_obstacles(self):
        x = 0.
        y = 0.
        r = 0.1
        for i in range(self.max_obstacles):
            name = i.__str__()
            blockos = opensim.Body(name + '-block', 0.0001, opensim.Vec3(0),
                                   opensim.Inertia(1., 1., .0001, 0., 0., 0.))
            pj = opensim.PlanarJoint(
                name + '-joint',
                self.osim_model.model.getGround(),  # PhysicalFrame
                opensim.Vec3(0., 0., 0.),
                opensim.Vec3(0., 0., 0.),
                blockos,  # PhysicalFrame
                opensim.Vec3(0., 0., 0.),
                opensim.Vec3(0., 0., 0.))

            self.osim_model.model.addJoint(pj)
            self.osim_model.model.addBody(blockos)

            block = opensim.ContactSphere(r, opensim.Vec3(0., 0., 0.), blockos)
            block.setName(name + '-contact')
            self.osim_model.model.addContactGeometry(block)

            force = opensim.HuntCrossleyForce()
            force.setName(name + '-force')

            force.addGeometry(name + '-contact')
            force.addGeometry("r_heel")
            force.addGeometry("l_heel")
            force.addGeometry("r_toe")
            force.addGeometry("l_toe")

            force.setStiffness(1.0e6 / r)
            force.setDissipation(1e-5)
            force.setStaticFriction(0.0)
            force.setDynamicFriction(0.0)
            force.setViscousFriction(0.0)

            self.osim_model.model.addForce(force)
ballGeometry.setColor(opensim.Gray)
ballBody.attachGeometry(ballGeometry)

# Attach ball to the model
ballJoint = opensim.FreeJoint("weldball",
                         model.getGround(), # PhysicalFrame
                         opensim.Vec3(0, 0, 0),
                         opensim.Vec3(0, 0, 0),
                         ballBody, # PhysicalFrame
                         opensim.Vec3(0, 0, 0),
                         opensim.Vec3(0, 0, 0))
model.addComponent(ballJoint)
model.addComponent(ballBody)

# Add contact
ballContact = opensim.ContactSphere(r, opensim.Vec3(0,0,0), ballBody);
model.addContactGeometry(ballContact)

# Reinitialize the system with the new controller
state = model.initSystem()

for i in range(6):
    ballJoint.getCoordinate(i).setLocked(state, True)

# Simulate
for i in range(100):
    t = state.getTime()
    manager = opensim.Manager(model)
    manager.integrate(state, t + stepsize)

    # Restart the model every 10 frames, with the new position of the ball
示例#3
0
    "pinblock",
    model.getGround(),  # PhysicalFrame
    opensim.Vec3(-0.5, 0, 0),
    opensim.Vec3(0, 0, 0),
    blockos,  # PhysicalFrame
    opensim.Vec3(0, 0, 0),
    opensim.Vec3(0, 0, 0))

bodyGeometry = opensim.Ellipsoid(0.1, 0.1, 0.1)
bodyGeometry.setColor(opensim.Gray)
blockos.attachGeometry(bodyGeometry)

model.addComponent(pj)
model.addComponent(blockos)
#block = opensim.ContactMesh('block.obj',opensim.Vec3(0,0,0), opensim.Vec3(0,0,0), blockos);
block = opensim.ContactSphere(0.4, opensim.Vec3(0, 0, 0), blockos)
model.addContactGeometry(block)

# Reinitialize the system with the new controller
state0 = model.initSystem()
state = opensim.State(state0)

# Change max force
muscleSet.get(0).setMaxIsometricForce(100000.0)

# Get ligaments
ligamentSet = []
for j in range(20, 26):
    ligamentSet.append(
        opensim.CoordinateLimitForce.safeDownCast(forceSet.get(j)))